Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Installing Iron Vault with Docker Compose

This guide takes a server from nothing to a Ready Iron Vault stack: the service in one container, one isolated network and TLS listener per caller container, and a host unlock so the service comes back Ready after a restart with no one typing a passphrase. It is the server and appliance shape of §17. docker-compose.md says why each choice was made. On a desktop or a shared workstation use protected Linux instead, and to try Iron Vault use development mode.

The protection depends on the host, not only the stack. Whoever controls the Docker daemon can replace Iron Vault, run commands in its container and read its memory after unlock, so the daemon’s administrators are trusted. Do the checks under Before you start first.

Only this shape is supported: rootful Docker on a Linux host with systemd, run by a host administrator, with Iron Vault and its callers in one Compose project. Rootless Docker, userns-remap, Podman and a TPM device passed into the container are not supported.

The host unlock has passed its release check on a machine’s firmware TPM, but the caller isolation check has not run on a real machine yet, so don’t rely on the Compose profile to protect real secrets. Every sudo line here is for you to run; none of it runs by itself.

The reference Compose file, with its two example callers, sets up this layout. Each caller container reaches only its own listener, on a network that has no other member and no way out; only Iron Vault joins the egress network:

+------------------------------------ host ------------------------------------+
|                                                                              |
|  caller-a network (internal)            iron-vault container                 |
|  172.30.1.0/29                          +-----------------------+            |
|  +------------+  TLS, no token          |                       |  egress    |
|  | caller-a   |------------------------>| 172.30.1.2:8443       |  network   |
|  | 172.30.1.3 |                         |                       |------------+--> provider APIs
|  +------------+                         |                       |  (HTTPS)   |
|                                         |                       |            |
|  caller-b network (internal)            |                       |            |
|  172.30.2.0/29                          |                       |            |
|  +------------+  TLS, no token          |                       |            |
|  | caller-b   |------------------------>| 172.30.2.2:8443       |            |
|  | 172.30.2.3 |                         +-----------------------+            |
|  +------------+                                     ^                        |
|                                                     | read-only mount        |
|  TPM --> iron-vault-host-unlock.service --> /run/iron-vault-unlock (ramfs)   |
|                                                                              |
+------------------------------------------------------------------------------+

Before you start

Who may control the Docker daemon

Daemon access is root on the host. No untrusted account may be in the docker group, hold a passwordless sudo docker, or reach the Docker socket some other way, such as a socket ACL or a remote API. Group membership is not the whole test; look at what can actually connect:

getent group docker
ls -l /var/run/docker.sock
sudo -l -U SOMEONE        # for each account that has sudo

Never use a user’s rootless daemon for Iron Vault: that user controls it.

Encrypt swap and hibernation storage

Iron Vault locks its memory, but locked memory does not stop hibernation from writing it to disk (§14). Use full-disk encryption, and check swap and hibernation storage as in the Linux guide’s Encrypt swap and hibernation storage. The host CLI you type passphrases into does not lock its memory either.

Harden sudo

Every admin command runs through sudo on the host, so follow Harden sudo.

What else the host needs

  • systemd with systemd-creds, and a TPM 2.0. The host unlock identity is sealed to the TPM and to the Secure Boot policy (PCR 7), so Secure Boot must be on.
  • Docker Engine with the Compose and buildx plugins, new enough to support the network option com.docker.network.bridge.gateway_mode_ipv4: isolated, and enabled at boot. The service image is built with BuildKit, which the buildx plugin provides. On Ubuntu’s own packages install docker-buildx with docker.io and docker-compose-v2: docker.io only suggests it, and without it the build fails with “the –chmod option requires BuildKit”. Docker’s apt repository calls it docker-buildx-plugin.
  • age-keygen (Debian and Ubuntu package age), openssl and curl.
  • This repository checked out, for the files under packaging/compose/.

Set up

The paths below are the ones the service’s trusted-path checks accept. Run everything from the repository root unless a step says otherwise.

1. Install the host files

Three files make the iron-vault account at the fixed uid and gid 460, create the three runtime directories at each boot, and define the unlock handoff unit:

