Skip to content
AnswerWell geo Documentation

Research · 7 min read · Answerwell

Keyless SSL Hardware Security Module PKCS#11 Configuration

How Cloudflare Keyless SSL uses PKCS#11 HSMs for private keys: URI setup, supported modules, limits, metrics, and verification.

This page summarizes Cloudflare documentation on running Keyless SSL with private keys held in a Hardware Security Module (HSM) via PKCS#11, instead of on disk under /etc/keyless/keys/. It covers how gokeyless finds keys, how to write a PKCS#11 URI in gokeyless.yaml, which HSM products are documented, operational limits, and how to confirm the key server is healthy.

Keyless SSL: what the key server does and when the HSM is used

Section titled “Keyless SSL: what the key server does and when the HSM is used”

Keyless SSL lets you use your own TLS certificates at Cloudflare’s edge while keeping private keys on infrastructure you control. The key server (gokeyless) runs on your side; Cloudflare’s keyless client connects during new TLS handshakes (default TCP port 2407) to request signing and related operations.

The key server is a daemon that you run on your own infrastructure. The key server receives inbound requests from Cloudflare’s keyless client on TCP port 2407 (by default) so you must make sure that your firewall and other access control lists permit these requests from Cloudflare’s IP ranges ↗︎.

— Cloudflare, Glossary — key server

Keyless SSL is an Enterprise paid add-on; you supply CA-issued certificates—Cloudflare does not issue certs for Keyless. If you upload a custom certificate but want keys to stay on your network, Keyless is the documented path (Custom certificates — Keyless SSL).

For HSM-backed keys, the key server still never holds plaintext private key material in its filesystem store; it delegates crypto to the HSM through PKCS#11 (Hardware security modules).

Why use an HSM with Keyless SSL instead of disk storage?

Section titled “Why use an HSM with Keyless SSL instead of disk storage?”

Hardware Security Modules (HSMs) facilitate a higher level of protection for your private keys over storing them directly on your key server. The primary responsibility of an HSM is safeguarding private keys and performing operations such as signing or encryption internally.

— Cloudflare, Hardware security modules — Why use Keyless SSL with an HSM?

Disk storage is supported (private_key_stores with dir: /etc/keyless/keys, PEM/DER, mode 400, owner keyless), but PKCS#11 fits policies that require tamper resistance, FIPS 140 levels, and keys that never leave the module. Reference architectures describe Keyless plus Cloudflare Tunnel so key operations reach an on-prem or cloud HSM without exposing the key server on the public internet (FIPS 140 level 3 compliance with Cloudflare Application Services).

PKCS#11 configuration: token setup and gokeyless private_key_stores

Section titled “PKCS#11 configuration: token setup and gokeyless private_key_stores”

Before editing gokeyless.yaml, initialize the HSM (keys, PIN, token label) per the vendor’s instructions. Cloudflare stresses restricting key-server access and reading manufacturer docs (Configuration — Hardware security modules).

Discover token and key labels with pkcs11-tool:

pkcs11-tool --module <module-path> --list-token-slots
pkcs11-tool --module <module-path> --pin <pin> \
--list-token-slots --login --list-objects

Add PKCS#11 entries alongside—or instead of—a directory store in /etc/keyless/gokeyless.yaml:

private_key_stores:
- dir: /etc/keyless/keys
- uri: pkcs11:token=...;object=...?module-path=...&pin-value=...&max-sessions=1

Docker and environment variables cannot set private key locations; you still need private_key_stores (or --private-key-dirs / --private-key-files) for keys (Run with Docker).

PKCS#11 URI format: module-path, token, and key object

Section titled “PKCS#11 URI format: module-path, token, and key object”

A PKCS#11 URI is a sequence of attribute value pairs separated by a semicolon that form a one-level path component, optionally followed by a query.

— Cloudflare, Configuration — PKCS#11 URI

General form: pkcs11:path-component[?query-component]. Keyless expects:

Attribute Role
module-path (query) Path to the PKCS#11 .so library
token, serial, or slot-id (path) Which PKCS#11 token
id or object (path) Which key pair

Keyless requires the following three attributes be specified: Module … Token … Slot …

— Cloudflare, Configuration — PKCS#11 URI

Examples from Cloudflare’s docs include SoftHSM, Thales/nShield (libcknfast.so), YubiKey PIV, and Luna (libCryptoki2_64.so) (Configuration — Examples).

max-sessions, pin-value, and vendor-specific query fields

Section titled “max-sessions, pin-value, and vendor-specific query fields”

For certain modules, a query attribute max-sessions is required in order to prevent opening too many sessions to the module. Certain additional attributes, such as pin-value, may be necessary depending on the situation.

— Cloudflare, Configuration — PKCS#11 URI

After saving config, restart and check the service:

sudo systemctl restart gokeyless.service
sudo systemctl status gokeyless.service -l

PKCS#11 limitation: one module library per key server

Section titled “PKCS#11 limitation: one module library per key server”

For now, only one PKCS#11 module can be used at a time, so if you have keys on multiple HSMs, we recommend using p11-glue to consolidate access through one module ↗︎.

— Cloudflare, Configuration — Limitations

Documented HSM integrations: cloud vs on-premise

Section titled “Documented HSM integrations: cloud vs on-premise”

The key server communicates with HSMs via PKCS#11, so any HSM supporting the standard can be used with Keyless SSL.

— Cloudflare, Hardware security modules — Communicating using PKCS#11

Cloudflare lists tested interoperability and cloud offerings:

