// insights

HashiCorp Vault auto-unseal with a Luna HSM via PKCS#11

Contents

This is the hands-on companion to the shared root-of-trust chapter: connecting HashiCorp Vault to a Luna Network HSM so Vault’s root key is protected by, and its unseal automated through, the HSM’s PKCS#11 interface. Done properly, a Vault node reboots and comes back unsealed with no human typing key shares at 3am. Done casually, you build a system whose startup depends on an HSM path nobody monitored.

Vault-side syntax below is verified against HashiCorp’s current pkcs11 seal documentation; Luna-side commands against the Luna Network HSM 7 documentation on thalesdocs.com. Where a detail is version- or edition-dependent we say so — and if your output differs, trust the vendor docs for your release over any blog post, including this one.

Step 1: The licensing reality check

Do this before you request a partition, because it kills more of these projects than any technical issue: the pkcs11 seal is a Vault Enterprise feature. Vault Community Edition does not support HSM auto-unseal at all — its auto-unseal options are the cloud KMS and transit seal types. Specifically:

  • You need a Vault Enterprise licence, and you need the HSM-enabled Enterprise binary — distributed separately as vault_<version>+ent.hsm from HashiCorp’s release server. A standard Enterprise binary will refuse the seal stanza with “KMS type ‘pkcs11’ requires the Vault Enterprise HSM binary”.
  • The HSM binary has historically been Linux/amd64 only (it links against the PKCS#11 library via libltdl). Check the current release matrix for your platform before you promise anything on other architectures.
  • Enterprise also unlocks seal wrap — per-object encryption of selected Vault data under the HSM key, which is the feature that makes the HSM more than an unseal convenience and is worth reading about before you design the partition.

If you’re on Community Edition, stop here: no configuration below will work, and pretending otherwise wastes a partition. The architectural alternative — Shamir key shares held by custodians — is operationally painful but supported everywhere.

Step 2: Luna client install and NTLS registration on every Vault node

Each Vault server is an ordinary Luna client. Install the Luna HSM Client software on every node in the cluster, then register each node against the appliance(s) over NTLS — certificate exchange, client register, partition assignment, then verify. The full procedure, including recovering the registration after an IP change, is in our NTLS client registration walkthrough; the short version per node:

vtl createCert -n vault01.agency.gov.au
vtl addServer -n hsm01.agency.gov.au -c server.pem
# on the appliance (lunash):
lunash:> client register -client vault01 -hostname vault01.agency.gov.au
lunash:> client assignpartition -client vault01 -partition vault-unseal
# back on the node:
vtl verify

vtl verify must show the partition as a slot on every node before you touch Vault configuration. The PKCS#11 library the seal will load ships with the client — on Linux, conventionally at /usr/safenet/lunaclient/lib/libCryptoki2_64.so (path varies by client version; confirm on your install).

Step 3: Partition and roles for Vault

Give Vault its own partition — per the partition-per-consumer pattern, its Crypto Officer credential should exist in exactly one place: Vault’s seal configuration. The workload is tiny (unseal-time operations plus any seal-wrapped reads and writes), so this partition never drives capacity planning; it exists for isolation.

Initialise the partition’s roles as usual: the Partition Security Officer initialises the Crypto Officer (CO), and the CO can initialise a Crypto User (CU). The role split matters here: on Luna, the CU role can use existing keys but object creation belongs to the CO. Vault needs two keys in the partition — an AES encryption key and an HMAC key. You have two clean options:

  • Let Vault create them: set generate_key = "true" in the seal stanza and run Vault with a credential that can create objects (the CO PIN). Vault generates the keys on first start if the labels don’t exist.
  • Pre-create, then drop privilege: have the CO create the keys in a ceremony (or let Vault’s first start do it), then run Vault day-to-day with the CU PIN so the credential in Vault’s config cannot create or destroy partition objects. The least-privilege option, at the cost of one more credential to manage.

Whichever you choose, record it — an auditor will ask which role’s PIN sits in the config file, and “whichever worked” is the wrong answer.

Step 4: The seal “pkcs11” stanza

Add the seal stanza to the Vault server configuration on every node. A realistic Luna configuration:

seal "pkcs11" {
  lib            = "/usr/safenet/lunaclient/lib/libCryptoki2_64.so"
  token_label    = "vault-unseal"
  pin            = "vault-co-pin"
  key_label      = "vault-unseal-key"
  hmac_key_label = "vault-hmac-key"
  generate_key   = "true"
}

Parameter notes, verified against the current HashiCorp documentation:

  • lib — path to the PKCS#11 shared library. Required.
  • slot or token_label — one of the two is required. Prefer token_label (the partition label): slot numbers can shift when partitions or HA virtual slots are added to the client, and a moved slot number is a Vault that won’t start.
  • pin — the partition role PIN from Step 3. It can be supplied via the VAULT_HSM_PIN environment variable instead of the file; on balance we prefer the file with tight permissions over an environment variable visible in process metadata, but either beats a world-readable config.
  • key_label / hmac_key_label — labels of the AES and HMAC keys. Both required.
  • mechanism — optional; Vault selects the best mechanism available from the library. 0x1087 (CKM_AES_GCM) is the modern choice on Luna; CBC variants require an accompanying HMAC mechanism.
  • max_parallel — concurrent HSM requests, default 1. Leave it alone until you have evidence.

Step 5: Initialise against the HSM

For a fresh cluster, start Vault and initialise:

vault operator init -recovery-shares=5 -recovery-threshold=3

Note what you get back: recovery keys, not unseal keys. With an HSM seal, Vault’s root key is protected by the HSM and unsealing is automatic; the recovery shares exist for privileged operations (generating a root token, certain rekeys) — they cannot unseal Vault if the HSM is gone. Distribute them to custodians with the same ceremony discipline you’d apply to any key shares, and record clearly in the runbook that they are not an HSM-outage escape hatch. Restart a node and confirm it returns to Sealed: false with nobody touching it — that reboot test, done now, is the whole point of the exercise.

Step 6: Migrating an existing Shamir cluster

An existing cluster on Shamir seals migrates in place. The procedure per current HashiCorp docs: stop the cluster, add the seal "pkcs11" stanza to every node’s configuration, restart, and have your custodians run the unseal with the migrate flag, entering the existing Shamir shares to threshold:

vault operator unseal -migrate

On completion the Shamir unseal keys become recovery keys, and subsequent restarts auto-unseal from the HSM. Two operational cautions. First, on Integrated Storage (Raft), update the seal configuration on all nodes before restarting them, so the cluster can re-establish quorum on the new seal — migrating nodes piecemeal is how you end up with a cluster arguing with itself. Second, this is the reverse-gear procedure too: migrating off the HSM later means marking the pkcs11 seal disabled = "true" alongside the new seal stanza and running the same -migrate flow with recovery keys. Knowing the exit exists (and rehearsing it in non-prod) is part of the risk assessment for making Vault HSM-dependent at all.

Step 7: The failure drill — HSM down at startup versus runtime

Same discipline as the CyberArk failure drill, same asymmetry, and the parallel is worth drilling into the NOC because the two systems will often share the same Luna estate:

  • HSM unreachable at startup: the node cannot decrypt its root key, so it cannot auto-unseal. It sits sealed — the process runs and the API answers, but vault status shows Sealed: true and every secret operation fails. Nothing recovers until the HSM path returns; recovery keys will not unseal it.
  • HSM lost at runtime: an unsealed node has its keys in memory and does not re-seal because the HSM dropped. Routine secret reads and writes generally continue. What fails is anything that needs a fresh HSM operation — notably reads and writes of seal-wrapped data, and seal-dependent maintenance operations — and, critically, any node restart during the outage converts the incident from “degraded” to “down”. Exact runtime behaviour varies by Vault version and by what you seal-wrapped; rehearse it in non-prod rather than trusting this paragraph.

The operational corollaries write themselves into the runbook: do not restart Vault nodes during an HSM incident; monitor the NTLS path from every Vault node (TCP 1792) and the appliance’s health independently of Vault’s own health endpoint; and make the unseal partition an HA group across appliances so a single HSM failure never becomes a Vault incident in the first place. A sealed-node alert should page whoever owns the HSM estate as well as the Vault team — the fix is usually on the other side of that fence.

Step 8: Partition activation for unattended nodes

One last trap, specific to PED-authenticated (multi-factor) partitions: auto-unseal is only automatic if the partition itself is usable without a human presenting a PED key. That is what partition activation and auto-activation policies are for — caching the authenticated state so client logins with the challenge secret succeed unattended, and surviving a short power loss without a re-ceremony. If your Vault partition is PED-authenticated and not activated, every appliance reboot quietly re-introduces the 3am human you built all this to remove. Password-authenticated partitions don’t have this problem. The policy numbers, commands and caveats are covered in configuring partition policies for unattended startup — apply that chapter to the Vault partition before you sign off the build, and prove it with a full power-cycle test of one appliance while watching Vault stay unsealed.


Where this leaves you

Vault now unseals from the Luna estate, its recovery keys are with custodians, and its failure behaviour is drilled rather than discovered. The next consumer in the queue has a different shape: database TDE, where SQL Server’s EKM provider and Oracle’s PKCS#11 wallet integration each bring their own quirks to the same partition-per-consumer pattern. Those are upcoming chapters. The series so far lives at The Luna Field Guide.

// cryptographic hsm solutions
Running hardware you can’t afford to get wrong?

Securitribe designs, deploys and operates Thales Luna HSM estates — partitions, HA, key ceremonies and DR that stand up to audit.

Explore Cryptographic HSM SolutionsBook a strategy call →
// more insights

Keep reading