sudo install -m 0644 packaging/compose/host/sysusers.d/iron-vault.conf /usr/lib/sysusers.d/iron-vault.conf
sudo install -m 0644 packaging/compose/host/tmpfiles.d/iron-vault-compose.conf /usr/lib/tmpfiles.d/iron-vault-compose.conf
sudo install -m 0644 packaging/compose/host/iron-vault-host-unlock.service /etc/systemd/system/iron-vault-host-unlock.service
sudo systemd-sysusers
sudo systemd-tmpfiles --create
sudo systemctl daemon-reload
id iron-vault             # uid=460(iron-vault) gid=460(iron-vault)

If id shows another uid, stop: something else already held 460, and the service refuses to run when the host’s account and the image’s differ. The account has no shell, and nothing on the host may run as it. This stack must not share a host with the Linux package: both use /run/iron-vault and the iron-vault account.

Then make the project directory, root’s alone, and the TLS directory under it:

sudo install -d -m 0700 /etc/iron-vault-host
sudo install -d -m 0755 /etc/iron-vault-host/tls

2. Build or pull the image

Build the container image from this repository. The build refuses anything but the container feature set:

sudo docker build -f packaging/compose/Dockerfile -t iron-vault .

The uid and gid are build arguments, IRON_VAULT_UID and IRON_VAULT_GID, both 460 by default. Change them only together with the host’s sysusers.d file and the Compose file’s user:. To use an image you pulled or were given, skip the build. Each release also publishes this image to ghcr.io/cjs77/iron-vault, tagged with the release version (for example 0.6.0-alpha); final releases also move latest. A digest pin needs a registry digest. An image pulled from ghcr already has one; read it with docker image inspect --format '{{index .RepoDigests 0}}' IMAGE. For a local build, push it to a registry you control first, then read the digest the same way.

Copy the host CLI out of the image. It is the same binary as the service, which is how the two stay in step:

ctr=$(sudo docker create IMAGE)
sudo docker cp "$ctr:/usr/bin/iron-vault" /usr/local/bin/iron-vault
sudo docker rm "$ctr"
sudo chown root:root /usr/local/bin/iron-vault && sudo chmod 0755 /usr/local/bin/iron-vault
iron-vault --version      # lists "container"

3. Write the Compose file

Copy the reference file and edit it:

sudo install -m 0600 packaging/compose/compose.yaml /etc/iron-vault-host/compose.yaml
sudo -e /etc/iron-vault-host/compose.yaml

Replace the image digests (they are placeholders), the two example callers with your own, and the subnets if they clash with the host’s. Pin iron-vault’s image: by digest, so a retagged image cannot change what a later recreation runs. Keep every other line; the hardening checklist says what each one is for. Put no compose.override.yaml and no .env beside it: Compose reads both automatically.

4. Provision the host unlock identity

This generates the host unlock identity and seals it to the TPM, as root. The secret text exists only in a pipe:

sudo packaging/compose/host/provision-host-unlock.sh

It writes /etc/iron-vault-host/host-unlock.cred (root, 0600) and prints one line to the terminal: the identity’s recipient key, age1.... Note it down to compare with what you enrol. The script refuses to run if the credential already exists. --with-key host+tpm2 also ties the seal to the host’s /var/lib/systemd/credential.secret; no other value is accepted.

5. Start the unlock unit

sudo systemctl enable --now iron-vault-host-unlock.service
findmnt /run/iron-vault-unlock        # a ramfs

The unit mounts a ramfs on /run/iron-vault-unlock and installs the identity there for the service account. It runs before Docker at every boot. If it fails, Docker still starts and the service waits Locked.

6. Make the certificates

Each caller’s listener is TLS, and the caller trusts only the CA that issued its certificate. The certificate names Iron Vault’s address on that caller’s network as an IP subject alternative name. One certificate may name every listener’s address, because only Iron Vault holds its key. The addresses below are the reference file’s; use yours.

cd "$(mktemp -d)"
curve="-newkey ec -pkeyopt ec_paramgen_curve:prime256v1 -nodes"
openssl req -x509 $curve -keyout ca.key -out ca.crt -subj /CN=iron-vault-ca -days 365 \
    -addext basicConstraints=critical,CA:TRUE -addext keyUsage=critical,keyCertSign
