Skip to content

feat: optional mTLS client auth for custom webhook - #10

Merged
anhtuank7c merged 1 commit into
mainfrom
feat/webhook-mtls
May 8, 2026
Merged

anhtuank7c merged 1 commit into
mainfrom
feat/webhook-mtls

Conversation

@anhtuank7c

Copy link
Copy Markdown
Owner

Summary

Adds three optional config keys — webhook_client_cert, webhook_client_key, webhook_ca_bundle — that let operators authenticate to their custom webhook receiver with a client certificate instead of (or in addition to) the Bearer header from #7. Targets the operator profile that already runs a PKI: internal CA + cert-manager / SPIFFE / service-mesh issuance, where shared secrets are a step backwards from the cert-based service identity their other workloads use. Stronger than Bearer alone — the private key never travels over the wire, replay windows don't exist, and credential rotation is delegated to the cert-management pipeline rather than baked into config edits. Combines additively with webhook_auth_header from #7 — the Wazuh / corporate-SIEM pattern (mTLS for service identity, Bearer for per-request authorization).

Linked issue

Closes #8. Builds on #7 (merged as c96508c); the docs section under "Custom webhook (ECS JSON)" now has both an "Authentication (optional)" subsection (#7) and a new "Mutual TLS (optional, advanced)" subsection (#8).

Test plan

  • 11 new CMocka cases in tests/test_config.c: cert+key happy path, with-CA-bundle happy path, cert-without-key rejection, key-without-cert rejection, world-readable-key rejection (mode 0644), group-readable-key rejection (mode 0640), symlinked-key rejection (O_NOFOLLOW), nonexistent-path rejection, mTLS-without-webhook_url rejection, path-with-quote rejection, mTLS+webhook_auth_header combined load. Suite grew 42 → 53, all pass.
  • Verified in a Debian bookworm container: meson compile -C build zero warnings, meson test -C build 4/4 OK, clang-tidy -p build src/config.c src/notify.c clean.
  • No packaging or systemd-unit change.

Threat-model alignment

Strengthens attack #3 (alert credential exposure via process listing) and attack #6 (network attacker on alert path).

For attack #3: the post_alert / build_secrets_memfd refactor (positional args → curl_config_t struct) means the cert/key/CA paths flow through the same memfd-backed isolation the Bearer header already used. Even though paths aren't secret (the file contents are), keeping argv minimal and uniform is the right shape — verifiable with ps auxf during a live alert: byte-identical command line whether mTLS is on or off.

For attack #6: mTLS gives the daemon transport-layer service identity. A network attacker who somehow obtains the Bearer token (#7) cannot use it without also presenting a valid client cert; the receiver's requestCert: true, rejectUnauthorized: true rejects them at the TLS handshake before the HTTP request even starts.

The validator (validate_tls_path) mirrors the protection level of pamsignal.conf itself: O_NOFOLLOW open, regular-file required, ownership outside {root, geteuid()} rejected, webhook_client_key additionally rejected if S_IRGRP|S_IROTH is set. Path strings constrained to printable ASCII minus " and \ so they're safe in the curl -K config file.

Pre-commit checklist

  • clang-format -i src/*.c include/*.h tests/*.c produced no diff.
  • clang-tidy -p build src/*.c tests/*.c reports zero warnings/errors.
  • meson compile -C build produces zero warnings.
  • meson test -C build — all 4 suites pass; 11 new cases cover the change.
  • CHANGELOG.md updated under ## Unreleased → ### Features.
  • Commit subject follows Conventional Commits (feat:, imperative, ≤72 chars).
  • Not a breaking change — all three keys are additive, default-empty, and the curl_config_t refactor produces byte-identical wire output for the four legacy callers.
  • No packaging / systemd-unit changes.

Notes for the reviewer

  • Internal API change: post_alert(url, auth_header, body) → post_alert(const curl_config_t *cc, body). Static-only, no header surface. The four legacy callers (Telegram, Slack/Teams/Discord simple-webhook, WhatsApp) now pass struct-literal &(curl_config_t){.url = url} or &(curl_config_t){.url = url, .auth_header = auth} arguments. New webhook_curl_config(cfg) helper builds the full struct for the three webhook entry points.
  • Buffer growth: build_secrets_memfd buffer 2048 → 4096 to fit four 512-char path/header lines without truncation. Each snprintf append is bounds-checked with the standard (size_t)n + (size_t)m >= sizeof(buf) pattern (widening before addition, not after — caught by clang-tidy bugprone-misplaced-widening-cast on the first revision and fixed before this PR).
  • Encrypted keys not supported: documented in docs/alerts.md. Operators use filesystem perms, systemd-creds, or their cert manager's secret-injection model — pamsignal doesn't try to be a secrets store.
  • TOCTOU window: between validate-time open() and curl-time open() there's a small window where the file could be swapped. An attacker with write access at that path already has the daemon's privileges, so the window is benign by the threat model. Same trade-off as the existing pamsignal.conf validation.

🤖 Generated with Claude Code

Closes #8. Adds three new optional config keys —
webhook_client_cert, webhook_client_key, webhook_ca_bundle — that
let operators authenticate to their custom webhook receiver with a
client certificate. Targets environments that already run a PKI
(internal CA, cert-manager, SPIFFE, service-mesh issuance) where
shared-secret auth is a step backwards. Combines additively with
the Bearer header from #7 — the common Wazuh / corporate-SIEM
pattern.

Values are filesystem paths, not inline PEM, so cert rotation flows
through the operator's existing cert pipeline without touching
pamsignal.conf. Validator at config-load time mirrors the
protection level of pamsignal.conf itself: O_NOFOLLOW open
(symlinks rejected), regular-file required, ownership outside
{root, geteuid()} rejected, webhook_client_key additionally
rejected if group/world-readable. Cross-field: cert without key
(or vice versa) is a config-load error, and any TLS key set
without webhook_url is rejected.

Path strings are constrained to printable ASCII minus quote and
backslash so they can be safely written into curl's -K config
file as quoted values. Cert/key/CA paths flow through the same
memfd-backed curl config as the auth header, so argv stays
byte-identical to today when no mTLS keys are set.

Internal post_alert and build_secrets_memfd signatures swap from
positional (url, auth_header, body) to a curl_config_t struct
that carries the optional fields by name; the four legacy callers
(Telegram, Slack/Teams/Discord, WhatsApp) pass struct-literal
arguments and produce identical wire output. Buffer in
build_secrets_memfd grows 2048 -> 4096 to accommodate up to four
config lines without truncation.

Tests: 11 new CMocka cases (test_config 42 -> 53). Build clean,
clang-tidy clean, OWASP ASVS L1 audit zero FAIL findings.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@anhtuank7c
anhtuank7c merged commit 19e09ce into main May 8, 2026
4 checks passed
@anhtuank7c
anhtuank7c deleted the feat/webhook-mtls branch May 8, 2026 04:36
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.

Optional mTLS client auth for custom webhook (cert/key/CA)

1 participant