OpenBao as a NixOS host service on the thinks (3-node Raft, PKCS#11 auto-unseal) #8
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
lab/machine-configs#8
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Part of lab/machine-configs#7.
Why
Secrets must exist before k3s does (the k3s join token is needed to start k3s), so OpenBao cannot run inside the cluster it bootstraps. It runs as a host service on think-01..03, upgraded by comin, independent of k3s health.
What
services.openbaoon the three thinks, integrated Raft storage ontank(plain ZFS dataset, no DRBD: Raft replicates itself).seal "pkcs11"with one YubiKey 5 per think (PIV slot holding the same imported RSA key; mechanismRSA_PKCS_OAEP;libykcs11.so). OpenBao requires the key to exist on the token before init.retry_joinbetween the thinks; TLS for the API listener and Raft frompki-infra(bootstrap cert at day 0).Done when
Research, 2026-11-06: YubiKey PKCS#11 auto-unseal works with OpenBao. Full report from a research subagent; the first two points I checked myself.
Build support
hsmbuild tag on Linux by default (pkgs/by-name/op/openbao/package.nix:withHsm ? stdenvNoCC.hostPlatform.isLinux,tags = lib.optional withHsm "hsm" ...). The built-inseal "pkcs11"is compiled in. No override.hsmtag. The plugin isopenbao-plugin-kms-pkcs11in openbao/openbao-plugins, latestkms-pkcs11-v0.3.0(2026-11-03). It is not packaged in our pin. Config shape:plugin "kms" "pkcs11" { command = "openbao-plugin-kms-pkcs11" sha256sum = "..." }plusplugin_directory, and theseal "pkcs11"block keeps its name.YubiKey side (from yubico-piv-tool source, not checked by hand)
libykcs11.so(yubico-piv-tool 2.7.3 in nixpkgs) advertisesCKM_RSA_PKCS_OAEPdecrypt for RSA 1024-4096. The card does raw RSA and ykcs11 strips OAEP on the host, sorsa_oaep_hash = "sha256"works.Private key for Key Management, CKA_ID0x03. Token labelYubiKey PIV #<serial>.key_id = "0x03"alone. In ykcs11 it matches cert, private and public objects, and the lookup errors on more than two.Config (per think, serial differs)
BAO_HSM_PINfrom a root-only EnvironmentFile.services.openbao.settingsrenders into the world-readable store.services.pcscd.enable = true; order openbao after pcscd.ykman piv keys import --pin-policy once --touch-policy never 9d seal.pem. PIN policyalwaysor touchalwaysbreaks unattended unseal.Risks
Next
Hardware test on arch-ws: throwaway key into 9d, single-node
bao operator init, restart and confirm auto-unseal, then swap in a second key holding the same import and confirm it unseals the same data.Results, 2026-11-06/07: YubiKey auto-unseal proven on hardware and in a VM test.
Hardware (arch-ws, two new YubiKey 5 Nano, fw 5.8.0)
Throwaway RSA-2048 key imported into PIV 9d (
--pin-policy once --touch-policy never),libykcs11.sofrom yubico-piv-tool 2.7.3.Private key for Key Management/Public key for Key Management, CKA_ID0x03token_labelchangedopenbao-plugin-kms-pkcs110.3.0, Raft storage: init, 3 restartsbuiltin: false,CKM_RSA_PKCS_OAEPSHA-256, auto-unseal every time, KV reads backVM test (machine-configs
feat/openbao-pkcs11, ffc6dc3, local)checks.x86_64-linux.openbao-pkcs11-softhsm, 11/11: PIN only via EnvironmentFile (absent from store config and unit), init, restart auto-unseal, wrong PIN stays sealed with the unit active, token B unseals after token A is deleted.Design facts confirmed
pkgs.openbao2.7.2 builds withouthsm; the plugin is required. nixpkgs-unstable carriesopenbaoPlugins.kms-pkcs11at 0.2.1; we package 0.3.0 (the version tested on hardware).C_Loginon every operation). It lives in/var/lib/openbao-hsm/pkcs11.env, 0400 root, written once by the key ceremony. Never in Nix config: the store and the S3 binary cache are readable.sha1; YubiKeys usesha256.envin apluginstanza replaces the plugin's whole environment and dropsBAO_HSM_PIN. Don't set it.filestorage backend.Before the ceremony
ykman piv resetboth test keys (38686678, 38686829).Decisions, 2026-11-07 (supersede "Raft storage on tank" above).
/var/lib/openbao), not atankdataset. Raft data is a few MB, and OpenBao must come up even whentankfails to import; no ordering onzfs-import-tank.pki-infra), keys already on the thinks in/var/lib/openbao-tls/api.key. Delivered to the unit with systemdLoadCredentialso the dynamic user can read a root-only key.token_label = "YubiKey PIV #<serial>".openbao-plugin-kms-pkcs110.3.0 (branchfeat/openbao-pkcs11, ffc6dc3); PIN file/var/lib/openbao-hsm/pkcs11.envwritten by the owner.Order: ceremony (mc#9) → certs + root into trust stores → host-openbao on the thinks → PIN files →
bao operator initon think-01 → think-02/03retry_join→ import pki-infra → kured roll test.Live, 2026-11-07.
Bring-up
fb22c86on main: OpenBao 2.7.2 +openbao-plugin-kms-pkcs110.3.0 on think-01..03, Raft on the root SSD, API TLS frompki-infra, each think on its own YubiKey (829/965/678).no matching token: nixpkgs-unstable runs pcscd as the unprivilegedpcscduser, and the ccid udev rule only applies to devices plugged in after it exists. Fixed live withudevadm trigger --action=add --subsystem-match=usb --attr-match=idVendor=1050+ pcscd restart; from the next boot the rule applies at coldplug.bao operator init -recovery-shares=3 -recovery-threshold=2. Three voters, think-01 leader, all three unsealed by their own YubiKey at the same committed index.pki-infraimported from the ceremony bundle (two issuers: intermediate with key, root cert only); bundle shredded.kured roll (done-when item 3)
task node:request-reboot HOSTS='think-01 think-02 think-03'(new ine710bdb:/run/reboot-requestis a reboot-marker reason, so the roll goes through marker, DRBD gate, kured fleet lock, boot verify).Probe on arch-ws,
/v1/sys/healthon all three every 5s, 265 samples over 22 min:Done-when status
Key-pull test, 2026-11-07 (done-when item 2).
task node:request-reboot HOSTS=think-03, rebooted 21:36Z with no key:Error configuring seal "pkcs11": no matching token, OpenBao down on think-03. think-02 active and think-01 standby throughout.pcscdgroup at once (udev rule on a live plug), OpenBao unsealed, Raft caught up, standby again.Probe, 103 samples every 5s: 0 with no active node; think-03 unreachable or sealed for 46 samples (~4 min).
Two gaps found and fixed in
62a7734:systemctl reset-failed. NowStartLimitIntervalSec=0,RestartSec=10s: plugging the key back in is the whole fix.reboot-boot-verifypassed with OpenBao sealed, so kured could take a second think and cost quorum. Not a health-check job (that rolls the generation back, a node fault per #6).reboot-markergained generic sentinel gates besidedrbdGate; each think now offers itself to kured only while OpenBao answers unsealed (200/429) on both peers.Done-when status
openbao/openbao-snapshot-agentCronJob on the think cluster via Flux, Kubernetes auth with a snapshot-only policy, S3 bucket on mini's SeaweedFS with a lifecycle rule; restore rehearsed on arch-ws with a seal key)Backups and restore rehearsal, 2026-11-07 (done-when item 4). All four items done.
Backups
flux-clusters
14d568de:ghcr.io/openbao/openbao-snapshot-agent:0.4.5(digest-pinned) CronJob, hourly at :17, namespaceopenbao-snapshot. Logs in atauth/kubernetes-think(roleraft-snapshot, policy: readsys/storage/raft/snapshotandinfra/data/openbao-snapshotonly), reads its S3 credentials from OpenBao (infra/openbao-snapshot), so the cluster holds no S3 secret. Reaches OpenBao through a selectorless Service over the three host IPs, TLS verified against the lab root asopenbao.int.animeteamspeak.moe.openbao-snapshots(reclaim Retain), 30-day lifecycle, identityopenbao-snapshotthat can list and put but not delete.First run 22:10Z: 7 s end to end,
think/bao_2026-11-07-2210.snapshot(48,665 bytes) confirmed on the filer.Restore rehearsal
On arch-ws, throwaway OpenBao 2.7.2 + kms-pkcs11 plugin with think-03's seal key (38686678) moved over (quorum gate held kured meanwhile):
bao operator raft snapshot restore -forcewith the S3 snapshotpki-infra/issuerslists both issuers,infra/openbao-snapshotat version 1,kubernetes-think/presentThrowaway data, PIN file and snapshot copy shredded afterwards.
Done-when
Still open elsewhere: revoke the root token once human auth exists;
auth/kubernetes-think/configgets the new cluster CA after the rebuild (#14).All four done-when items met (see the last four comments). Follow-ups: revoke the root token once human auth exists; kubernetes-think reconfig after the rebuild (#14).