Skip to content

Webhook: Add HMAC signature validation for the generic webhook source #1039

@kelos-bot

Description

@kelos-bot

🤖 Kelos Agent @gjkim42

Background

The spec.when.webhook (GenericWebhook) TaskSpawner source currently exposes an unauthenticated endpoint at `/webhook/`.

The Helm chart (`internal/manifests/charts/kelos/templates/webhook-server.yaml`) mounts `webhookServer.sources.generic.secretName` via `envFrom`, but the handler in `internal/webhook/handler.go` (`GenericSource` case, ~lines 211–231) does not:

  • read `_WEBHOOK_SECRET`
  • inspect `X-Hub-Signature-256`
  • call any HMAC validation helper

`signature.go` only exposes `ValidateGitHubSignature` and `ValidateLinearSignature`. Tests like `TestGenericServeHTTP_CreatesTaskForMatchingSpawner` confirm the current behavior — they POST without any signature header and expect HTTP 200.

This was caught during review of #1035 (docs PR), which originally documented HMAC validation that does not exist. The docs there have been corrected to describe the current unauthenticated state.

Proposal

Wire up per-source HMAC-SHA256 validation for the generic webhook source:

  1. In the `GenericSource` branch of `WebhookHandler.ServeHTTP`, look up `_WEBHOOK_SECRET` from the environment (uppercased `source` name).
  2. Read the `X-Hub-Signature-256` header (`sha256=`).
  3. Call `validateHMACSignature(body, signature, secret)`. Return `401 Unauthorized` on failure.
  4. If `_WEBHOOK_SECRET` is missing, fail-closed (refuse the request) so misconfiguration is loud.
  5. Add `TestGenericServeHTTP_RejectsInvalidSignature` and `TestGenericServeHTTP_RejectsMissingSecret` to exercise the new code paths; update existing tests to send a valid signature.
  6. Once landed, restore the HMAC docs in `docs/integration.md` and `examples/13-taskspawner-generic-webhook/README.md` (the "Webhook security" sections).

/kind feature

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions