AWS CloudHSM setup
Keep the OSH - CA key in AWS CloudHSM: install the client SDK on the CA machine, create a crypto user and a P-256 key pair, check its fingerprint in OSH - CA, unlock it with the HSM PIN and trust it on your servers.
Before you start
1. Before you start
The CA key is a P-256 key pair inside your CloudHSM cluster and never leaves it. OSH - CA talks to the HSM through its PKCS#11 library, so the same steps work for other PKCS#11 tokens. The CloudHSM client runs on Linux and Windows only (there is no macOS client), and the CA machine must reach the cluster's network: the same VPC, peering, a VPN or Direct Connect. The CloudHSM audit log does not record each signature; OSH - CA keeps its own record of every certificate it signs.

Install the CloudHSM client on the CA machine
2. Install the CloudHSM client on the CA machine
Install CloudHSM CLI and the PKCS#11 library of client SDK 5, then point both at the cluster. You need the IP address of one HSM and the customerCA.crt you used to initialize the cluster. For Ubuntu 22.04:
wget https://s3.amazonaws.com/cloudhsmv2-software/CloudHsmClient/Jammy/cloudhsm-cli_latest_u22.04_amd64.deb https://s3.amazonaws.com/cloudhsmv2-software/CloudHsmClient/Jammy/cloudhsm-pkcs11_latest_u22.04_amd64.deb && sudo apt install ./cloudhsm-cli_latest_u22.04_amd64.deb ./cloudhsm-pkcs11_latest_u22.04_amd64.debOther Linux versions and Windows: take the matching packages from the AWS CloudHSM documentation.
sudo cp customerCA.crt /opt/cloudhsm/etc/ && sudo /opt/cloudhsm/bin/configure-cli -a <HSM IP> && sudo /opt/cloudhsm/bin/configure-pkcs11 -a <HSM IP>The library OSH - CA loads is /opt/cloudhsm/lib/libcloudhsm_pkcs11.so on Linux and C:\Program Files\Amazon\CloudHSM\lib\cloudhsm_pkcs11.dll on Windows.
A cluster with a single HSM refuses to create or use keys until both configure tools run once more with --disable-key-availability-check. Keep that for testing; run two HSMs in production.
Create a crypto user and the key pair
3. Create a crypto user and the key pair
Give the CA its own crypto user (CU), then create a P-256 key pair owned by that user, with the same label on both halves. Start CloudHSM CLI, log in as the admin, create the user, then log in as that user and create the key.
/opt/cloudhsm/bin/cloudhsm-cli interactivelogin --username admin --role adminuser create --username osh_ca --role crypto-userA user name may contain only letters, digits and _ (osh-ca is refused). Choose a strong password: it is half of the PIN OSH - CA asks for.
logoutlogin --username osh_ca --role crypto-userkey generate-asymmetric-pair ec --curve secp256r1 --public-label osh-ca --private-label osh-ca --private-attributes sign=trueKeep the public half: OSH - CA reads the CA public key from it. Keys made this way have no CKA_ID; OSH - CA pairs the two halves by their label.
Work out the fingerprint yourself
4. Work out the fingerprint yourself
Still logged in as the crypto user, export the public key, then let ssh-keygen print its fingerprint. You compare it with the one OSH - CA shows in the next step.
key generate-file --encoding pem --path osh-ca.pem --filter attr.label=osh-ca attr.class=public-keyssh-keygen -i -m PKCS8 -f osh-ca.pem > k.pub && ssh-keygen -lf k.pubRun this in a normal terminal, after quitting CloudHSM CLI. It prints SHA256:<base64>.
Check the key, then use it
5. Check the key, then use it
Open OSH - CA, go to Settings → CA Key and choose PKCS#11 / AWS CloudHSM as Key Source. Enter the PKCS#11 library path, the key label (osh-ca) and the HSM PIN, which for CloudHSM is the crypto user and its password joined by a colon: osh_ca:<password>. Leave the token label empty unless the library shows more than one token. Press Check key: OSH - CA logs in, signs a test digest, checks it against the public half and shows the fingerprint. If it matches the one you worked out, press Use this key and confirm. OSH - CA reads the key again, saves it only if the HSM still answers the fingerprint you confirmed, and restarts with it.
The PIN is used for the check only and is never written to disk.
Check key while this CA is already signing with the HSM is refused with lock the CA first: the HSM login is shared, so the new PIN could not be checked. Press Lock, then check.

Unlock the CA after every start
6. Unlock the CA after every start
OSH - CA starts locked after every start: it connects to the gateway but refuses to sign until someone types the HSM PIN in Settings and presses Unlock, as with a YubiKey. The PIN stays in memory only.
A Linux CA that runs without a screen reads the PIN from the variable CA_PKCS11_PIN in its service environment instead, and starts unlocked.
CloudHSM locks a crypto user out after a few wrong logins. If the HSM refuses the PIN the CA holds, the CA forgets it and goes locked rather than try again.
Trust the CA on your servers
7. Trust the CA on your servers step by step
In OSH - CA press Copy public key line. It copies ecdsa-sha2-nistp256 followed by the key; pass only the key (the long text after the space) to the install script, as described in Trust the CA. The k.pub file from Work out the fingerprint yourself holds the same line. Do this again whenever you change the HSM key.
What to expect when something goes wrong
8. What to expect when something goes wrong
A locked CA, or one whose HSM refuses the request (session lost, user not logged in, key not found), answers that it cannot sign, and the gateway (0.34.0 or later) retries on another CA. Run a second CA (a different CA ID) for failover.
A signature that does not come back within 12 seconds is not retried elsewhere, because the HSM may already have signed. Measured on a real cluster with the network to the HSM cut: the request waited about 16 seconds, the CA turned not ready, and it signed again about 10 seconds after the network came back, without anyone typing the PIN again.
A key label that holds a key other than the one you confirmed switches the CA off until it restarts.
Troubleshooting
9. Troubleshooting
The HSM refused the PIN (CKR_PIN_INCORRECT): check the user name and the password, joined by a colon. Do not retry many times: the crypto user gets locked out.
Key must be available on at least 2 HSMs: the cluster has one HSM. Add a second HSM, or for testing run configure-cli and configure-pkcs11 with --disable-key-availability-check.
The PKCS#11 library reports no token: the CA machine cannot reach the HSM. Check the security groups, the route to the cluster, and that configure-pkcs11 points at a live HSM IP.
Expected one private key labelled osh-ca, found 0 or 2: the label is wrong, or two key pairs share it. Give each key pair its own label.