Skip to content

feat(service): verify GitHub App webhooks with one secret #4417

Open

Description

@dan-petty

Problem or Motivation

ADR 0015 (docs/adr/0015-roadmap-jobs-act-as-a-github-app-on-the-personal-account.md, line 37) moved the Service to a GitHub App (devops-cli-service) and explicitly deferred webhook consolidation: "The webhooks of each repository stay. The App's own webhook can replace them in a later item."

Keeping per-repository webhooks causes three operational and architectural problems:

  1. Onboarding each repository requires creating a separate repository webhook and updating a JSON map in service.webhook_secrets (k8s/README.md steps 2, 8, and 9).
  2. HmacSha256.signers (src/devops_cli/server/routes/webhooks.py:86-93) computes an HMAC-SHA256 digest over the request body against every configured repository secret on every incoming GitHub delivery.
  3. As noted in feat(roadmap): onboard checks the webhook of a repository #3772, the App installation token holds no repository Administration permission, so GET repos/<owner>/<name>/hooks returns HTTP 403. By contrast, the App's own JWT can read GET /app/hook/config directly without repository Administration permission.
  4. App-level events such as installation and installation_repositories carry no top-level repository object. GitHubWebhookPayload (src/devops_cli/models/webhooks.py:38) rejects them with HTTP 400 invalid payload instead of acknowledging them cleanly.