openssl req -new $curve -keyout server.key -out server.csr -subj /CN=iron-vault
printf 'subjectAltName=IP:172.30.1.2,IP:172.30.2.2\nbasicConstraints=CA:FALSE\nextendedKeyUsage=serverAuth\n' > san.ext
openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -days 365 -extfile san.ext -out server.crt

Install the certificate for each listener, and its key for the service account only:

for name in caller-a caller-b; do
    sudo install -m 0644 server.crt "/etc/iron-vault-host/tls/$name.crt"
    sudo install -m 0600 -o iron-vault -g iron-vault server.key "/etc/iron-vault-host/tls/$name.key"
done

Give each caller container ca.crt as its trust anchor, and nothing else from this directory. Then move ca.key out of reach, to an offline store: it can sign certificates that callers would trust. Delete the directory’s copy of server.key too, once it is installed.

7. Start the stack

sudo docker compose -f /etc/iron-vault-host/compose.yaml up -d
sudo iron-vault ping                  # shows the container profile
sudo iron-vault status                # Locked: there is no vault yet

8. Create the vault and enrol the host unlock identity

sudo iron-vault init --host-unlock

init prompts for the vault and approval passphrases and shows the recovery key once. Store the recovery key offline. --host-unlock makes init read the handoff first, and it refuses to start if the handoff is missing or unsafe. The vault then has three recipients: the operational identity, the recovery key and the host unlock identity. sudo iron-vault recipient list shows them once the service is Ready; the host unlock recipient’s key is the one step 4 printed.

init leaves the service Locked. Restart it, and it opens the vault from the handoff:

sudo docker compose -f /etc/iron-vault-host/compose.yaml restart iron-vault
sudo iron-vault status                # Ready

vault-initialization.md describes init.

9. Add the credentials and approve the config

Add each credential the config names, then write the config and approve it. packaging/compose/config.example.toml is the matching example for the reference Compose file: one TLS listener per caller, each with auth = "isolated-network". The approval must come after the certificates are in place, because the config names them.

cp packaging/compose/config.example.toml config.toml
$EDITOR config.toml        # your callers, listener addresses, routes and credential names
sudo iron-vault add venice_chat --origin api.venice.ai
sudo iron-vault add brave --origin api.search.brave.com
sudo iron-vault config approve config.toml

An isolated-network caller needs no token. It must have its own TLS listener on a dedicated address, as that listener’s only caller; the approval refuses a config that breaks it. The approval cannot see Docker’s networks, so keeping each address on its own network is the Compose file’s job.

10. Send a request

A caller reaches its own listener over TLS, trusting the CA from step 6 and sending no token: the network identifies it. From a caller container that has curl and ca.crt:

curl --cacert /ca.crt -X POST https://172.30.1.2:8443/venice-chat/chat/completions

Use the body your application sends. A request outside the caller’s routes is refused.

Approve with a TPM PIN

This is optional. A signing key that never leaves the host’s TPM can approve your configs, and the changes that need you present, once you type its PIN. It adds an approver and replaces none. Ubuntu 24.04 LTS only, as on a protected install, and it has had no release check on a real machine yet, so don’t rely on it for real secrets.

The container never touches the TPM. The host runs the TPM signing helper from the Linux package, and the service reaches its socket through the read-only mount of /run/iron-vault-tpm. The helper answers only uid 460, the service account, and signs only an approval, a presence proof or a migration proof, never anything else.

What it does not protect. You type the PIN at sudo iron-vault, and it passes through the service to the helper, as the approval passphrase does. The helper checks the form of what it signs, not that you saw it. A compromised service container that captured the PIN could sign an approval for a config you never saw, as it could with the approval passphrase. Showing the summary and taking the PIN on the host was considered and declined: the service already holds the vault and every credential (design).

Install the helper on the host

You need the Linux package (iron-vault_*.deb) of the same release as the image, from the release page or built with scripts/build-deb.sh. Unpack it without installing it, because the package may not share a host with this stack, and install the helper, its two units and its account:

