Repository navigation
feat(notify): sign notifications with Standard Webhooks - #240
Merged
Merged
Conversation
A receiver that records deploy events, such as a monitoring service that verifies each production deploy, needs to know a notification came from this project's Onebox and not from anyone who learned the webhook URL. The notification field signingSecretEnv names a local environment variable holding a Standard Webhooks secret (whsec_ + base64). When set, each request carries webhook-id, webhook-timestamp and webhook-signature: v1,<HMAC-SHA256 over id.timestamp.body>, computed over the exact bytes sent. The JSON payload shape does not change. A signed notification must declare format: JSON. The default text body is a sentence for a chat channel; signing it authenticates nothing a verifier reads. The loader and the published schema both refuse the combination, and the variable name uses the same grammar as registries.passwordEnv. A signed send is retried, because a verifying receiver is one that records the event: at most three attempts within 15 seconds, retrying only a network error, a 429, or a 5xx, with the same webhook-id and a fresh timestamp and signature each time. A 4xx is the receiver refusing the request and is not repeated. Fail-open holds: a missing or malformed secret, or exhausted retries, is the same stderr warning as any webhook problem, and the error names the variable, never its value. An unsigned send is one attempt, exactly as before. Scheduled jobs sign too. The host has no Onebox at 2am, so ob deploy resolves the key from the operator's environment and writes it into the root-only notifier beside the webhook URL, and the notifier signs each attempt with openssl over the body curl posts. The webhook-id is the systemd invocation id plus the notification's position, so retries repeat it. The unit's TimeoutStopSec grows by ten seconds for the retry budget. When the secret is unavailable at deploy, the deploy warns and the notifier logs that it did not send: an unsigned request to a receiver that verifies signatures is one it must reject. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The host notifier signed with openssl dgst -mac HMAC -macopt hexkey:..., which puts the key in the argument list of a running process, where ps and /proc/<pid>/cmdline show it to every user on the host. openssl's HMAC options, dgst -hmac and mac -macopt alike, only take the key that way, and the host has no Onebox to sign for it. ob deploy now precomputes HMAC-SHA256's two keyed blocks (RFC 2104) and writes them as root-only files beside the notifier, which finds them through $0. The host computes the HMAC as two plain openssl dgst -sha256 runs over those files and the body, so no command takes the key or anything derived from it as an argument, and the notifier text no longer contains it. Each deploy clears the pad files before writing the current ones, and unit removal deletes them. A notifier whose pads are missing logs that it did not send. Tests run the notifier as systemd does, record the argv of every openssl and curl it starts, and assert that neither those nor the rendered script contain the key, its encodings, or the pads; the pads are checked against crypto/hmac, and schedule apply is checked to write them over stdin. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Four review findings on signed notifications. The retry budget was untested: the dead-endpoint test dialed a port that refuses at once. The per-attempt timeout and the signed budget are now package variables, and a test whose receiver hangs past the attempt timeout checks that the send ends at the budget with "not delivered within" in its error. Several signed notifications to dead receivers added their budgets together, because ob sent them one after another. notify.SendAll sends every notification at once and returns failures in name order, so a verb's notification tail stays about one budget however many webhooks are configured. writeServiceFile stages each pad as <pad>.onebox-tmp, which the cleanup globs did not match, so a half-written key-equivalent file could stay on the host. Both cleanups now match every *pad* file beside the notifier. A deploy run without the secret exported deleted working pads and left the job unable to sign. It now keeps a notification's existing pads and warns "signing secret unavailable; kept existing pads"; pads are deleted only when signing is removed from the configuration or the job is removed. Pad files are named from a hash of the notification name rather than its position, so a kept pad can never sign a different notification after the set changes. The engine signing tests fail instead of skipping when openssl is missing and CI is set, so CI cannot pass with host signing unverified. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
What this changes
Outcome notifications can be signed with Standard Webhooks, so a receiver such as a deploy-verifying monitor can tell that an event came from this project's Onebox and not from someone who learned the webhook URL.
webhook-id,webhook-timestamp(unix seconds), andwebhook-signature: v1,<base64 HMAC-SHA256(key, id.timestamp.body)>, where the key is the base64-decoded part afterwhsec_. The signature covers the exact body bytes sent. The JSON payload shape does not change.signingSecretEnvuses the same env-var-name grammar asregistries.passwordEnv. A signed notification must declareformat: JSON, because the default text body is not what a verifier reads. The loader and the published schema both refuse the combination.webhook-idwith a fresh timestamp and signature. A 4xx is not retried. Unsigned sends are one attempt, unchanged.obsends every configured notification at once (notify.SendAll), so several dead receivers add up to about one budget, not one per webhook. Warnings print in name order.warn: notify webhook …line. A send cut off by the budget says "webhook not delivered within 15s". Errors name the variable and never carry its value. A signed notification whose secret is unavailable sends nothing, because an unsigned request to a verifying receiver is one it must reject.ob deployresolves the key from the operator's environment. It precomputes HMAC-SHA256's two keyed blocks (RFC 2104 ipad/opad) and writes them as root-only files (0600, via stdin) beside the notifier, which finds them through$0. The host computes the HMAC as two plainopenssl dgst -sha256runs that read those files and the body curl posts. The key, and anything derived from it, never appears in any command's arguments,ps,/proc/<pid>/cmdline, or the notifier text.openssl's HMAC options (-hmac,-macopt hexkey:) are not used, because they only take the key on the command line.webhook-idismsg_<INVOCATION_ID>_<n>. The host allows 3 attempts of 4s each, 1s apart, and the unit'sTimeoutStopSecgrows by 10s when the job can send a signed notification. Pad files are named from a hash of the notification name, so a kept pad can never sign a different notification. If the secret is unset or malformed at deploy, the deploy warns "signing secret unavailable; kept existing pads" and keeps the pads already on the host, so the job goes on signing with the last good key. Pads, including half-written.onebox-tmpstaging copies, are deleted only when signing is removed from the config or the job is removed. A host with no pads logs "not sent", and a host without openssl logs the send as failed.Why this is correct
internal/notify/sign_test.gochecks the signature against an independent HMAC computed in the test, and against the Standard Webhooks reference example (msg_p5jXN8AQM9LWM0D4loKWxJek,1614265330). It also covers: header presence, no signing headers on unsigned sends, retry with a stable id on 5xx and 429, giving up after 3 attempts, no retry on 400/401/404, a dead endpoint staying within the budget, and secret-free errors for unset, unprefixed, non-base64, and empty secrets, none of which send a request.SendAlltest with four hanging receivers proves the total stays about one budget.internal/engine/schedule_signing_test.goruns the generated notifier the way systemd does (sh <path>) with real openssl and a curl stub, then verifies each attempt's signature in Go. It covers a stable id across 503 → 000 → 204, no retry on 401, no send plus warnings when the secret is unset, no send when the pads are missing, and the stop-timeout extension. It also records the argv of every openssl and curl process and asserts that neither the argv nor the rendered script contains the secret, the key (raw, hex, or base64), or the pads. Two further checks: the pads reproducecrypto/hmacfor short, 64-byte, and over-long keys, andScheduleApplywrites the pads over stdin and clears stale ones. Three more tests: the cleanup command, run against real files, removes stale pads and staging copies but keeps the pads it was told to keep; a deploy without the secret keeps the pads and warns; and kept pads still produce a verifiable signature. These host tests fail rather than skip without openssl whenCIis set.contract-verdicts.json, and the published schema agrees with the loader.Effect on the safety envelope
None for operations: notifications stay fail-open and never block or fail a verb. A signed notification can add at most 15s to a verb's notification step (unsigned stays at 5s). Scheduled-job units with a signed notification get a 10s longer
TimeoutStopSec. Key material (the HMAC pads) now lives on the target host in root-only files beside the notifier, never in a command line.Checklist
just checkpasses locally.just checkverifies this).Ran:
just check(passes) andgolangci-lint runon the touched packages (0 issues). Not run:just e2e(Docker suite) and the fulljust ci.🤖 Generated with Claude Code