Repository navigation
feat: optional mTLS client auth for custom webhook - #10
Merged
Merged
Conversation
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>
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.
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 withwebhook_auth_headerfrom #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
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_urlrejection, path-with-quote rejection, mTLS+webhook_auth_headercombined load. Suite grew 42 → 53, all pass.meson compile -C buildzero warnings,meson test -C build4/4 OK,clang-tidy -p build src/config.c src/notify.cclean.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_memfdrefactor (positional args →curl_config_tstruct) 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), keepingargvminimal and uniform is the right shape — verifiable withps auxfduring 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: truerejects them at the TLS handshake before the HTTP request even starts.The validator (
validate_tls_path) mirrors the protection level ofpamsignal.confitself:O_NOFOLLOWopen, regular-file required, ownership outside{root, geteuid()}rejected,webhook_client_keyadditionally rejected ifS_IRGRP|S_IROTHis set. Path strings constrained to printable ASCII minus"and\so they're safe in the curl-Kconfig file.Pre-commit checklist
clang-format -i src/*.c include/*.h tests/*.cproduced no diff.clang-tidy -p build src/*.c tests/*.creports zero warnings/errors.meson compile -C buildproduces zero warnings.meson test -C build— all 4 suites pass; 11 new cases cover the change.CHANGELOG.mdupdated under## Unreleased→### Features.feat:, imperative, ≤72 chars).curl_config_trefactor produces byte-identical wire output for the four legacy callers.Notes for the reviewer
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. Newwebhook_curl_config(cfg)helper builds the full struct for the three webhook entry points.build_secrets_memfdbuffer 2048 → 4096 to fit four 512-char path/header lines without truncation. Eachsnprintfappend is bounds-checked with the standard(size_t)n + (size_t)m >= sizeof(buf)pattern (widening before addition, not after — caught byclang-tidybugprone-misplaced-widening-caston the first revision and fixed before this PR).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.open()and curl-timeopen()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 existingpamsignal.confvalidation.🤖 Generated with Claude Code