sudo apt install libtss2-esys-3.0.2-0t64 libtss2-tctildr0t64 tpm-udev
dpkg-deb -x iron-vault_*.deb pkg
sudo install -D -m 0755 pkg/usr/libexec/iron-vault/iron-vault-tpm-signer /usr/libexec/iron-vault/iron-vault-tpm-signer
sudo install -m 0644 pkg/usr/lib/systemd/system/iron-vault-tpm-signer.socket \
    pkg/usr/lib/systemd/system/iron-vault-tpm-signer@.service /etc/systemd/system/
sudo install -m 0644 packaging/compose/host/sysusers.d/iron-vault-tpm.conf /usr/lib/sysusers.d/iron-vault-tpm.conf
sudo systemd-sysusers
sudo systemctl daemon-reload
sudo systemctl enable --now iron-vault-tpm-signer.socket
ldd /usr/libexec/iron-vault/iron-vault-tpm-signer | grep 'not found'    # prints nothing
ls -l /run/iron-vault-tpm/signer.sock     # srw------- 1 iron-vault root ...

The units need no change: on this host the iron-vault account is uid 460, the container’s, so the socket’s owner and the helper’s one permitted peer are already the service. tpm-udev gives the tss group /dev/tpmrm0, which the helper’s unit adds for the helper alone. A container whose Compose file mounts /run/iron-vault-tpm sees the socket at once; it needs no restart.

A stack set up from 0.7.0-alpha or earlier has no such mount, and its service answers approver add --kind tpm with exit code 44 however the host is set up. Give it the mount before you enrol:

  1. Install this release’s tmpfiles file, which adds /run/iron-vault-tpm, and create the directory:

    sudo install -m 0644 packaging/compose/host/tmpfiles.d/iron-vault-compose.conf /usr/lib/tmpfiles.d/iron-vault-compose.conf
    sudo systemd-tmpfiles --create
    
  2. Add the read-only bind from the reference packaging/compose/compose.yaml to the iron-vault service’s volumes: in /etc/iron-vault-host/compose.yaml:

          - type: bind
            source: /run/iron-vault-tpm
            target: /run/iron-vault-tpm
            read_only: true
    
  3. Recreate the service. It restarts, and comes back Ready through the unlock handoff:

    sudo docker compose -f /etc/iron-vault-host/compose.yaml up -d
    

Do step 1 first: Docker refuses to start a service whose bind source is missing.

Enrol and use it

sudo iron-vault approver add --kind tpm --label "server TPM"

From here the TPM PIN recipe applies unchanged, from its step 2: the PIN rules, the TPM’s dictionary-attack settings, approving a config with the PIN, and what a wrong PIN costs.

Keep a software approver beside it. The TPM keeps no copy of the PIN. A forgotten PIN, a cleared host TPM or a replaced board leaves the TPM approver unusable, and only another approver gets you out: enrol a new one with it, then approver remove the lost one (recipe). If the lost TPM approver was the only one, only reset remains.

Hardening checklist

Tick each line against your own Compose file and host. The reference file applies every line. The reasons, and the threats each answers, are in the design’s checklist.

The Iron Vault container

  • user: "460:460", the same uid and gid as the image and the host’s iron-vault account.
  • read_only: true.
  • cap_drop: [ALL].
  • security_opt: [no-new-privileges:true].
  • ulimits with memlock: -1 and core: 0. Without an unlimited memlock the service cannot lock memory, and refuses to unlock.
  • None of privileged, pid: host, ipc: host, network_mode: host, devices, or the Docker socket.
  • No seccomp=unconfined or apparmor=unconfined.
  • No environment or env_file holding a secret.
  • command: ["serve", "--log-to-stdout"], and logging with the json-file driver and max-size and max-file. Never journald (log operations).
  • restart: unless-stopped.
  • image: pinned by digest.
  • Networks are egress and each caller’s network, each with a static ipv4_address.
  • No other container uses network_mode: "service:iron-vault" or "container:..." naming it.

Mounts

  • Named volumes config at /etc/iron-vault and state at /var/lib/iron-vault.
  • Host /run/iron-vault at /run/iron-vault, read-write.
  • Host /run/iron-vault-unlock at the same path, read-only, as a directory and not as a file.
  • Host /run/iron-vault-tpm at the same path, read-only, as a directory and not as a file.
  • Host /etc/iron-vault-host/tls at /etc/iron-vault-tls, read-only.
  • Nothing else: no home directory, no Docker socket.

Each caller container

  • cap_drop: [ALL], and never NET_ADMIN or NET_RAW.
  • security_opt: [no-new-privileges:true].
  • On its own caller network only: never egress, never another caller’s.
  • A static ipv4_address of its own on that network.
  • No network_mode of host, or sharing Iron Vault’s.
  • No config or state volume, no /run/iron-vault, /run/iron-vault-unlock, /run/iron-vault-tpm or TLS key mount, and no Docker socket.
  • No privileged, pid: host or ipc: host.
  • Trusts only the CA that issued its listener’s certificate.

The caller networks

  • One network per caller, internal: true, with a small subnet such as a /29, and IPv6 off.
  • com.docker.network.bridge.gateway_mode_ipv4: isolated on each, so the bridge has no host address.
  • egress is not internal, and only Iron Vault joins it.

The host

  • /etc/iron-vault-host is root’s, 0700, and holds the Compose file, with no compose.override.yaml or .env.
  • The image’s build context, and any entrypoint or script mounted into a container, are root’s too.
  • host-unlock.cred is root’s, 0600; the unit and its scripts are root-owned.
  • Only root reaches the Docker socket: no ordinary account in docker, no passwordless sudo docker.
  • The host iron-vault account has no shell, and nothing on the host runs as it.
  • Swap and hibernation storage are encrypted.
  • sudo is hardened as in protected Linux.

Remote administration

Without user-namespace remapping the container shares the host’s uids, so the service sees the host account that opens the admin socket. Root is the only admin principal in this profile; the service account is not one. A plain docker exec runs as the service uid and is refused for that reason, and docker exec -u 0 is root without CAP_DAC_OVERRIDE, so it cannot open the socket.

There are two ways to administer a server from elsewhere. Both are SSH, and neither exposes the admin protocol on a network.

  • Run the command on the server (the default).

    ssh -t admin@server sudo iron-vault status
    

    The command runs through sudo on the server, and what you type goes through the SSH terminal. -t is required for commands that prompt.

  • Forward the admin socket. This needs a key-only root login (PermitRootLogin prohibit-password) on the server.

    ssh -N -L ~/.iv-admin.sock:/run/iron-vault/admin.sock root@server &
    iron-vault --admin-socket ~/.iv-admin.sock status
    

    Close the forward when you are done: any process of your local account can use the socket while it is open, as root on the server.

An ssh -L forward through a non-root login is refused. sshd connects to the socket as the login account, so the kernel refuses the connect() first: the socket is 0600 and owned by the service account, in a 0711 directory, so only root can open it. Even a login that got through would be refused, because the service accepts only uid 0. Use the first form, or log in as root with a key.

Restarts and reboots

  • A restart of the service container, by hand or after a crash (restart: unless-stopped), reads the handoff again, and the service comes back Ready with no one present.
  • A reboot of the host runs the unlock unit before Docker starts, then Docker starts the stack, and the service reads the handoff. Check with sudo iron-vault status once it is up.
  • lock holds until a passphrase sudo iron-vault unlock, across a crash, a restart of the container and a reboot: it leaves an empty file, locked-by-owner, in the state volume, and a service that finds it does not read the handoff. Whoever controls the runtime can still delete that file, so this protects your lock from a crash, not from the runtime’s administrator.
  • If the handoff is missing or refused, the service stays Locked, and sudo iron-vault unlock with the vault passphrase still works. The reason is in the vault.host-unlock record of the audit log. A failed host unlock does not count toward the passphrase attempt limit.

A lost TPM, or a cleared credential

The host unlock identity lives only sealed to this host’s TPM. It is lost with the TPM, the motherboard, a TPM clear, or a change to Secure Boot’s policy (PCR 7). Then the stack starts Locked, and the vault is intact.

A TPM approver on the same TPM is lost with a clear or a new board too, though not with a Secure Boot change. Replace it through your software approver, as Approve with a TPM PIN says.

Open the vault with the vault passphrase, which recipient add needs. Optionally run recovery check to confirm the offline recovery key still opens it; it does not unlock the vault.

sudo iron-vault unlock
sudo iron-vault recovery check

Then replace the host unlock identity:

  1. Move the unusable credential aside, because the script will not overwrite it, and provision a new identity:

    sudo mv /etc/iron-vault-host/host-unlock.cred /etc/iron-vault-host/host-unlock.cred.old
    sudo packaging/compose/host/provision-host-unlock.sh
    sudo systemctl restart iron-vault-host-unlock.service
    

    Note the age1... recipient key it prints.

  2. Enrol it as the host unlock recipient, with the vault passphrase:

    sudo iron-vault recipient add --host-unlock age1... --label "host unlock, new TPM"
    

    recipient list shows the key with the role host-unlock, beside the old one.

  3. Restart the container, and check it reaches Ready with no unlock:

    sudo docker compose -f /etc/iron-vault-host/compose.yaml restart iron-vault
    sudo iron-vault status
    
  4. Remove the old host-unlock entry by its key as recipient list prints it, and delete the old credential:

    sudo iron-vault recipient list
    sudo iron-vault recipient remove age1...
    sudo rm /etc/iron-vault-host/host-unlock.cred.old
    

    Removal needs the approval passphrase, and it protects future copies of identity.age only. recipient remove refuses the entry whose identity the unlock handoff holds, so if it refuses, you named the new key.

Upgrade

Build or pull the new image as in step 2, put its digest in the Compose file’s image:, and recreate the service:

sudo docker compose -f /etc/iron-vault-host/compose.yaml up -d

The service restarts, reads the handoff and comes back Ready. The named volumes keep the vault and the config. Copy the new host CLI out of the image as in step 2, so it matches the service. Without a working handoff, run sudo iron-vault unlock.

If you take a new reference compose.yaml, install the same release’s tmpfiles file and run sudo systemd-tmpfiles --create first (step 1): a bind whose source directory is missing, such as /run/iron-vault-tpm on a host set up from 0.7.0-alpha or earlier, makes Docker refuse to start the service (“bind source path does not exist”). The vault is unharmed; the service stays down until the directory exists.

Read the release’s Breaking changes in the changelog first. If it says the new release cannot open the old vault, as from 0.3.0-alpha to 0.4.0-alpha, the service comes up with reason: recovery needed instead of Ready: follow Recover from an upgrade that cannot open the vault.

Remove

Stop the stack. The volumes, and with them the vault, stay:

sudo docker compose -f /etc/iron-vault-host/compose.yaml down

To retire the host unlock, stop and disable the handoff unit, remove the credential, then remove its recipient with recipient remove while the stack still runs. The service keeps working through the passphrase.

To retire a TPM approver, approver remove it while the stack runs, then remove the helper:

sudo systemctl disable --now iron-vault-tpm-signer.socket
sudo rm /etc/systemd/system/iron-vault-tpm-signer.socket /etc/systemd/system/iron-vault-tpm-signer@.service \
    /usr/libexec/iron-vault/iron-vault-tpm-signer /usr/lib/sysusers.d/iron-vault-tpm.conf
sudo systemctl daemon-reload
sudo userdel iron-vault-tpm

To delete everything, down -v deletes the vault and every stored credential, and nothing recovers them, not even the recovery key.

sudo docker compose -f /etc/iron-vault-host/compose.yaml down -v
sudo systemctl disable --now iron-vault-host-unlock.service
sudo rm -rf /etc/iron-vault-host
sudo rm /etc/systemd/system/iron-vault-host-unlock.service /usr/lib/tmpfiles.d/iron-vault-compose.conf \
    /usr/lib/sysusers.d/iron-vault.conf /usr/local/bin/iron-vault
sudo systemctl daemon-reload
sudo userdel iron-vault

Keep the account if you keep the volumes: a later account at the same uid could otherwise read a kept vault’s files.