Skip to content

security: authenticate the alertmanager and manual webhook endpoints - #23

Merged
OkiriGabriel merged 2 commits into
open-devops-agent:mainfrom
Nitjsefnie-OSC:fix/10-webhook-auth
Jul 16, 2026
Merged

OkiriGabriel merged 2 commits into
open-devops-agent:mainfrom
Nitjsefnie-OSC:fix/10-webhook-auth

Conversation

@Nitjsefnie

Copy link
Copy Markdown
Contributor

Summary

/webhook/alertmanager and /webhook/manual previously accepted any unauthenticated POST request. An attacker who could reach the agent could queue arbitrary incidents (including mutating type/source fields), 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_webhook and manual_trigger now read the raw request body first (await request.body()), then verify the X-Hub-Signature-256 header against WEBHOOK_SECRET using the existing verify_github_signature() helper (hmac.compare_digest over raw bytes).
    • Return 401 Invalid signature when WEBHOOK_SECRET is configured but the header is missing, malformed, or does not match the body.
    • When WEBHOOK_SECRET is unset, verification is skipped — exactly mirroring the opt-out behaviour of the GitHub webhook so existing deployments are not broken on upgrade.

Header / secret

Endpoint Header Secret env var
/webhook/alertmanager X-Hub-Signature-256 WEBHOOK_SECRET
/webhook/manual X-Hub-Signature-256 WEBHOOK_SECRET

WEBHOOK_SECRET is already documented in .env.example.

Upgrade-compatibility note

This change is opt-in by configuration: deployments that do not set WEBHOOK_SECRET continue to work unchanged (but remain unauthenticated). Operators should set WEBHOOK_SECRET and configure their callers to send X-Hub-Signature-256 to 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:

  • Valid signature → accepted for both endpoints.
  • Invalid signature → 401.
  • Missing signature → 401.
  • Signature computed over a different body → 401.
  • WEBHOOK_SECRET unset → verification skipped, request accepted.
  • GitHub webhook regression tests still pass.

Gates

python3 -m pytest tests/ -q
# 85 passed, 1 warning in 1.32s

flake8 api/server.py tests/test_webhook_auth.py --count --select=E9,F63,F7,F82 --show-source --statistics
# 0

Closes #10

Prepared with AI assistance (Kimi K2.7 Code), human-reviewed before submission.

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]>
@OkiriGabriel

Copy link
Copy Markdown
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.

@OkiriGabriel
OkiriGabriel merged commit 377cd91 into open-devops-agent:main Jul 16, 2026
3 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add authentication to Alertmanager and manual webhook endpoints

2 participants