Repository navigation
security: authenticate the alertmanager and manual webhook endpoints - #23
Merged
OkiriGabriel merged 2 commits intoJul 16, 2026
Merged
Conversation
Add HMAC-SHA256 signature verification to /webhook/alertmanager and /webhook/manual, mirroring the existing GitHub webhook implementation: - Verify the X-Hub-Signature-256 header against WEBHOOK_SECRET. - Compute the signature over the raw request body before JSON parsing. - Return 401 when the secret is configured but the signature is missing, invalid, or computed over a different body. - Skip verification when WEBHOOK_SECRET is unset, matching the GitHub endpoint opt-out semantics. Add tests covering valid signature acceptance, invalid/missing signature rejection, signature over a different body, and opt-out behaviour for both endpoints, plus a GitHub webhook regression test. Co-Authored-By: Kimi K2.7 Code <[email protected]>
Collaborator
|
Thanks @Nitjsefnie! Webhook authentication for Alertmanager and manual endpoints is already covered in PR #20 (merged on feat/add-mcp). Closing as duplicate — appreciate the contribution. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
/webhook/alertmanagerand/webhook/manualpreviously accepted any unauthenticated POST request. An attacker who could reach the agent could queue arbitrary incidents (including mutatingtype/sourcefields), trigger unnecessary remediation attempts, pollute audit logs, and potentially exhaust API/AI budgets.This PR authenticates both endpoints using the same HMAC-SHA256 scheme already used by
/webhook/github.What changed
api/server.py:alertmanager_webhookandmanual_triggernow read the raw request body first (await request.body()), then verify theX-Hub-Signature-256header againstWEBHOOK_SECRETusing the existingverify_github_signature()helper (hmac.compare_digestover raw bytes).401 Invalid signaturewhenWEBHOOK_SECRETis configured but the header is missing, malformed, or does not match the body.WEBHOOK_SECRETis unset, verification is skipped — exactly mirroring the opt-out behaviour of the GitHub webhook so existing deployments are not broken on upgrade.Header / secret
/webhook/alertmanagerX-Hub-Signature-256WEBHOOK_SECRET/webhook/manualX-Hub-Signature-256WEBHOOK_SECRETWEBHOOK_SECRETis already documented in.env.example.Upgrade-compatibility note
This change is opt-in by configuration: deployments that do not set
WEBHOOK_SECRETcontinue to work unchanged (but remain unauthenticated). Operators should setWEBHOOK_SECRETand configure their callers to sendX-Hub-Signature-256to actually gain protection. A future release could decide to fail closed (require the secret) if the maintainers prefer.Tests
Added
tests/test_webhook_auth.py:WEBHOOK_SECRETunset → verification skipped, request accepted.Gates
Closes #10
Prepared with AI assistance (Kimi K2.7 Code), human-reviewed before submission.