Skip to content

feat(notify): sign notifications with Standard Webhooks - #240

Merged
vishr merged 3 commits into
mainfrom
feat/notify-signing
Nov 26, 2026
Merged

vishr merged 3 commits into
mainfrom
feat/notify-signing

Conversation

@vishr

@vishr vishr commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

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.

notifications:
  facet:
    webhook: https://facet.example.com/hooks/onebox
    format: JSON
    signingSecretEnv: FACET_WEBHOOK_SECRET   # holds whsec_<base64>
  • Headers. webhook-id, webhook-timestamp (unix seconds), and webhook-signature: v1,<base64 HMAC-SHA256(key, id.timestamp.body)>, where the key is the base64-decoded part after whsec_. The signature covers the exact body bytes sent. The JSON payload shape does not change.
  • Validation. signingSecretEnv uses the same env-var-name grammar as registries.passwordEnv. A signed notification must declare format: JSON, because the default text body is not what a verifier reads. The loader and the published schema both refuse the combination.
  • Retries (signed only). At most 3 attempts within a 15s total budget (5s per attempt, with 0.5s and 1s backoff). Only network errors, 429, and 5xx are retried. Retries reuse the same webhook-id with a fresh timestamp and signature. A 4xx is not retried. Unsigned sends are one attempt, unchanged.
  • Concurrent sends. ob sends 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.
  • Fail-open. A missing or malformed secret, or exhausted retries, is the usual 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.
  • Scheduled jobs sign too. ob deploy resolves 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 plain openssl dgst -sha256 runs 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-id is msg_<INVOCATION_ID>_<n>. The host allows 3 attempts of 4s each, 1s apart, and the unit's TimeoutStopSec grows 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-tmp staging 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.go checks 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.
  • The signed-send bounds are package variables in tests. A receiver that hangs past the per-attempt timeout proves the send stops at the budget with "not delivered within". A SendAll test with four hanging receivers proves the total stays about one budget.
  • internal/engine/schedule_signing_test.go runs 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 reproduce crypto/hmac for short, 64-byte, and over-long keys, and ScheduleApply writes 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 when CI is set.
  • The conformance cases for the new validation are recorded in 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 check passes locally.
  • Tests cover the new behaviour, including the failure paths.
  • Generated documentation is current (just check verifies this).
  • I have accepted the CLA, or will when the bot asks on my first pull request.

Ran: just check (passes) and golangci-lint run on the touched packages (0 issues). Not run: just e2e (Docker suite) and the full just ci.

🤖 Generated with Claude Code

vishr and others added 3 commits November 25, 2026 22:25
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>
@vishr
vishr merged commit 63c0a28 into main Nov 26, 2026
6 checks passed
@vishr
vishr deleted the feat/notify-signing branch November 26, 2026 07:21
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.

1 participant