Category Documented products
Modules with dedicated guides Entrust nShield Connect, Gemalto SafeNet Luna (Azure Dedicated / Luna workflows), SoftHSMv2, YubiKey Neo
Cloud HSM (tested) AWS CloudHSM, Azure Dedicated HSM, Azure Managed HSM, Fortanix DSM, IBM Cloud HSM, Google Cloud HSM

Pattern for Luna-style partitions (Azure Dedicated, IBM): create partition, assign to client, initialize, generate key pair and CSR on-HSM, then point gokeyless at token=KeylessSSL;object=myrsakey with libCryptoki2_64.so (Azure Dedicated HSM).

Pattern for AWS CloudHSM: import keys with key_mgmt_util, then URI like pkcs11:token=cavium;object=mykey?module-path=/opt/cloudhsm/lib/libcloudhsm_pkcs11_standard.so&pin-value=...&max-sessions=1 (AWS cloud HSM).

Pattern for Entrust nShield: use pkcs11-tool -O to read the private key label, then pkcs11:token=accelerator;object=rsa-privkey?module-path=/opt/nfast/toolkits/pkcs11/libcknfast.so&max-sessions=4 (Entrust nShield Connect).

Azure Managed HSM uses Azure Key Vault key import and managed identity for sign permission, then adds the key URI from az keyvault key import into private_key_stores (Azure Managed HSM).

Google Cloud HSM documents importing a DER key into Cloud KMS HSM and adding the resource name from the UI to YAML rather than a classic PKCS#11 URI in the excerpted steps (Google Cloud HSM).

Follow the matching vendor tutorial for provisioning; this page stops at the shared PKCS#11 URI + restart step all guides repeat.

Reaching the key server: Tunnel, enrollment, and two certificate types

Section titled “Reaching the key server: Tunnel, enrollment, and two certificate types”

Routing choices are Cloudflare Tunnel, Public DNS, or Docker (Get started). Tunnel is preferred for private key servers; public DNS exposes origin IP and cannot be proxied.

Upload Keyless SSL certificates in the dashboard with the key server hostname, port 2407, and the public site certificate PEM (Public DNS — Upload Keyless SSL Certificates). Do not confuse:

Certificate SAN should contain
Edge (Keyless SSL) certificate Site hostnames only (e.g. www.example.com)
Key server authentication certificate Key server hostname only

Do not add your key server hostname to the SAN of your public edge certificate.

— Cloudflare, Public DNS — Certificates used in Keyless SSL

In /etc/keyless/gokeyless.yaml, set hostname, zone_id, and enrollment credentials. API Token with Zone → SSL and Certificates → Edit is recommended; Origin CA API key is deprecated and stops working September 30, 2026 (Cloudflare Tunnel — Configure). Migrate to gokeyless 1.18.0+ and api_token or KEYLESS_API_TOKEN.

On first start with enrollment fields set, the key server auto-enrolls its mTLS authentication certificate with Cloudflare (Cloudflare Tunnel — Activate).

Prometheus metrics: spotting HSM and PKCS#11 problems

Section titled “Prometheus metrics: spotting HSM and PKCS#11 problems”

gokeyless exposes Prometheus metrics for signing latency, errors, and connection health (Key server metrics).

For HSM deployments, watch keyless_request_exec_duration_per_opcode with error="cryptography error". Documentation ties cryptography error to PKCS#11 session pool timeout, HSM errors, and key type mismatch (Key server metrics — error label).

When using a hardware security module (HSM) with a PKCS#11 session pool, the pool wait timeout is hardcoded at 10 seconds. A pool exhaustion event will therefore always appear in the +Inf bucket.

— Cloudflare, Key server metrics — Histogram buckets

A 99th-percentile RSA exec duration approaching 10 seconds indicates PKCS#11 session pool exhaustion; address pool sizing per Scaling and benchmarking and HSM vendor guidance. RSA signing is far more expensive than ECDSA; plan capacity accordingly (Scaling and benchmarking — Key type).

For availability, run at least two key servers behind a load balancer with health checks on port 2407 (High availability).

Common mistakes when combining Keyless SSL and HSMs

Section titled “Common mistakes when combining Keyless SSL and HSMs”
  • Wrong certificate SANs: edge cert includes key-server hostname, or auth cert missing key-server hostname—clients abort after cert exchange (Troubleshooting).
  • Proxied DNS for key server hostname on a Cloudflare zone: resolves to edge, not your server (Public DNS).
  • Mismatched PKCS#11 URI: wrong object/id, token label, or module-path; verify with pkcs11-tool --list-objects.
  • Multiple HSM vendors without p11-glue: only one PKCS#11 module per gokeyless instance (Configuration — Limitations).
  • Still on Origin CA Service Key after September 30, 2026—enrollment and refresh fail (Cloudflare Tunnel — Configure).
  • Treating SoftHSMv2 as hardware-grade security for compliance (SoftHSMv2).
  1. On the key server host, confirm the HSM token and private key object with pkcs11-tool using the same module-path and PIN as in Configuration.

  2. Verify gokeyless is active: sudo systemctl status gokeyless.service -l, and inspect logs with sudo journalctl -f -u gokeyless (Troubleshooting — Check the logs).

  3. In the Cloudflare dashboard, confirm uploaded Keyless SSL certificates reference the correct key server hostname and port 2407 (Public DNS — Upload Keyless SSL Certificates).

  4. Scrape the Prometheus /metrics endpoint and check RSA histograms for error="cryptography error" or p99 latency near 10s (Key server metrics).

  5. You can check automatically in Answerwell (our tool): https://answerwell.org/workspace

If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact wording you are asking about.