The encryption key and rotating secrets
By the end you can
- Say what PKI_KEY_ENCRYPTION_KEY protects and what happens if it is lost
- Escrow the key properly and check it with kek-check
- Rotate the key with kek-rotate and clean up afterwards
- Rotate an OTP service token without downtime
One key, many secrets
PKI_KEY_ENCRYPTION_KEY in .env is 64 hexadecimal characters, made by the installer. It encrypts every long-lived secret Authcha holds in the database, with AES-256-GCM, each one tied to its own row so a copied value does not decrypt elsewhere.
| What it protects |
|---|
| Certificate authority private keys (802.1X CA and RadSec CA) |
| The SCEP registration-authority key |
| Identity-provider token-signing keys |
| MDM (Intune, Jamf) client secrets |
| MikroTik gateway REST passwords |
| Enforcement connector secrets (firewall API keys, webhook signing secrets) |
The good news: a database dump or backup alone cannot issue certificates or sign tokens. The bad news is the flip side: it is a single point of loss. If the key is lost, every one of those secrets is unrecoverable, the certificate authorities included, and every certificate you issued would have to be replaced.
Escrow it
Keep at least two copies, offline, in different places: a password-manager vault with restricted access, a sealed envelope in a safe. Keep them separate from the backups. The key is never part of a backup on purpose, because a backup and its key stored together defeat the encryption. Record which backups were made with which key: the small radius-meta-<timestamp>.txt next to each dump holds a short fingerprint of the key it used.
If the key is not set, the console still works, but certificate issuance is unavailable and identity-provider signing keys are stored unencrypted (it warns at every start, and the metric authcha_oidc_plaintext_keys shows it). Set the key and restart: existing keys are encrypted in place.
Check it
sudo authcha kek-checkIt decrypts every sealed item with the key in .env and prints the counts. It changes nothing, and it is part of the restore drill.
Rotate it
Rotate on a schedule you set, when someone who knew the key leaves, and at once if the key, or a host backup together with .env, may have been exposed. Rotation re-encrypts every item under a new key. It does not re-issue certificates or change the certificate authority.
sudo authcha kek-rotate --dry-run # decrypt everything with the current key, verify, change nothing
sudo authcha kek-rotate # do itIn order, the command: does a dry run; takes a fresh backup; writes the new key to a .pending file so it cannot be lost if the host fails; stops the console; re-encrypts every item in one database transaction, checking each against the original before it may commit (any failure rolls everything back and restarts on the old key); replaces the key in .env; starts the console; and runs kek-check. Expect about a minute without the console. RADIUS authentication is not interrupted.
To use a key you made yourself, export it first: sudo NEW_PKI_KEY_ENCRYPTION_KEY=<64 hex> authcha kek-rotate.
After a successful rotation:
- Put the new key into escrow now.
- Backups taken before the rotation need the old key. The command leaves the old
.envatbackups/env-before-kek-rotation-<time>. Move the old key into escrow, labelled with the dates it covers, and delete that file. Keep it as long as you keep those backups. - Run
sudo authcha backup verify.
Rotating the other secrets
For each change to .env or otp.env, recreate the listed services so they read the new value.
| Secret | Procedure | Recreate | Side effects |
|---|---|---|---|
ADMIN_SESSION_SECRET | Replace with a long random value | admin | Everyone is signed out |
PROXY_TRUST_SECRET | openssl rand -hex 32 | admin caddy, together | None |
STATE_HMAC_SECRET | openssl rand -hex 32 | freeradius | Logins waiting at the code prompt must restart |
LOCAL_RADIUS_SECRET | openssl rand -hex 16 | freeradius | None |
| RADIUS shared secrets | Authorization Policies → RADIUS Clients | RADIUS restarts | Devices fail until updated |
| CoA secrets | Change on the device and in Authcha | None | None |
| API tokens | Issue a new one, update automation, revoke the old | None | None |
OTP service token with no downtime
REST_OTP_TOKEN authenticates the RADIUS server and console to the OTP service. The OTP service accepts a list of tokens, so you can rotate in three steps:
cd /opt/authcha
openssl rand -hex 24 # the new token
# 1. otp.env: VALID_API_KEYS=<old>,<new> then recreate otp_service
# 2. .env: REST_OTP_TOKEN=<new> then recreate freeradius admin
# 3. otp.env: VALID_API_KEYS=<new> then recreate otp_serviceLabHands-on
Use a test install for steps 3 to 6.
- Open Settings on the demo as
demo-viewer(passwordAuthcha-View-2026). The demo is public and read-only, so you can see where settings live but not change them. - On your install, read the key's fingerprint from the newest
radius-meta-*.txtin/opt/authcha/backups/. - Run
sudo authcha kek-checkand read the counts. - Run
sudo authcha kek-rotate --dry-run. Nothing changes. - Write down where your two escrow copies would be, and who can reach them.
- Run the real
sudo authcha kek-rotateon the test install. Move the old key to escrow, then runsudo authcha backup verify.
Check yourselfQuiz
Cheat sheetKeep this
PKI_KEY_ENCRYPTION_KEY: 64 hex, AES-256-GCM, protects CA keys, SCEP, IdP signing keys, MDM and connector secrets.- Lost key = lost CAs. Two offline copies, separate from backups.
- Check:
sudo authcha kek-check. Rotate:sudo authcha kek-rotate --dry-run, thensudo authcha kek-rotate(about 1 minute without the console, RADIUS keeps running). - After rotating: new key to escrow, old key kept for old backups, then
sudo authcha backup verify. - Changed
.env? Recreate the service. - Read more: Operations.