Thales Luna HSM¶
HelixIAM works with Thales Luna HSMs through its built-in PKCS#11 backend. With a realm in High assurance:
- the realm's signing keys (ES256, RS256 and PS256) and its key-encryption key are generated inside your Luna partition and never leave it;
- every access token, ID token and SAML assertion of that realm is signed by the HSM;
- the HelixIAM database holds only a reference to each key.
This page covers what is specific to Luna. Key custody (HSM and KMS) explains the assurance profiles, the backend settings and the failure behaviour that apply to every backend.
Tested with Thales Luna Cloud HSM
Thales Luna Cloud HSM on Data Protection on Demand (DPoD), FIPS mode, Luna client 10.9.4. HelixIAM was run on Kubernetes with the Helm chart and with Docker Compose. The tests covered High assurance with ES256, RS256 and PS256, token verification against the realm's JWKS, normal and emergency rotation, restarts, and clean shutdown. A Luna Network HSM uses the same Luna client and PKCS#11 library. Run the checks in Check that it works on yours.
Requirements¶
- HelixIAM 1.1.0-rc.28 or later.
- A Luna partition: a Luna Cloud HSM service on DPoD, or a partition on a Luna Network HSM.
- An initialised partition and Crypto Officer, one partition for each realm in High assurance. See Prepare the partition.
- The Luna client for Linux (64-bit). For a Luna Cloud HSM, it is the client zip you download for the
service. It contains:
- the PKCS#11 library
libs/64/libCryptoki2.so; - the plugin
plugins/libcloud.plugin; Chrystoki.confand the certificates.
- the PKCS#11 library
- The Crypto Officer PIN as a file, mounted read-only from a Secret. Never put the PIN in an environment variable.
- Network egress:
- For a Luna Cloud HSM: TCP 443 to
<region>.hsm.dpondemand.io(EU:eu.hsm.dpondemand.io) and toaccess.dpondemand.io. - For a Luna Network HSM: the port of your appliance.
- For a Luna Cloud HSM: TCP 443 to
The HelixIAM image already contains ca-certificates, which the Luna client needs for its TLS connections.
Treat the client configuration as a secret
Chrystoki.conf holds the service's client credentials. Keep it in a Kubernetes Secret, never in a ConfigMap,
an image or a Git repository. The same applies to the PIN.
Prepare the partition¶
For a Luna Cloud HSM:
- In the DPoD portal, create a Luna Cloud HSM service and download its client zip.
-
On a Linux host, unpack it in an empty directory:
The directory then holds
bin/64/lunacm,libs/64/libCryptoki2.so,plugins/libcloud.plugin,etc/openssl.cnf,Chrystoki.confand the three certificates. -
Start
lunacmfrom that directory (./bin/64/lunacm). If it starts without errors, the client reaches the service. Then initialise the partition and its roles:slot list slot set -slot <slot> partition init -label <partition-label> role login -name partition so role init -name crypto officer role logout role login -name crypto officer role changepw -name crypto officerpartition initasks for the partition security officer's password and the cloning domain. The Crypto Officer must change the password set by the security officer at its first login: the new password is the PIN HelixIAM uses. Keep it in a file that only you can read; you put it in a Secret below.
For a Luna Network HSM, your HSM administrator creates the partition and the Crypto Officer; the Luna documentation for your appliance has the steps.
Why the Crypto Officer
HelixIAM generates private, sensitive keys in the partition and disables and destroys them when they retire. On a Luna Cloud HSM the Crypto User can create public objects only, so HelixIAM logs in as the Crypto Officer.
One partition per High-assurance realm
High assurance needs a backend dedicated to one realm (see Dedicated key stores). Give each such realm
its own partition and backend. Several backends on one partition (one tokenLabel) work technically, but the
Crypto Officer of that partition can then use every realm's keys: use that only for a trial.
Set up on Kubernetes¶
The server runs as uid 10001 with a read-only root file system. The Luna client needs four things inside the container:
| What | Where (example) | How |
|---|---|---|
Chrystoki.conf and the certificates |
/opt/luna/conf |
A Secret, read-only |
The library and the plugin (libs/, plugins/) |
/opt/luna/libs, /opt/luna/plugins |
A read-only volume |
| A writable lock directory | /opt/luna/lock |
An emptyDir |
| The Crypto Officer PIN | /var/run/helix/custody/luna-1/pin |
The chart's pinSecret |
The library and the plugin hold no credentials, but they are too large for a Kubernetes Secret (1 MiB). Put them on a read-only volume that you prepare once:
hostPathon each node: the example below uses this.- A PersistentVolumeClaim or CSI volume with the same two directories also works.
Mount the Luna client at run time
The Luna client is Thales software. Mount it as shown here rather than building it into an image that you push to a registry.
1. Point Chrystoki.conf at the mounts¶
The Luna client reads its configuration from the directory named in the environment variable
ChrystokiConfigurationPath. Every path in Chrystoki.conf must be absolute and match where you mount the files.
Edit a copy of the Chrystoki.conf from the client zip. With the mounts on this page, the entries that name a file or
directory are:
LibUNIX64 = /opt/luna/libs/64/libCryptoki2.so;
MutexFolder = /opt/luna/lock;
PluginModuleDir = /opt/luna/plugins;
SSLConfigFile = /opt/luna/conf/openssl.cnf;
PartitionCAPath = /opt/luna/conf/partition-ca-certificate.pem;
PartitionCertPath00 = /opt/luna/conf/partition-certificate.pem;
SSLClientSideVerifyFile = /opt/luna/conf/server-certificate.pem;
- Already correct: in the DPoD client zip, the first three entries already point at
/opt/luna/.... - Change these: the certificate entries point at
/opt/luna/andSSLConfigFileat/opt/luna/etc/openssl.cnf. Change them to/opt/luna/conf/, and copyetc/openssl.cnfnext to the certificates. - Leave unchanged: the credential entries.
From the unpacked client directory:
mkdir -m 700 <conf-copy-dir>
sed -e 's#/opt/luna/etc/openssl.cnf#/opt/luna/conf/openssl.cnf#' \
-e 's#/opt/luna/partition-ca-certificate.pem#/opt/luna/conf/partition-ca-certificate.pem#' \
-e 's#/opt/luna/partition-certificate.pem#/opt/luna/conf/partition-certificate.pem#' \
-e 's#/opt/luna/server-certificate.pem#/opt/luna/conf/server-certificate.pem#' \
Chrystoki.conf > <conf-copy-dir>/Chrystoki.conf
cp etc/openssl.cnf partition-ca-certificate.pem partition-certificate.pem server-certificate.pem <conf-copy-dir>/
2. Create the Secrets¶
# The edited copy of Chrystoki.conf, openssl.cnf and the certificates, from a directory only you can read
kubectl create secret generic luna-client-config \
--from-file=<conf-copy-dir>/Chrystoki.conf \
--from-file=<conf-copy-dir>/openssl.cnf \
--from-file=<conf-copy-dir>/partition-ca-certificate.pem \
--from-file=<conf-copy-dir>/partition-certificate.pem \
--from-file=<conf-copy-dir>/server-certificate.pem
# The Crypto Officer PIN, from a file (not on the command line)
kubectl create secret generic luna-co-pin --from-file=pin=<file-holding-the-pin>
3. Put the library and the plugin on every node¶
With hostPath, every node that can run HelixIAM needs the client's libs/64/libCryptoki2.so and
plugins/libcloud.plugin under /var/lib/luna-client. One way, from the unpacked client directory: a short-lived
DaemonSet that creates the directories, then copy the files into each of its pods and compare their checksums.
kubectl create namespace luna-setup
cat <<'YAML' | kubectl apply -f -
apiVersion: apps/v1
kind: DaemonSet
metadata: {name: luna-client-files, namespace: luna-setup}
spec:
selector: {matchLabels: {app: luna-client-files}}
template:
metadata: {labels: {app: luna-client-files}}
spec:
tolerations: [{operator: Exists}]
containers:
- name: files
image: busybox:1.37.0
command: ["sh", "-c", "mkdir -p /host/libs/64 /host/plugins && sleep 3600"]
volumeMounts: [{name: host, mountPath: /host}]
volumes: [{name: host, hostPath: {path: /var/lib/luna-client, type: DirectoryOrCreate}}]
YAML
kubectl -n luna-setup rollout status ds/luna-client-files
for pod in $(kubectl -n luna-setup get pods -l app=luna-client-files -o name); do
kubectl -n luna-setup cp libs/64/libCryptoki2.so "${pod#pod/}:/host/libs/64/libCryptoki2.so"
kubectl -n luna-setup cp plugins/libcloud.plugin "${pod#pod/}:/host/plugins/libcloud.plugin"
kubectl -n luna-setup exec "${pod#pod/}" -- chmod -R a+rX /host
kubectl -n luna-setup exec "${pod#pod/}" -- sha256sum /host/libs/64/libCryptoki2.so /host/plugins/libcloud.plugin
done
sha256sum libs/64/libCryptoki2.so plugins/libcloud.plugin # must match every pod's output
kubectl delete namespace luna-setup
Repeat this for a node you add later, and after you upgrade the Luna client.
4. Configure the backend in the Helm values¶
config:
extraEnv:
- name: ChrystokiConfigurationPath
value: /opt/luna/conf
custody:
backends:
- id: luna-1
type: pkcs11
library: /opt/luna/libs/64/libCryptoki2.so
tokenLabel: <partition-label>
pinSecret: {name: luna-co-pin, key: pin} # mounted at /var/run/helix/custody/luna-1/pin
connectTimeout: PT30S # see "Settings for a cloud HSM"
opTimeout: PT5S
generateTimeout: PT1M
sessions: 8
networkPolicy:
extraEgressPorts: # keep the ports you already list here
- port: 443
protocol: TCP
extraVolumes:
- name: luna-config
secret: {secretName: luna-client-config, defaultMode: 0440}
- name: luna-libs # the client's libs/ directory on the node
hostPath: {path: /var/lib/luna-client/libs, type: Directory}
- name: luna-plugins # the client's plugins/ directory on the node
hostPath: {path: /var/lib/luna-client/plugins, type: Directory}
- name: luna-lock
emptyDir: {}
extraVolumeMounts:
- {name: luna-config, mountPath: /opt/luna/conf, readOnly: true}
- {name: luna-libs, mountPath: /opt/luna/libs, readOnly: true}
- {name: luna-plugins, mountPath: /opt/luna/plugins, readOnly: true}
- {name: luna-lock, mountPath: /opt/luna/lock}
- With a PersistentVolumeClaim: use one volume
(
persistentVolumeClaim: {claimName: <luna-client-pvc>, readOnly: true}) and mount it twice, withsubPath: libsat/opt/luna/libsandsubPath: pluginsat/opt/luna/plugins. - With a Luna Network HSM: add the port of your appliance to
extraEgressPorts. - More about the chart values: see With the Helm chart.
5. Switch a realm to High assurance¶
In the console, go to Realm keys → Key custody → Change profile. Or use the API:
curl -s -b cookies.txt -X PUT -H "X-XSRF-TOKEN: $CSRF" -H "Content-Type: application/json" \
-d '{"profile":"HIGH","backendId":"luna-1"}' \
"$HELIX_URL/admin/realms/$REALM/key-custody"
The answer is 202, with a list of the planned keys and when each one starts signing.
- What HelixIAM does: it creates the realm's key-encryption key in the partition, then a key per purpose. The new keys are published at once and start signing after the JWKS cache window. The details are in Moving a realm.
- Protected instead of High: use
"profile":"PROTECTED". Only the key-encryption key is then in the partition, and the signing keys sign in the server.
Set up without Kubernetes¶
Use this with Docker Compose, docker run or Podman. The server container needs:
- The unpacked client directory, read-only at
/opt/luna. The DPoD client zip already points every path inChrystoki.confat/opt/luna/..., so with the whole directory mounted there you need not edit it. - A writable lock directory at
/opt/luna/lock, owned by uid 10001: atmpfson top of the read-only mount. ChrystokiConfigurationPath=/opt/luna.- The Crypto Officer PIN as a file, read-only and readable by uid 10001.
- The backend in a YAML file loaded through
SPRING_CONFIG_ADDITIONAL_LOCATION. See Without the chart for how that works.
The client directory holds the service's client credentials (Chrystoki.conf): keep it in a directory only you can
read, as for the PIN.
custody.yaml:
helix:
custody:
backends:
- id: luna-1
type: pkcs11
settings:
library: /opt/luna/libs/64/libCryptoki2.so
tokenLabel: <partition-label>
pinFile: /var/run/helix/custody/luna-1/pin
connectTimeout: PT30S
opTimeout: PT5S
generateTimeout: PT1M
With the quick-start docker-compose.yml from the release, add a docker-compose.override.yml next to it:
services:
server:
environment:
ChrystokiConfigurationPath: /opt/luna
SPRING_CONFIG_ADDITIONAL_LOCATION: file:/etc/helix/custody/custody.yaml
volumes:
- <client-dir>:/opt/luna:ro
- <pin-file>:/var/run/helix/custody/luna-1/pin:ro
- ./custody.yaml:/etc/helix/custody/custody.yaml:ro
tmpfs:
- /tmp
- /opt/luna/lock:uid=10001,mode=0700
Then docker compose up -d, and continue with Switch a realm to High assurance
and Check that it works. The quick-start file is a trial setup (plain HTTP, demo passwords):
for production, run the server behind TLS as described in Install.
Check that it works¶
Sign in as a master-realm administrator on the admin host (see Authenticating to the API), then run these checks:
- Backend health:
GET /admin/key-custody/backendslistsluna-1as healthy, with the algorithms the partition signs. A partition in FIPS mode signs RS256, PS256, ES256 and ES384. At start-up the server log showsPKCS#11 key custody backend 'luna-1' ready. - Realm keys:
GET /admin/realms/$REALM/key-custodyshows the realm's keys with custody onluna-1. - Tokens: a token from the realm verifies against
/realms/$REALM/oauth2/jwks. - Restart: after you restart one pod, the same
kidkeeps signing.
Scripted checks
The chart enables MFA by default, so the bootstrap admin signs in with a second factor. For scripts, set
secrets.bootstrapClientId and use that client's client_credentials token.
From the HSM's side¶
These checks ask the partition itself, not HelixIAM.
The keys are in the partition. In lunacm, run partition contents. Without a login it lists the public keys;
logged in as Crypto Officer (role login -name crypto officer) it also lists the private keys and the
key-encryption key. Each HelixIAM key is labelled helix:<realm>:<PURPOSE>:<uuid>, for example
helix:acme:ACCESS:91603fb1-9410-4c30-884a-14a864b68beb, and a realm in High assurance has about 13 objects.
Each kid belongs to a key in the partition. HelixIAM derives a key's kid from its public key: for EC keys the
RFC 7638 JWK thumbprint, for RSA keys the base64 SHA-256 of the modulus (as a signed big-endian integer). So the
kid can be computed from what the partition holds. This script lists every HelixIAM key in the partition with its
kid. It opens a public session: no login and no PIN. Run it where the Luna client works, with Python and
PyKCS11 installed:
# helix-kids.py: the HelixIAM keys in a Luna partition and the kid HelixIAM publishes for each
import base64, hashlib, json, PyKCS11
from PyKCS11.LowLevel import CKA_EC_POINT
b64u = lambda b: base64.urlsafe_b64encode(b).rstrip(b"=").decode()
lib = PyKCS11.PyKCS11Lib(); lib.load("/opt/luna/libs/64/libCryptoki2.so")
s = lib.openSession(lib.getSlotList(tokenPresent=True)[0])
for o in s.findObjects([(PyKCS11.CKA_CLASS, PyKCS11.CKO_PUBLIC_KEY)]):
label, kt = s.getAttributeValue(o, [PyKCS11.CKA_LABEL, PyKCS11.CKA_KEY_TYPE])
if not str(label).startswith("helix:"):
continue
if kt == PyKCS11.CKK_EC:
pt = bytes(s.getAttributeValue(o, [CKA_EC_POINT])[0])[-64:] # P-256 point: x || y
jwk = json.dumps({"crv": "P-256", "kty": "EC", "x": b64u(pt[:32]), "y": b64u(pt[32:])}, separators=(",", ":"))
kid = b64u(hashlib.sha256(jwk.encode()).digest())
else:
n = bytes(s.getAttributeValue(o, [PyKCS11.CKA_MODULUS])[0]).lstrip(b"\0")
kid = base64.b64encode(hashlib.sha256((b"\0" + n) if n[0] & 0x80 else n).digest()).decode()
print(f"{kid} {label}")
Compare its output with /realms/$REALM/oauth2/jwks and with the kid in a token's header: each kid of the realm
appears with a helix:<realm>:… label. An RSA key is published a second time for PS256, with -ps256 after its
kid. During a rotation the JWKS can also list keys that are being retired.
The token's signature verifies with that public key (see the checks above), and the private key in the partition is not extractable: so the token was signed in the partition.
Thales' record of each signature. A Luna Cloud HSM logs every operation on the partition (Luna client 10.2 or later), so you can show from Thales' side that a token was signed in the HSM, and when:
- Request a token and note the second it was signed: the token's
iatclaim, in UTC. - In the DPoD portal, open Logs, choose the service and a date range that includes that time (UTC), and click Display Log. New entries appear within seconds. Download Log gives the same entries as a file.
- Find the
LUNA_SIGN_SINGLEPARTentry of that second with statusLUNA_RET_OK, and open it with the arrow on its left. Its details show:clientip: the address the HSM saw the request from, which is your cluster's or host's outgoing address;role:CO, the Crypto Officer session HelixIAM logs in with;ouids: the unique ID of the object that signed, the realm's private key.
- To name that key, log in to
lunacmas Crypto Officer and runpartition contents: it lists each object with its label and its object unique ID. Theouidsof the entry is the private key labelledhelix:<realm>:<PURPOSE>:…, the pair of the public key whosekidis in the token's header (see the script above).
Tenant administrators and application owners can read the logs; Thales keeps them for 12 months, and the DPoD Audit Query API exports them. The log also shows HelixIAM's other work on the partition, such as key generation and the key-encryption key's operations. See Thales' Service Audit Logs.
On a Luna Network HSM there is no DPoD portal: the appliance's own audit logging, set up by its Audit role, records the operations. See Thales' documentation for your appliance.
FIPS mode¶
Luna Cloud HSM partitions run in FIPS mode by default. HelixIAM detects this and adapts, so there is nothing to configure. Two things to know:
- No EdDSA. A partition in FIPS mode has no EdDSA, so HelixIAM does not offer it on this backend. Use ES256, RS256
or PS256. A request for EdDSA answers
400and changes nothing. - Mechanism restrictions belong in the partition policy. Luna does not accept per-key mechanism lists in FIPS mode. HelixIAM uses only each key's own mechanisms. To restrict mechanisms on the HSM side, use a Luna partition policy.
Settings for a cloud HSM¶
A cloud HSM is a network round trip away. The default timeouts suit an HSM in the same data centre. For a Luna Cloud HSM, use the values below, as in the example above:
| Setting | Default | For a Luna Cloud HSM | Why |
|---|---|---|---|
connectTimeout |
PT5S |
PT30S |
The first connection to the service can take 10–20 s. |
opTimeout |
PT2S |
PT5S |
The time allowed for one signature, including a network round trip. |
generateTimeout |
the larger of PT30S and opTimeout |
PT1M |
RSA key generation on a cloud HSM can take several seconds. At most PT5M. |
sessions |
8 | your expected concurrent signatures per pod | A pod signs at most this many tokens at once on this backend (1–256). |
Plan capacity:
- Sessions and replicas. Each signature is a network round trip to the HSM. For more tokens per second, raise
sessionsand the number of replicas, within the partition's session limit (sessions× replicas). - Objects. Each realm in High assurance holds about 13 objects in the partition: six key pairs and the
key-encryption key. Each rotation adds new keys until the retention job destroys the retired ones. If the partition
is full, a rotation is refused with
400 backendNoSpaceand the existing keys keep signing. Choose a partition size that fits your realms and rotations. - Load test. Run one against your own partition and network before you go live (see Sizing).
Rotation¶
Rotation works the same way as for every backend (see Day-to-day key work):
- Normal rotation: the new key is published first and starts signing after the cache window.
- Emergency rotation: the new key signs at once, and the old key is disabled in the partition.
# Emergency rotation of the realm's RSA keys (RS256 and PS256); add "algorithm":"ES256" for the EC keys
curl -s -b cookies.txt -X POST -H "X-XSRF-TOKEN: $CSRF" -H "Content-Type: application/json" \
-d '{"emergency": true}' \
"$HELIX_URL/admin/realms/$REALM/keys/rotate"
On a cloud HSM, an RSA rotation takes a few seconds, because the new keys are generated in the partition. After an emergency rotation, purge cached JWKS copies, as described in Emergency rotation and caches.
Retired keys are disabled in the partition, then destroyed by the retention job after custody.destroyAfter (default
P30D). custody.retentionCheckInterval sets how often the job runs (default PT1H).
Restart and shutdown¶
- Restart: the keys stay in the partition and the database keeps their references, so after a restart the same
kidsigns. - Shutdown: the server releases the Luna library and exits within about a second.
- HSM unreachable at start-up: the pod starts with the backend disconnected and connects as soon as the HSM
answers. Until then:
- High-assurance realms answer
503for what they must sign; - Standard realms keep working.
- High-assurance realms answer
See Failure behaviour.
Troubleshooting¶
| Symptom | Cause and fix |
|---|---|
| Backend DOWN with "No HSM token carries the configured label" | The Luna client finds no partition. Check that: ChrystokiConfigurationPath names the directory with Chrystoki.conf; every path in Chrystoki.conf is absolute and matches the mounts; egress on 443 to the DPoD hosts is allowed; tokenLabel is the partition label. |
| "Two HSM tokens carry the configured label" | Two partitions have the same label. Give each its own label. |
| Backend DOWN for the first seconds after start-up | The first connection is slower than connectTimeout. Set connectTimeout: PT30S. |
| "The PIN file of the PKCS#11 backend cannot be read" or "is empty or missing" | The PIN Secret is not mounted, not readable by uid 10001, or empty. |
| "The PKCS#11 library of the backend does not exist" | library does not match where libs/64/libCryptoki2.so is mounted. |
400 backendNoSpace on a rotation or a switch to High assurance |
The partition is full. Free objects (lower custody.destroyAfter, or delete unused objects with lunacm) and retry. Existing keys keep signing. |
Occasional 503 on the token endpoint under load |
Signatures take longer than opTimeout, or there are more concurrent signatures than sessions. Set opTimeout: PT5S and size sessions. |
A request for EdDSA answers 400 |
Expected in FIPS mode. Use ES256. |
| Warning "the token refused CKA_ALLOWED_MECHANISMS" | Expected on Luna in FIPS mode. See FIPS mode. |
Objects labelled helix:<realm>:… that HelixIAM does not list |
Keys left on the partition by interrupted attempts. HelixIAM disables them but does not destroy keys it does not track. Delete them with lunacm, logged in as Crypto Officer. |