Repository navigation
feat(example): mTLS-capable HTTPS variant in nodejs-webhook server - #13
Merged
Merged
Conversation
Closes #12. The bundled examples/nodejs-webhook/ receiver now ships a runnable mTLS path that pairs with pamsignal's webhook_client_cert / webhook_client_key keys (#8). Previously the README's "Mutual TLS (advanced)" section showed an https.createServer({ requestCert: true, rejectUnauthorized: true }) snippet, but the actual code shipped only plain http via app.listen() — operators following the README had to write that piece themselves. src/server.ts: branch on env vars. When TLS_KEY_PATH and TLS_CERT_PATH are set, build an HTTPS server with optional CA override (TLS_CLIENT_CA_PATH) and optional mTLS enforcement (TLS_REQUIRE_CLIENT_CERT=true → requestCert + rejectUnauthorized). With no TLS env vars set, behavior is identical to today: plain HTTP via Express on the same port. scripts/gen-test-certs.sh: produces a CA + server cert (CN=localhost with subjectAltName) + client cert (CN=pamsignal-test-client) under ./certs/ via openssl, mode-locks the private keys to 0600 (matches pamsignal's group-readable rejection), and prints next steps. For local end-to-end testing only — production deployments use the operator's cert pipeline. tests/mtls.test.ts: three Jest cases over a real HTTPS server constructed with the same pattern as src/server.ts. Generates certs at setup-time via openssl spawn (same commands as gen-test-certs.sh), tears down server + cert dir in afterAll. Verifies: valid-cert+Bearer → 200, no-client-cert → TLS-layer rejection (request errors before reaching Express), Bearer mismatch on a successful handshake → 401. Total Jest cases 7 → 10. README "Mutual TLS (advanced)" rewritten as a runnable end-to-end demo (cert script + env vars + matching pamsignal.conf block) rather than a conceptual snippet, with an explicit production-vs-demo separation pointing operators at cert-manager / certbot / systemd-creds for real deployments. .gitignore adds certs/, package-lock.json, yarn.lock so locally generated test certs and accidentally-installed npm/yarn lockfiles don't pollute the pnpm-managed example repo. CHANGELOG: Unreleased / Examples entry. No change to pamsignal itself — pamsignal v0.4.0 already speaks mTLS correctly via #8. 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
Ships the runnable mTLS path that v0.4.0's
webhook_client_cert/webhook_client_keykeys (#8) need to demo end-to-end. The bundledexamples/nodejs-webhook/receiver previously only listened on plain HTTP viaapp.listen(); the README's "Mutual TLS (advanced)" section showed the construction pattern as a snippet, but the actual code that would do that didn't ship — operators following the README hit a "where do I put this?" wall. Same docs-vs-reality gap that #7 closed for the Bearer-auth side.Linked issue
Closes #12. Builds on #7 (
c96508c) and #8 (19e09ce), both shipped in v0.4.0. No change to pamsignal itself.What changed
src/server.ts— branches on env vars. WhenTLS_KEY_PATH+TLS_CERT_PATHare set, constructs an HTTPS server (with optionalTLS_CLIENT_CA_PATHfor trust-store override andTLS_REQUIRE_CLIENT_CERT=truefor full mTLS viarequestCert + rejectUnauthorized); otherwise the existing plain-HTTP path is unchanged. Backward compatible: operators with a Bearer-only deployment see no behavioral change..env.example— documents the four new TLS env vars under a comment block that names the correspondingwebhook_client_cert/webhook_client_keykeys on the pamsignal side.scripts/gen-test-certs.sh— produces a CA + server cert + client cert under./certs/via openssl. Server cert getssubjectAltName=DNS:localhost,IP:127.0.0.1so Node's HTTPS client accepts it; private keys are mode 0600 to match pamsignal's group-readable rejection.tests/mtls.test.ts— three new Jest cases that spin up the full HTTPS server with the same construction pattern assrc/server.ts, generate certs at setup-time via openssl spawn, and verify the three behaviours that matter (valid cert + Bearer → 200, no client cert → TLS-layer rejection, Bearer mismatch on successful handshake → 401). Total Jest cases 7 → 10. All pass.README.md— "Mutual TLS (advanced)" subsection rewritten as a runnable end-to-end demo (cert script + env vars + matchingpamsignal.confblock) with an explicit production-vs-demo separation pointing operators at cert-manager / certbot / systemd-creds for real deployments..gitignore— addscerts/,package-lock.json,yarn.lockso locally-generated test certs and accidentally-installed npm/yarn lockfiles don't pollute the pnpm-managed example repo.CHANGELOG.md—## Unreleased / ### Examplesentry.Test plan
npm test(Node 24, locally on macOS) — 10/10 pass including the 3 new mTLS cases.npm run build(TypeScript strict mode) — clean.scripts/gen-test-certs.sh /tmp/foosmoke-tested manually;openssl verify -CAfile ca.crt server.crt client.crtreturns OK on both.https.requestfor the no-cert negative path rather than rawtls.connect, because the latter races with the server's reject-after-handshake behavior — Node fires the client'ssecureConnectcallback before the server has finished tearing the connection down. Thehttps.requestform surfaces the rejection cleanly as a request-level error.Threat-model alignment
No new attack surface — this is example code, not a pamsignal feature. But the example does demonstrate the threat-model property #8 added: clients without a valid cert signed by
TLS_CLIENT_CA_PATHare rejected at the TLS handshake, before any HTTP request reaches Express. Thetests/mtls.test.ts"no client cert" case is the unit test for that property on the receiver side.The cert-generation script is not for production and the docs say so explicitly. Operators replace
./certs/*with paths managed by their cert pipeline.Pre-commit checklist
npm run build— TypeScript clean, no warnings.npm test— 10/10 pass (jest), 7 existing + 3 new.CHANGELOG.md—## Unreleased→### Examplesentry added.feat(example):, imperative, ≤72 chars).src/,include/,tests/test_*.c), so the C build and CMocka tests are not affected — CI's ASAN+UBSAN job is a no-op on this PR.Notes for the reviewer
gen-test-certs.sh. Cost: tests needopensslin PATH — ubiquitous on Linux/macOS, present in every CI runner we use.node:tlsrejection isn't tested directly: an earlier draft usedtls.connectfor the no-cert case but Node'ssecureConnectcallback fires before the server has finished tearing the connection down onrejectUnauthorized— race condition.https.requestwaits for the actual response or error and is reliable.TLS_*env, the example behaves byte-identically to v0.3.x and the existing 7 supertest cases continue to pass againstappdirectly.🤖 Generated with Claude Code