Proposed Solution & Architectural Design

  • Replace service.webhook_secrets (DEVOPS_CLI_SERVICE_WEBHOOK_SECRETS) with one string secret service.github_app.webhook_secret, keeping no legacy shim (AGENTS.md).
  • Update HmacSha256 and _authenticated_payload (src/devops_cli/server/routes/webhooks.py) to verify X-Hub-Signature-256 once against service.github_app.webhook_secret.
  • Make GitHubWebhookPayload.repository optional (src/devops_cli/models/webhooks.py).
  • Return 200 {"status": "no_subscriber"} (or pong on ping) for App events that carry no repository field.
  • Require payload.repository.full_name to match service.repos (managed_repos) for repository events, refusing unmanaged repositories.
  • Update cluster_secrets.py, docs/ENV_VARS.md, and k8s/README.md, and align onboarding checks (feat(roadmap): onboard checks the webhook of a repository #3772) with GET /app/hook/config.

Target Subsystem

Kubernetes & Minikube Automation

Existing Tool Considered

gidgethub (gidgethub.sansio.Event.from_http) verifies single-secret X-Hub-Signature-256 headers, and webhooks.py already implements streaming body caps (_read_capped_body), pre-read header refusals, and HmacSha256.verify (hmac.compare_digest) in standard-library Python. Replacing the multi-secret map with a single App secret simplifies HmacSha256 and removes code rather than adding a new library. The change costs about 95,000 tokens to build, maintain, and fix, and about 2 hours of elapsed time.

Acceptance Criteria

  • service.github_app.webhook_secret (DEVOPS_CLI_SERVICE_GITHUB_APP_WEBHOOK_SECRET) replaces service.webhook_secrets across settings.py, env.py, cluster_secrets.py, service.py, docs/ENV_VARS.md, and k8s/README.md, with no backward-compatibility shim.
  • _authenticated_payload verifies each GitHub delivery with one constant-time HMAC-SHA256 check and accepts repository events only when repository.full_name is in service.repos.
  • Validly signed App-level events without a top-level repository field (such as ping, installation, and installation_repositories) return 200 (pong or no_subscriber) instead of 400 or 401.
  • Offline unit tests cover single-secret HMAC verification, unmanaged-repository refusal, and repository-less App events.

Standards Compliance

  • I confirm this proposal aligns with AGENTS.md engineering principles (cyclomatic complexity <= 10, nesting <= 5, zero bare exceptions, tests that cover the changed lines).
  • I am willing to submit a pull request implementing this feature with accompanying tests.

Alternatives check of 2026-11-25: in-use.
The repository already uses this tool.
Tool: gidgethub/gidgethub (https://github.com/gidgethub/gidgethub), Apache-2.0, last activity 2026-11-20, maintained.
Reason: Searches surfaced no broader tool; gidgethub's Event.from_http already verifies one X-Hub-Signature-256 secret and the project uses it, but the body cap, header refusals, managed-repository check and App-event answers stay custom.

Covers:

  • Single-secret X-Hub-Signature-256 check in sansio Event.from_http
  • Sans-I/O event parsing of delivery headers and body
  • Already a dependency, so no new library

Lacks:

  • Capped streaming read that refuses bodies above 25 MiB
  • Pre-read header refusals before the body is read
  • Exact repository.full_name membership check against service.repos
  • 200 no_subscriber or pong answer for repository-less App events

Proposed design

Problem statement

ADR 0015 moved the Service to the GitHub App devops-cli-service and deferred the App webhook. The Service still keeps a per-repository webhook secret map. It checks every secret on each delivery. It rejects valid App-level events that carry no repository. This change replaces the map with one App webhook secret, verifies each delivery once, accepts App-level events, and limits repository events to service.repos.

Acceptance criteria

Requirement: Single App webhook secret setting

The Service SHALL replace service.webhook_secrets with service.github_app.webhook_secret and DEVOPS_CLI_SERVICE_GITHUB_APP_WEBHOOK_SECRET in settings and environment declarations, and it SHALL keep no backward-compatibility shim.

Scenario: Load the App webhook secret

  • WHEN The offline settings test runs uv run pytest tests/server/test_server.py with DEVOPS_CLI_SERVICE_GITHUB_APP_WEBHOOK_SECRET set and DEVOPS_CLI_SERVICE_WEBHOOK_SECRETS unset.
  • THEN The test reads service.github_app.webhook_secret as the configured value, and the settings model exposes no service.webhook_secrets field.

Requirement: Environment declaration uses new variable

The environment declaration SHALL list DEVOPS_CLI_SERVICE_GITHUB_APP_WEBHOOK_SECRET and MUST NOT list DEVOPS_CLI_SERVICE_WEBHOOK_SECRETS.

Scenario: Config declaration check

  • WHEN The config declaration test runs uv run pytest tests/security/test_config_declarations.py.
  • THEN The test passes and asserts that DEVOPS_CLI_SERVICE_GITHUB_APP_WEBHOOK_SECRET is declared and DEVOPS_CLI_SERVICE_WEBHOOK_SECRETS is absent.

Requirement: Optional cluster secret

The cluster secret table SHALL replace service.webhook_secrets with the optional service.github_app.webhook_secret.

Scenario: Deploy without the App webhook secret

  • WHEN The offline cluster secret plan test runs uv run pytest tests/k8s/test_cluster_secret_plan.py with no keyring value and no cluster value for service_github_app_webhook_secret.
  • THEN The test shows the push skips the key with a warning and the deploy plan continues.

Requirement: One signature check

The webhook route SHALL verify each GitHub delivery with one constant-time HMAC-SHA256 check against service.github_app.webhook_secret before it parses the payload.

Scenario: Valid and invalid signatures

  • WHEN The offline webhook test sends a validly signed delivery and a delivery signed with another secret.
  • THEN The test shows the valid delivery passes authentication, and the other delivery gets HTTP 401 invalid signature with no payload parse.

Requirement: Managed repository only

The webhook route MUST accept a repository event only when payload.repository.full_name is one of service.repos.

Scenario: Unmanaged repository event

  • WHEN The offline webhook test sends a validly signed repository event whose repository.full_name is absent from service.repos.
  • THEN The test shows HTTP 403 and no round starts.

Requirement: Repository-less App event

The webhook route SHALL return HTTP 200 with {"status": "no_subscriber"} for a validly signed App-level event that has no top-level repository field.

Scenario: Installation event without repository

  • WHEN The offline webhook test sends a validly signed installation or installation_repositories delivery with no top-level repository field.
  • THEN The test shows HTTP 200 with {"status": "no_subscriber"} and no round starts.

Requirement: Ping event

The webhook route SHALL answer a validly signed ping delivery with HTTP 200 and a pong body.

Scenario: Ping without repository

  • WHEN The offline webhook test sends a validly signed ping delivery with no top-level repository field.
  • THEN The test shows HTTP 200, a body that contains pong, and no round starts.

Requirement: Repository field optional

GitHubWebhookPayload SHALL make repository optional while it keeps validation of the other declared fields.

Scenario: App-level payload validation

  • WHEN The offline model test runs uv run pytest tests/models/test_webhooks.py and validates an installation payload with sender and no repository.
  • THEN The test shows the model accepts the payload and exposes repository as None.

Requirement: Existing webhook guards

The webhook route SHALL keep the existing 25 MiB body cap and pre-read header refusals after the secret change.

Scenario: Oversized delivery

  • WHEN The offline webhook test runs uv run pytest tests/server/test_server_service.py and sends a delivery with a Content-Length above 25 MiB.
  • THEN The test shows HTTP 413 before the route reads the body.

Requirement: Onboarding uses App hook config

The onboarding check SHALL verify the App webhook with GET /app/hook/config and MUST NOT call GET repos/<owner>/<name>/hooks.

Scenario: Onboarding check request

  • WHEN The offline onboarding test runs uv run pytest tests/commands/k8s/test_k8s.py with a stubbed GitHub API.
  • THEN The test shows the check sends GET /app/hook/config and sends no GET repos/<owner>/<name>/hooks request.

Requirement: Deployment manifest uses the App webhook secret

The roadmap-service deployment SHALL read service.github_app.webhook_secret and MUST NOT set DEVOPS_CLI_SERVICE_WEBHOOK_SECRETS.

Scenario: Kubernetes manifest check

  • WHEN The Kubernetes check runs uv run devops ci --check --only k8s.
  • THEN The check passes and the roadmap-service deployment sets no DEVOPS_CLI_SERVICE_WEBHOOK_SECRETS.

Requirement: Documentation names the App webhook secret

The documentation in docs/ENV_VARS.md and k8s/README.md SHALL name service.github_app.webhook_secret and DEVOPS_CLI_SERVICE_GITHUB_APP_WEBHOOK_SECRET in place of service.webhook_secrets and DEVOPS_CLI_SERVICE_WEBHOOK_SECRETS.

Scenario: Documentation check

  • WHEN The documentation check runs uv run devops ci --check --only docs.
  • THEN The check passes and reports no documentation error for the changed files.

Requirement: Offline webhook tests

The change SHALL add offline unit tests for single-secret HMAC verification, unmanaged-repository refusal, and repository-less App events.

Scenario: Webhook test suite

  • WHEN The offline webhook tests run uv run pytest tests/server/test_server_service.py.
  • THEN The tests cover the single-secret signature, the unmanaged repository refusal, and the App-level event acknowledgement.

Requirement: Pending a person after the merge

A person SHALL enable the App webhook and set service.github_app.webhook_secret after the merge.

Scenario: App webhook configured

  • WHEN A person enables the App webhook at https://hooks.&lt;domain>/webhooks/github, sets the same secret in the App settings and the keyring, and runs devops k8s push-secrets --only devops/devops-cli.
  • THEN A live GitHub ping delivery returns HTTP 200 with a pong body, and the Service log shows no signature error.

Existing Tool Considered

gidgethub (https://github.com/gidgethub/gidgethub) has the verdict in-use; the issue body's alternatives check lists its Covers and Lacks. The repository already uses gidgethub. The proposal keeps HmacSha256 and the webhook route for the Lacks: the capped streaming read, the pre-read header refusals, the exact repository.full_name membership check, and the 200 no_subscriber or pong answer for repository-less App events. The issue estimates about 95,000 tokens to build, keep, and fix this change, and about 2 hours of elapsed time.

Key questions

  • Which secret setting replaces the per-repository webhook secret map?: Use one string secret, service.github_app.webhook_secret, and its variable DEVOPS_CLI_SERVICE_GITHUB_APP_WEBHOOK_SECRET. Remove service.webhook_secrets and add no compatibility shim. (best practice) [sources: docs/adr/0015-roadmap-jobs-act-as-a-github-app-on-the-personal-account.md, src/devops_cli/k8s/cluster_secrets.py, docs/ENV_VARS.md, k8s/README.md, k8s/devops/roadmap-service/deployment.yaml, AGENTS.md]
    • Chosen: Single App webhook secret. ADR 0015 defers the App webhook replacement. One App secret removes per-repository onboarding and repeated HMAC checks.
    • Rejected: Keep the per-repository map. It keeps one repository webhook for each repository and checks every configured secret on each delivery.
    • Rejected: Add a compatibility shim. AGENTS.md forbids backward-compatibility shims before 1.0.
  • Must the new App webhook secret be required for a devops stack deploy?: No. Keep the cluster secret row optional, as the old webhook secret map was optional. A missing secret leaves the webhook route refusing deliveries while polling continues. (best practice) [sources: docs/adr/0021-the-roadmap-service-is-a-webhook-router-cluster-pods-run-the-roadmap-jobs-and-valkey-holds-their-shared-state.md, k8s/README.md, src/devops_cli/k8s/cluster_secrets.py]
    • Chosen: Optional secret. The old map was optional, and polling continues when webhook verification has no secret.
    • Rejected: Required secret. It would stop deploy-stack for a feature that only cuts webhook latency.
    • Rejected: Generate the secret automatically. A person must set the same secret in the GitHub App settings, so a generated value alone does not configure the webhook.
  • How does the route verify a delivery with one secret?: Verify the raw body once with HmacSha256 and hmac.compare_digest against service.github_app.webhook_secret before parsing. Keep the capped streaming read and the pre-read header refusals. (best practice) [sources: src/devops_cli/server/routes/webhooks.py:88, src/devops_cli/server/routes/webhooks.py:719]
    • Chosen: Use existing HmacSha256 with one secret. It already uses hmac.compare_digest and keeps the existing body cap and pre-read refusals.
    • Rejected: Adopt gidgethub Event.from_http. It verifies one signature but provides no capped streaming read, pre-read refusals, exact repository membership check, or 200 no_subscriber/pong answers.
    • Rejected: Keep HmacSha256.signers over every repository secret. It does unnecessary work on each delivery and keeps the per-repository secret map.
  • What does a validly signed App-level event with no repository return?: Return HTTP 200 with {"status": "no_subscriber"}. Return HTTP 200 with a pong body for ping. Start no round. (best practice) [sources: src/devops_cli/models/webhooks.py:107, src/devops_cli/server/routes/webhooks.py]
    • Chosen: Acknowledge with HTTP 200. App-level events have no subscriber. A 200 stops GitHub retries and matches the route's existing no-subscriber answer.
    • Rejected: Reject with HTTP 400 invalid payload. The current model rejects valid App-level events because repository is required.
    • Rejected: Return HTTP 202 with an empty body. The route reports its result as a JSON status, and a test can assert the 200 and the status body.
  • How does the route decide that a repository event is managed?: Compare payload.repository.full_name with service.repos. Accept the event only on an exact match. Refuse an unmanaged repository with HTTP 403. (best practice) [sources: src/devops_cli/server/routes/webhooks.py, docs/ENV_VARS.md, k8s/README.md]
    • Chosen: Exact membership in service.repos. It uses the existing managed repository list and refuses an unmanaged repository before any round starts.
    • Rejected: Trust every validly signed App event. A valid App signature does not prove that the repository is in service.repos.
    • Rejected: Normalize the names to lower case. The configured values and the current route use exact owner/name strings. Normalization is a separate change.
  • Which payload fields become optional for App-level events?: Make repository optional. Keep sender required because installation and installation_repositories events carry it. (best practice) [sources: src/devops_cli/models/webhooks.py:107]
    • Chosen: Only repository optional. It matches the issue and keeps sender validation for App-level events that carry a sender.
    • Rejected: Make repository and sender optional. It weakens validation with no evidence that the App events lack a sender.
    • Rejected: Keep repository required and special-case event names. It moves payload validation into the route and misses future App events.
  • Which GitHub API does the onboarding check use to verify the App webhook?: Use GET /app/hook/config with the App JWT. Do not use GET repos/<owner>/<name>/hooks. (best practice) [sources: docs/adr/0015-roadmap-jobs-act-as-a-github-app-on-the-personal-account.md, k8s/README.md]
    • Chosen: GET /app/hook/config. The App JWT can read the App webhook configuration without repository Administration permission.
    • Rejected: GET repos/<owner>/<name>/hooks. The installation token has no repository Administration permission, so this call returns HTTP 403.
    • Rejected: Skip the webhook check. Onboarding must verify that the App webhook is configured.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    type/feature
    scope/service
    status/new
    value/medium
    effort/medium
    on Nov 10, 2026
  2. dan-petty commented on Nov 10, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/feature. The feat prefix of the title gives the type.
    • Scope: scope/service. The (service) scope of the title gives the scope.
    • Priority: P2-Medium. It reduces onboarding friction and fixes a 400 for App events, but the current multi-secret path still works for repository events.
    • Value: Medium. Simplifies operations for every new repository and removes a 400 error class, but does not unblock a broken feature.
    • Effort: Medium. It touches settings, env, cluster_secrets, webhooks.py, models, docs, and k8s README, plus new unit tests.
    • Related: feat(service): one webhook router verifies each provider its own way, parses a typed payload and delivers each event only to the consumers subscribed to it #1386, which asks for a different change. Both work on the webhook router in webhooks.py, but #1386 built the router structure while the candidate changes the secret from a per-repo map to one App secret.
  3. added
    priority/p2-medium
    on Nov 10, 2026
  4. devops-cli-service commented on Nov 10, 2026

    @devops-cli-service
    Contributor

    Refine cannot set this item to Ready at 1ca0133 until a person answers the questions below. Reply in a comment or edit the body, and the next refine round looks at the item again.

    • Who sets the App webhook URL and secret? (a person decides)
  5. devops-cli-service commented on Nov 11, 2026

    @devops-cli-service
    Contributor

    Alternatives check: partly

    Reason: Searches for a library that verifies a GitHub App webhook with one secret found gidgethub, whose sansio.Event.from_http checks a single X-Hub-Signature-256 against one secret in constant time, so it covers the signature-verification part of this change. It covers nothing else the issue needs: the settings/env/cluster-secret migration away from service.webhook_secrets, the capped streaming body read and pre-read header refusals, the service.repos membership refusal, the 200 no_subscriber/pong answer for repository-less App events, and the GET /app/hook/config onboarding check.

    Tool: gidgethub/gidgethub (https://github.com/gidgethub/gidgethub)

    • License: Apache-2.0
    • Last activity: 2026-09-25
    • Maintained: yes

    Covers:

    • Verifies one X-Hub-Signature-256 header against a single webhook secret (sansio Event.from_http)
    • Parses GitHub webhook deliveries into an event object
    • Apache-2.0 library, maintained, latest release v6.0.0

    Lacks:

    • No migration of service.webhook_secrets to service.github_app.webhook_secret in settings, env, cluster_secrets, docs and k8s README
    • No capped streaming body read (25 MiB) or pre-read Content-Length refusal
    • No check that payload.repository.full_name is in service.repos
    • No 200 no_subscriber / pong answer for repository-less App events, and no optional repository model
    • No onboarding check through GET /app/hook/config

    Tools considered:

    Searches run:

    • python library verify GitHub App webhook signature single secret, results: 5
    • gidgethub webhook X-Hub-Signature-256 verification Event.from_http, results: 5
    • gidgethub sansio Event from_http signature secret, results: 5
    • gidgethub documentation sansio module Event, results: 5
    • "gidgethub" python GitHub webhook verify signature, results: 5
    • githubkit webhook verify parse signature python, results: 5
    • sansio webhook signature verification github app python package pypi, results: 5
    • gidgethub GitHub repository, results: 5

    Sources:

    Checked on 2026-11-11. A person decides what this means for the item. The check changes no label and closes no issue.

  6. devops-cli-service commented on Nov 19, 2026

    @devops-cli-service
    Contributor

    The result in the alternatives block of the issue body changed. Before this check: partly, tool https://github.com/gidgethub/gidgethub. A person decides what the new result means for the item.

    Searches (6)

    Tools considered:

    Searches run:

    • gidgethub Event.from_http verify webhook X-Hub-Signature-256, results: 5
    • python library verify GitHub App webhook signature single secret, results: 5
    • gidgethub sansio Event.from_http documentation, results: 5
    • github webhook HMAC verification python package 2025, results: 5
    • gidgethub pypi, results: 5
    • "gidgethub" webhook, results: 5

    Sources:

  7. devops-cli-service commented on Nov 20, 2026

    @devops-cli-service
    Contributor

    Owner question: See the first point of Open questions in the section Proposed design of the body.

    Options

    1. Decide the question: The job refines the item with your answer.
    2. Leave it to the job: The job records the best-practice answer and goes on.

    Recommendation: Decide the question: only a person can answer it.

    Evidence

  8. added
    status/ready
    and removed
    status/new
    on Nov 26, 2026
  9. devops-cli-service commented on Nov 26, 2026

    @devops-cli-service
    Contributor

    Next step: the stage job writes the plan of the item. See the section Proposed design of the body.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/mediumpriority/p2-mediumscope/servicesource/agentstatus/readytype/featurevalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions