Skip to content

Keys and HSM

Every private key of LiMDM, where it lives, how to move it into an HSM, and how to rotate each one without enrolling the fleet again.

Inventory

Key Purpose Algorithm Where Backup
Device CA (ca) issues the agents' mTLS client certificates and the certificate of the agent listener; agents pin it ECDSA P-384, certificate 15 years LIMDM_CA_DIR/<name>.crt and <name>.key (0600), or the HSM yes, with the CA directory
Network CA (network-ca) issues EAP-TLS device certificates and signs the network CRL (Network profiles and device certificates) ECDSA P-384, 15 years as above yes
Command key (command) signs commands, library items, catalog apps, managed Flatpak remotes and device user lists; the audit chain key is derived from it Ed25519 LIMDM_CA_DIR/<name>.key (0600), or the HSM yes
Audit chain keys HMAC-SHA256 of the audit log (Audit log) derived with HKDF from the command key derived; earlier segments in LIMDM_CA_DIR/audit-keys (0600) yes, audit-keys and audit-keyed-from
Session key signs console sessions and CSRF tokens, derives the AES-256-GCM keys for sealed values (OIDC client secret, Google service account key, notification channel secrets, LUKS recovery keys, desktop login client secret, webhook signing secret) 32+ random bytes LIMDM_SESSION_KEY in server.env or .env yes, apart from the database
Webhook signing secret (webhook) signs the compliance webhook and global signed webhook channels (X-LiMDM-Signature); each tenant's channel secret is derived from it (Webhook channel payload and signature) HMAC-SHA256, 32 random bytes settings row webhook in the database, sealed with the session key; shown in Settings, Notifications yes, with the database
Log archive key (logs) wraps the per tenant data keys of the log archive (Encryption); independent of the session key Ed25519; the key encryption key is HKDF over its deterministic signature of a fixed label, AES-256-GCM LIMDM_CA_DIR/<name>.key (0600, created at the first start), or the HSM object limdm-<name> yes, with the CA directory: without it archived logs cannot be decrypted
Release key signs SHA256SUMS of agent releases; its public half is compiled into the agent and the server (/install.sh embeds it, LIMDM_RELEASE_PUBLIC_KEY overrides it) Ed25519 CI secret RELEASE_SIGNING_KEY, an offline file, or the HSM (Release key) offline
Console TLS key HTTPS of the console any LIMDM_TLS_KEY or the reverse proxy as usual

The agent listener certificate is issued by the device CA at every start (one year, renewed a month before expiry) and is not stored.

LIMDM_CA_DIR/keys.json names the active key of each kind and, while a rotation runs, the retiring one. Without the file the names are ca, network-ca and command, which are the files every installation before 0.16 has. A key file never goes into the database: whoever can only write to the database can neither issue certificates nor make devices run commands.

With several server instances the CA directory must be the same on all of them (shared volume or copied after every rotation step).

Key provider and HSM

LIMDM_KEY_PROVIDER selects where the private keys of the device CA, the network CA and the command key live:

  • file (default): PEM files in the CA directory, created on first start, mode 0600. The server refuses a key file readable by group or others.
  • pkcs11: a PKCS#11 token (YubiHSM 2, SoftHSM, Nitrokey HSM, Thales Luna, AWS CloudHSM, any module with PKCS#11). The server only asks the token to sign; the keys never leave it. Certificates stay files in the CA directory.
Variable Meaning
LIMDM_KEY_PROVIDER file or pkcs11
LIMDM_PKCS11_MODULE path of the module, for example /usr/lib/softhsm/libsofthsm2.so
LIMDM_PKCS11_TOKEN token label
LIMDM_PKCS11_PIN user PIN (keep server.env root only)

Keys are found by label limdm-<name>: limdm-ca, limdm-network-ca, limdm-command, and after a rotation the names from keys.json. They must exist before the server starts; the server creates the CA certificates itself. The CAs need ECDSA P-256 or P-384, the command key Ed25519 (PKCS#11 3.0 CKM_EDDSA, supported by SoftHSM 2.5+, YubiHSM 2 and most current HSMs). The audit chain key comes from a deterministic Ed25519 signature over a fixed label, since an HSM key has no readable seed; the server checks at start that the token signs deterministically.

Separate build

The release binaries are static (CGO_ENABLED=0) and have no PKCS#11 support; with LIMDM_KEY_PROVIDER=pkcs11 they refuse to start with "needs a server built with -tags pkcs11". PKCS#11 needs cgo (the module is a shared library) and one extra dependency (github.com/miekg/pkcs11):

CGO_ENABLED=1 go build -tags pkcs11 -trimpath -ldflags "-s -w" -o limdm-server ./cmd/limdm-server

The binary links glibc dynamically. For a container, build in golang:1.27 (Debian, with gcc) and run on gcr.io/distroless/base-debian12:nonroot (it has glibc, the static image does not), copy the module of your HSM into the image or mount it, and pin both images by digest like Dockerfile does.

SoftHSM test

Not part of the automated tests. To try the provider:

softhsm2-util --init-token --free --label limdm --so-pin 1234 --pin 5678
M=/usr/lib/softhsm/libsofthsm2.so
pkcs11-tool --module $M --token-label limdm --login --pin 5678 --keypairgen --key-type EC:secp384r1 --label limdm-ca
pkcs11-tool --module $M --token-label limdm --login --pin 5678 --keypairgen --key-type EC:secp384r1 --label limdm-network-ca
pkcs11-tool --module $M --token-label limdm --login --pin 5678 --keypairgen --key-type EC:edwards25519 --label limdm-command
LIMDM_KEY_PROVIDER=pkcs11 LIMDM_PKCS11_MODULE=$M LIMDM_PKCS11_TOKEN=limdm LIMDM_PKCS11_PIN=5678 \
  LIMDM_CA_DIR=/tmp/limdm-ca ./limdm-server serve

Check that ca.crt and network-ca.crt appear, enroll a test device, send it a command and run limdm-server audit verify on an export.

Moving existing keys into an HSM

The provider applies to all keys at once; one installation cannot mix file and HSM keys. Import the current file keys (the names in keys.json, no rotation running) into the token under their labels, for example pkcs11-tool --write-object ca.key --type privkey --label limdm-ca (convert the Ed25519 seed of command.key to PKCS#8 first if the token wants it), check that the public keys match, set LIMDM_KEY_PROVIDER=pkcs11, restart, and delete the key files and their backups. Keys created in the HSM from the start never exist outside it: rotate each kind after the switch to get there.

Vault Transit

Not supported. A Vault Transit provider was left out to keep the dependency and code surface small; Vault users can use Vault's PKCS#11 provider (Vault Enterprise) or an HSM.