Wire cache backends into setup quadlets; fast cache status#16
Merged
Conversation
The secret cache silently broke on hosts using the HSM backend because
only psi-secrets.container got the pcscd socket and
LoadCredentialEncrypted=hsm-pin wiring. The psi-{provider}-setup
containers also need HSM access now that setup eagerly populates the
cache, but the generators did not emit that wiring. Result: setup logs
"Secret cache backend hsm unavailable during setup: No HSM PIN found",
skips cache population, and every lookup still hits the live provider.
unitgen now has helpers that return the Container/Service lines needed
by each cache backend. Both generate_container_serve_quadlet and
generate_container_provider_setup_quadlet consume them. HSM backend
adds the pcscd volume, credentials directory, hsm-pin credential, and
After=pcscd.service ordering. TPM backend adds the psi-cache-key
credential.
psi cache status now defaults to a fast path that reads only config
and the envelope header — no PKCS#11 session, no TPM unseal, no
decrypt. The entry count previously required a full backend open just
to report a number, which took 25+ seconds on HSM. Pass --verify to
get the decrypt-and-count path. psi.cache.read_header parses magic,
version, and backend tag from the first six bytes without touching
the payload.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
psi-{provider}-setup.containergenerators now propagate the same cache-backend wiring that the serve quadlet gets. HSM backend: pcscd volume,CREDENTIALS_DIRECTORY,LoadCredentialEncrypted=hsm-pin,After=pcscd.service. TPM backend:LoadCredentialEncrypted=psi-cache-key.psi cache statusdefaults to a fast path that reads only config and the envelope header — no PKCS#11 session, no TPM unseal.--verifypreserves the old decrypt-and-count behavior.Why
PR #15 shipped the encrypted cache but only wired the serve container for HSM access. On the test server the cache silently skipped population with
"Secret cache backend hsm unavailable during setup: No HSM PIN found"because the setup container could not resolve the PIN. Manually patching the setup quadlet to match the serve container confirmed the fix — setup then populated 490 entries intocache.enc.Separately,
psi cache statuswas opening a full HSM session (PKCS#11 login + pubkey fetch + RSA-OAEP decrypt) just to print an entry count, which took 25+ seconds on Nitrokey HSM. Routine status checks never need that cost. The fast path now reads the first six bytes ofcache.encfor magic, version, and backend tag — no crypto, no provider interaction.What changes
psi/unitgen.py_cache_hsm_container_linesand_cache_tpm_container_linesreturn the[Container]/[Service]lines each backend needs_cache_quadlet_extraspicks the right one based onsettings.cache.backendand also signals whether the caller should addAfter=pcscd.servicegenerate_container_serve_quadletandgenerate_container_provider_setup_quadletboth consume the helperspsi/cache.pyread_header(path)helper: opens the file, reads 6 bytes, validates magic, returns(version, backend_tag). RaisesCacheErroron short files or bad magic. No payload access.psi/cli.pypsi cache statusdefault path: prints config, file size, mtime, and on-disk backend tag without opening any backendpsi cache status --verifypreserves the prior behavior: opens the backend, decrypts, reports entry counttests/test_unitgen.pyTest plan
uv run ruff check psi/ tests/— cleanuv run ruff format --check psi/ tests/— cleanuv run ty check— cleanuv run pytest -q— 288 passed (10 new cache-wiring tests)psi systemd install --mode container --image ghcr.io/quickvm/psi:latest --enable, confirm the regeneratedpsi-infisical-setup.containerhas the HSM wiringpsi cache status(no flag) returns in well under a second inside the serve containerpsi cache status --verifystill decrypts and reports the entry count