Commit 030891b
feat(github-app): P4.2 — App webhook → push-to-deploy + security hardening (#225)
* feat(github-app): P4.2 — App webhook → push-to-deploy + security hardening
POST /webhooks/github: one App-level endpoint for ALL installations (vs the
manual per-repo /webhooks/github/:webhook_id). Verifies the App HMAC, dedupes on
X-GitHub-Delivery (Redis), and dispatches: `push` → match repo+branch to a
connection linked to that installation+team → enqueue the same rate-limited
redeploy the manual path uses; `installation` deleted/suspend/unsuspend → sync
github_installations. Gated by GITHUB_APP_ENABLED (default OFF). Token-into-clone
wiring is P4.2b.
Built with parallel agents: internal/github/webhook.go (HMAC verify +
push/installation parsers, 100%), internal/models/github_push_match.go
(repo/branch + installation lookups, 100%), infra observability (separate repo).
Security review fixes (adversarial pass):
- HIGH-1: config.Load now fails closed — GITHUB_APP_ENABLED=true with an empty
GITHUB_APP_WEBHOOK_SECRET (<16 chars) / missing key / missing id panics,
instead of serving an HMAC verifiable with a public empty key.
- HIGH-2: UpsertGitHubInstallation is WHERE-guarded so a callback can't rebind an
installation owned by another team → ErrGitHubInstallationTeamConflict → 409
install_conflict (anti-hijack). Residual first-writer race + worker-dispatch
guard (MED-2) documented as pre-flag-flip prerequisites in the runbook.
- MED-1: webhook event metric label canonicalized to a bounded set before the
HMAC check (pre-auth Prometheus cardinality DoS).
- LOW-2: push `after` validated as 40-hex; response reports successfully-enqueued
count, not matched (matched/enqueued split).
Metrics instant_github_webhook_received_total / _pushdeploy_total (+ infra
alerts/dashboard/catalog in the companion infra change, rule 25). New routes
whitelisted in the openapi route-coverage gate (GitHub-facing, flag-gated;
contract sync is P4.3). Coverage: 100% on the new github/models packages +
the webhook handler arms (white-box + sqlmock + DB/Redis-gated).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* test(github-app): cover P4.2 config fail-closed + webhook error arms
Close the patch-coverage gaps CI flagged on the P4.2 review fixes:
- config.go 492/495 — the private-key-missing + app-id-missing fail-closed
panic arms (HIGH-1), via two more mustPanic cases.
- github_app_webhook.go 132-141/201-207 — the installation delete/suspend/
unsuspend slog.Warn arms, the generic enqueue-error arm, and the
last-deploy-update warn arm, via sqlmock white-box tests (force each DB op
to error; the real-DB integration path can't reach them).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent 1c195e4 commit 030891b
20 files changed
Lines changed: 1950 additions & 5 deletions
File tree
- internal
- config
- github
- handlers
- metrics
- models
- router
- testhelpers
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
479 | 479 | | |
480 | 480 | | |
481 | 481 | | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
482 | 498 | | |
483 | 499 | | |
484 | 500 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
374 | 374 | | |
375 | 375 | | |
376 | 376 | | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
377 | 387 | | |
378 | | - | |
| 388 | + | |
379 | 389 | | |
380 | 390 | | |
381 | 391 | | |
| |||
386 | 396 | | |
387 | 397 | | |
388 | 398 | | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
389 | 421 | | |
390 | 422 | | |
391 | 423 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
0 commit comments