Skip to main content

Configure Infisical KMS

This guide explains how to configure Infisical to create its KMS root key in a Securosys HSM.

This tutorial assumes that Infisical already runs, either with Docker Compose or on Kubernetes, and that you have met the prerequisites. See the Infisical documentation for how to install Infisical.

Both deployments configure the same four HSM_* variables and reach the HSM through the same Primus PKCS#11 Provider. They differ only in how the Provider is delivered to the Infisical server: Docker mounts it from the container host, while Kubernetes stages it into a volume.

Step 1: Prepare group membership​

The Infisical image runs as non-root-user (UID 1001, group nodejs). It needs to be added to the primus group to be able to access the Primus PKCS#11 Provider. However, the primus group does not exist inside the container image by name. Therefore, you need to find out its numeric group ID.

On the container host, run the following:

$ getent group primus
primus:x:989:alice,bob

Note down the group ID (here: 989).

Step 2: Set up environment variables​

Add these to the .env file of your Infisical deployment:

LICENSE_KEY=${LICENSE_KEY} # enterprise license key required for HSM encryption

HSM_SLOT=0 # as per slot-id from `ppin -l`
HSM_KEY_LABEL=infisical-kms-root # key label to be created in the HSM
HSM_PIN=secret-pkcs11-pin # the PKCS#11 password for your Partition

PRIMUS_GID=989 # obtained above

Step 3: Docker Compose​

Mount the Primus PKCS#11 Provider and its configuration files into the Infisical container, and point Infisical at the provider. Add the following to the Docker Compose service block:

services:
backend:
container_name: infisical-backend
# other fields omitted
# ...
environment:
HSM_LIB_PATH: /usr/local/primus/lib/libprimusP11.so
SECUROSYS_PKCS11_CONF: /etc/primus/primus.cfg
SECUROSYS_SECRETS_CONF: /etc/primus/.secrets.cfg
volumes:
- /usr/local/primus/lib:/usr/local/primus/lib:ro
- /etc/primus:/etc/primus:ro
group_add:
- "${PRIMUS_GID}"

Restart the container to apply the changes:

docker compose up -d

Step 4: Switch the encryption strategy to HSM​

  1. Sign in as a server administrator and open the Server Console.
  2. Go to Encryption.
  3. Set the strategy to Hardware Security Module (HSM) and save.

Infisical Server Console Encryption set to HSM

Infisical automatically creates infisical-kms-root and infisical-kms-root_HMAC in the Partition and re-encrypts its KMS key under the HSM.

Step 5: Testing​

The root key is used when the instance starts, and the HSM reports key usage once the PKCS#11 session closes. Restart the container to produce both for initial verifications:

docker compose restart infisical-backend
docker compose logs infisical-backend | grep -E 'PKCS#11|HSM:|ROOT Key'
"msg":"PKCS#11 module initialized"
"msg":"HSM: Successfully authenticated"
"msg":"HSM: Terminated session successfully"
"msg":"KMS: Loading ROOT Key into Memory."

Verifying the keys in the Partition​

The HSM records usage against the two keys, when an operation is performed, for example creation of a secret:

Key Name: infisical-kms-root, Encrypt: 1, Decrypt: 1
Key Name: infisical-kms-root_HMAC, Sign: 1, Verify: 1

You can list the keys inside your HSM Partition to verify that Infisical has created them there:

pkcs11-tool --module /usr/local/primus/lib/libprimusP11.so --token-label ${PARTITION_NAME} --login --list-objects --type secrkey
Secret Key Object; AES length 32
label: infisical-kms-root
Usage: encrypt, decrypt
Access: sensitive, always sensitive, never extractable, local
Secret Key Object; Generic secret length 32
label: infisical-kms-root_HMAC
Usage: sign, verify
Access: sensitive, always sensitive, never extractable, local

Creating a secret in a project produces no HSM activity. Each secret is encrypted with a project key that the KMS key protects, and only the KMS key is wrapped by the root key in the HSM.

warning

Once Infisical uses the HSM strategy, the HSM is a hard dependency. If the Partition or its two keys are lost, the data in Infisical cannot be decrypted. Switching back to software encryption also requires access to the HSM. Make sure the Partition is backed up or replicated before storing production secrets.

Get startedwith CloudHSM.
Other questions?Ask Sales.
Feedback
Need help?