Skip to content

feat(use-cases): TLS keys in an HSM over PKCS#11 - #42

Merged
pigri merged 4 commits into
mainfrom
feat/hsm-tls-keys
Nov 10, 2026
Merged

pigri merged 4 commits into
mainfrom
feat/hsm-tls-keys

Conversation

@pigri

@pigri pigri commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

What

A new use case, use-cases/hsm-tls-keys: TLS private keys in an HSM, or any PKCS#11 token, that Synapse signs handshakes with. The key never leaves the device. It needs Synapse 0.8.9 or later.

  • Config set: config.yaml with a proxy.hsm block and upstreams.yaml with tls.terminate hosts. One certificate's .key is a pkcs11: URI and one is a software key, in the same directory.
  • Demo: a SoftHSM token made by make-token.sh, run with Docker Compose, and a client.sh that checks the served certificates. No hardware is needed.
  • README: covers the PIN file rules, module failover, the OpenSSL pkcs11 provider, retry_interval_secs, on_failure, what needs a restart, and certbot with --csr for HSM-backed certificates.

scripts/check.sh gives a set with an hsm: block a 0600 test PIN file through PROXY_HSM_PIN_FILE. The set names /hsm/pin, which exists only in the container. Other sets run with the PIN env vars unset, so a caller's value cannot change their result. This needs a 0.8.9 build where --check-config honours PROXY_HSM_PIN_FILE.

Tests

  • New controls in scripts/test-check.sh (fixtures/hsm-pin):

    • the HSM set fails without a PIN file;
    • it passes through check.sh;
    • a caller's PROXY_HSM_PIN_FILE does not reach a set without hsm.
    • With the old check.sh, the last two fail.
  • make test-check passes with a 0.8.9 release build.

  • make test: use-cases/hsm-tls-keys passes. use-cases/lb-passthrough fails, as it does on main against a 0.8.9 build, because of its "passes through HTTP only" warnings. That is not from this PR, and it gets its own fix.

  • make lint passes.

  • review

Code-reviewed: 78207b4 — 7 findings

  • check.sh injected a test PIN into an hsm block with no pin_file: fixed in 6bf835b, it injects only for a named pin_file; check-config does not require one, so the comment states the limit
  • make-token.sh passes the PINs on the command line: fixed in 6bf835b, the README's production notes say so
  • a half-made token is provisioned again on rerun: fixed in 6bf835b, make-token.sh stops and says to run down -v
  • listeners on 80/443 need root in the container: not fixed, a nit
  • host ports 8085/8443 clash with tcp-mss and certbot: not fixed, a nit
  • the image's pkcs11 provider is not proven by a published image: not fixed, a nit; the README's "Not checked here" says so
  • force_https redirects to a port the host does not map: not fixed, a nit

Not re-reviewed: 6bf835b — should-fix batch, no must-fix

@pigri
pigri marked this pull request as ready for review November 10, 2026 18:33
@pigri
pigri merged commit 3d0f4a7 into main Nov 10, 2026
3 checks passed
@pigri
pigri deleted the feat/hsm-tls-keys branch November 10, 2026 18: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.

1 participant