safekeys/deployment-packaging [built]
Reproducible, hardened packaging so Safekeys can run on a real host: container images for the control plane and sidecar, a production Compose file, and systemd units that carry the OS isolation the architecture promises. Production refuses every development shortcut — dev-mode OpenBao, a hardcoded root token, an ad-hoc signing seed, and the insecure local keystore.
Status: built
Why this exists
The software MVP works end to end, but "works on the author's laptop" and "safe to run on a VPS" are different claims. Deployment packaging closes the gap without touching the agent-facing protocol: the token and folder formats do not change, only how the authority and the sidecar are built, confined, and started. It is also where the architecture's process-isolation promise stops being prose and becomes enforceable configuration — the sidecar's separate OS user, seccomp-style system-call filtering, and AppArmor confinement land here, not in application code.
The guiding rule is deny-by-default applied to operations: a production unit must be unable to select a development key path even by accident, and a hardening regression must fail a test rather than pass silently.
Design decisions
systemd-single-vm-first [accepted]
Decision: Ship systemd units plus a production Compose file targeting a single hardened VM as the reference deployment; defer Kubernetes manifests.
Rationale: The system map's own footprint is "2–3 small VMs or one small Kubernetes namespace", and the sidecar's trust boundary is the host, which systemd expresses directly. Adding a cluster orchestrator early would multiply configuration surface without adding a security property, and the agent-facing interface is unaffected either way, so Kubernetes can land later behind the same images and units.
Alternatives considered:
- Kubernetes manifests now — rejected: No cluster exists to justify them, and network policies and pod security contexts would duplicate the host-level confinement that is the actual isolation mechanism.
os-isolation-via-systemd [accepted]
Decision: Fold the sidecar's OS isolation into the systemd unit's hardening directives, with an AppArmor profile where the host supports it, rather than deferring it as separate work.
Rationale: The system map already specifies seccomp/AppArmor confinement and a separate user; the unit is exactly where those are expressed and where they can be asserted by a test. Leaving it out would ship a deployment whose stated guarantee the artifact does not enforce.
socket-shared-group [accepted]
Decision: Change the sidecar socket from 0600 to group-access (sidecar user plus a dedicated shared group, group-only mode) so agent processes running as a distinct user can connect.
Rationale: The separate-os-user decision requires agents to be a different user from the sidecar, but a 0600 socket is reachable only by the sidecar's own user — the two are contradictory, and today it works only because development runs everything as one account. A narrow shared group restores the intended least privilege: agents may connect, nothing else local may. This refines the separate-user decision rather than reversing it.
publish-by-digest [accepted]
Decision: Publish CI-built images to a registry and have production pin them by digest.
Rationale: A host that builds from source runs whatever that host compiled that day; a digest pin makes the running artefact identical to the tested one and gives rollback without a rebuild. Local Dockerfiles still build without any registry, so contributors are unaffected.
signing-key-holding-pattern [accepted]
Decision: Deployment provisions the Ed25519 signing seed as a root-owned credential delivered to the control plane only; HSM or secure-element custody remains the Phase 1 target.
Rationale: The key-custody-hsm ADR requires HSM backing from Phase 1 and forbids a bare key file in production as the end state. Hardware is not yet built, so this flow makes the interim explicit, auditable, and never agent-adjacent instead of pretending the problem is solved.
credentials-as-files [accepted]
Decision: Every credential is resolved from a file when a *_FILE variable is set, falling back to the environment only otherwise; the production profile refuses the environment path outright for the signing key and the key-store token.
Rationale: Environment variables are readable from /proc/<pid>/environ, appear in container inspect output, and are inherited by every child process the sidecar spawns for injection. Since the deployment already has a file-based mechanism (systemd LoadCredential, Compose secrets), making files the preferred source costs nothing and removes a class of exposure that would otherwise be inherited by consumer processes. The production profile makes the preference enforceable rather than advisory, so the convention cannot be forgotten on a real host.
How it works
Build the service images (build-images)
Multi-stage Dockerfiles produce minimal, non-root images for the control plane and the sidecar.
- Setup — A builder stage compiles a static, CGO-free Go binary for each service; a runtime stage copies only the binary and CA certificates.
- Setup — Each image declares a fixed non-root UID/GID, a read-only-friendly layout, and no shell or package manager in the runtime layer.
- Validate — The build asserts that no image layer contains a signing key, KEK, API key, or secret.
- Observe — Local images are tagged for Compose; CI publishes them for a real host.
Publish images by digest (publish-images)
CI builds and pushes the images so a host runs exactly what was tested.
- Send — CI builds both images from the committed Dockerfiles.
- Record — Images are pushed to a registry and referenced by immutable digest, never a moving tag.
- Validate — The deploy manifest pins the digest, so a pull cannot silently change the artefact.
- Observe — A previous digest can be re-run for rollback without rebuilding.
Deploy to a single hardened VM (deploy-single-vm)
A reference install on one host — users, directories, secrets, and start order.
- Setup — The install creates a dedicated sidecar OS user distinct from any agent user, plus a shared group whose sole purpose is granting access to the sidecar socket.
- Setup — Secrets (control-plane signing seed, API key, OpenBao token) are placed as root-owned 0600 material and delivered to services as systemd credentials or Compose secrets.
- Setup — systemd units start the key store, then the control plane, then the sidecar, with dependency ordering and restart policy expressed in the units themselves.
- Validate — The units carry the confinement directives and pass the asserted hardening threshold.
- Observe — An agent process running as its own user, in the shared group, resolves a token through the socket; no other local user can connect.
Provision a production key store (provision-prod-keystore)
OpenBao runs as a persistent, sealed-at-rest server — not the in-memory dev server.
- Setup — OpenBao is configured for persistent storage with TLS, and a real init produces sealed unseal shares rather than a fixed root token.
- Setup — The transit engine is enabled and the KEK is created; the KEK never leaves the store.
- Authenticate — The control plane and sidecar receive narrowly scoped tokens limited to the transit operations they need, not the root token.
- Observe — A missing or sealed key store denies resolution rather than falling back to a local KEK.
Provision the token signing key (provision-signing-key)
The Ed25519 signing seed is a root-only credential until HSM custody lands in Phase 1.
- Setup — An operator generates an Ed25519 seed and installs it as a root-owned 0600 credential on the control-plane host, never in a shell profile, image layer, or Compose environment block.
- Setup — The unit loads the seed as a systemd credential or Compose secret and exposes it only to the control-plane process.
- Validate — The sidecar never receives the seed; it holds public keys only.
- Observe — HSM or secure-element custody remains the Phase 1 target; this flow is the explicit, auditable holding pattern, not a replacement for it.
Flow Diagrams
sequenceDiagram
participant User
participant Browser
participant IdP
participant IdP as Identity Provider
Note over Server,Browser: setup — OpenBao is configured for persistent storage with TLS, and a real init produces sealed unseal shares rather than a fixed root token.
Note over Server,Browser: setup — The transit engine is enabled and the KEK is created; the KEK never leaves the store.
Browser->>IdP: OIDC flow — The control plane and sidecar receive narrowly scoped tokens limited to the transit operations they need, not the root token.
Browser-->>User: shows A missing or sealed key store denies resolution rather than falling back to a local KEK.Guarantees
no-dev-credentials-in-prod
Production artifacts must be unable to select a development credential path.
Acceptance criteria:
- [ ] Production uses a persistent OpenBao server, never
server -dev, and never a fixed root token - [ ] The signing seed is delivered from root-owned secret material, not a shell export or the dev key file
- [ ] No production artifact sets SAFEKEYS_ALLOW_INSECURE_KEYSTORE or SAFEKEYS_REVOCATION_OFFLINE
- [ ] The development Compose file is not a supported production artefact
least-privilege-containers
Each image runs with the minimum privilege it needs and nothing more.
Acceptance criteria:
- [ ] Both services run as a fixed non-root UID/GID
- [ ] The runtime image contains no shell, package manager, or build toolchain
- [ ] No image layer contains a signing key, KEK, API key, or plaintext secret
- [ ] Containers drop all Linux capabilities except those a service genuinely requires
- [ ] The sidecar's root filesystem is read-only apart from its socket and folder directories
sidecar-host-isolation
The OS-level confinement the architecture promises is enforced by the unit and asserted by a test.
Acceptance criteria:
- [ ] The sidecar runs as an OS user distinct from any agent user
- [ ] The unit sets NoNewPrivileges, a system-call filter, and the Protect* / Restrict* families
- [ ] The sidecar shares no memory with agent processes (private tmp, no shared dev/shm, IPC removed)
- [ ] An AppArmor profile or SELinux type confines the binary on hosts that support one
- [ ] A hardening regression fails
systemd-analyze securityagainst a pinned exposure threshold
socket-access-model
The socket is reachable by agents running as a distinct user, and by no one else.
Acceptance criteria:
- [ ] The socket is owned by the sidecar user and a dedicated shared group
- [ ] Socket mode grants the group access and denies all others; a world-accessible socket is a failure
- [ ] A process not in the group cannot connect, even as a local user
- [ ] The access model is consistent with the separate-user decision rather than contradicting it
fail-closed-on-boot
A production start that cannot verify authority must not serve.
Acceptance criteria:
- [ ] The sidecar refuses to start when it cannot load public keys or resolve-time policy
- [ ] The sidecar refuses to start when the configured key store is unreachable or sealed
- [ ] Services declare dependencies and restart policy so ordering is enforced, not assumed
- [ ] Deny-by-default policy is retained; production exposes no offline or cached-allow fallback
reproducible-deploy
A host runs exactly the artefact that was tested.
Acceptance criteria:
- [ ] Images are referenced by immutable digest, never by a moving tag such as latest
- [ ] The build is reproducible from the committed Dockerfiles and pinned base images
- [ ] A rollback to a prior digest requires no rebuild
- [ ] The deploy inputs (units, Compose file, config) are version-controlled
Test specifications
images-run-nonroot
Given:
- image: "sidecar-and-control-plane"
When: build-images
Then:
- assertion: each container's process runs as a non-root UID
- assertion: the runtime image contains no shell or package manager
Contracts verified: least-privilege-containers
images-contain-no-secrets
Given:
- scan: "image-layers"
When: build-images
Then:
- assertion: no layer contains a signing seed, KEK, API key, or plaintext secret
Contracts verified: least-privilege-containers, no-dev-credentials-in-prod
prod-refuses-dev-credentials
Given:
- profile: "production"
When: provision-prod-keystore
Then:
- assertion: startup fails when only the insecure local keystore is configured
- assertion: startup fails when a fixed development key store token is supplied
- assertion: no production unit references SAFEKEYS_ALLOW_INSECURE_KEYSTORE
Contracts verified: no-dev-credentials-in-prod
sidecar-hardening-asserted
Given:
- command: "systemd-analyze security safekeys-sidecar"
When: deploy-single-vm
Then:
- assertion: the reported exposure level is at or below the pinned threshold
- assertion: NoNewPrivileges and the system-call filter are active
Contracts verified: sidecar-host-isolation
socket-not-world-accessible
Given:
- agent_user: "safekeys-agent"
- other_user: "someone-else"
When: deploy-single-vm
Then:
- assertion: the agent user in the sidecar group can connect and resolve
- assertion: a user outside the group cannot connect
- assertion: the socket mode denies access to unaffiliated local users
Contracts verified: socket-access-model
boot-fails-closed
Given:
- keystore: "unreachable"
When: deploy-single-vm
Then:
- assertion: the sidecar exits rather than serving a degraded resolution
- assertion: systemd restart policy does not mask the failure from monitoring
Contracts verified: fail-closed-on-boot
deploy-pins-digest
Given:
- manifest: "deploy/compose.prod.yml"
When: publish-images
Then:
- assertion: every image reference is pinned by digest
- assertion: no service resolves a moving tag
Contracts verified: reproducible-deploy
Implementation
- Primary: deploy/
- Test code: scripts/verify-hardening.sh
- Test code status: manual
See Also
- safekeys/sidecar
- safekeys/control-plane
- safekeys/envelope-encryption
- safekeys/hardware-root