Runbook — Turning the vault on for a deployment
The vault is the encrypted storage of the applicant on the government server. Between visits, it keeps a form that is not finished, and later the answers that an approved filing put on record. The vault ships switched off in every country.
This runbook gives the four steps that turn the vault on: make the encryption key, set two environment variables, redeploy, and check one URL. It also gives the message of each crash when you miss a step. The start-up step of the application container writes the database row of the active key version. Nobody inserts that row by hand.
Scope: this enables the vault surface. It does not migrate anything, does not fill any existing form, and does not change what officers can see — the vault is readable by the applicant alone.
Before you start
- The deployment is already onboarded and boots green
(
docs/runbooks/provision-deployment.md). This runbook only flips the vault on. - You can set container environment variables out-of-band (a mounted host env
file or the platform secret store). The encryption key must never go through
the Coolify API — it is a KEK-tier secret, like
OPENGOV_ENCRYPTION_KEY.
1. Mint the encryption key
python scripts/generate_secrets.py <code> # mints + SOPS-encrypts secrets.env
The value to inject is OPENGOV_VAULT_KEK_V1 — a 44-character Fernet key. The
CLI prints it in the KEK-tier list; set it out-of-band, never through Coolify.
Preserve legacy keys until you check their use. Earlier Python versions refused the old generator’s 43-character, unpadded keys. Python 3.15 can build a cipher when such a key still contains all 32 decoded bytes. Do not replace an existing key because of its encoded length alone. Stored values can depend on that key. Follow the key-rotation runbook when replacing a key.
2. Set the environment variables
| Var | Where it goes | Required | Notes |
|---|---|---|---|
OPENGOV_VAULT_KEK_V1 | out-of-band, on the application container and on the worker container | ✅ | from step 1 |
OPENGOV_FEATURE_VAULT | ordinary env | ✅ | true mounts the vault at /api/v1/vault/*; false (the default) 404s every vault path |
OPENGOV_VAULT_RETENTION_POLICY_URL | ordinary env | ✅ in production | the country’s real page saying how long personal data is kept |
OPENGOV_VAULT_ACTIVE_KEK_VERSION | ordinary env, on the application container and on the worker container | ✅ with the vault on | set it to 1. A key change sets a higher number (docs/runbooks/vault-key-rotation.md) |
OPENGOV_VAULT_DRAFT_TTL_DAYS | ordinary env | defaults to 90 — days a half-finished form survives without a save |
Set the key and the version variable on the application container and on the worker container. The worker runs the same key checks at its start as the application. With the vault on, a container that lacks the key or the version variable stops at its start. With the vault off, an absent version variable counts as version 1. A container that names a different version than the active row of the database stops at its start, with the vault on or off.
The retention-policy URL must be a real page. RGPD Art. 13 requires the
applicant to be told how long their data is kept, so a production boot with the
vault on and no URL fails deliberately, and a placeholder such as
https://example.com/privacy is not an acceptable substitute. Dev and test runs
(auth_disabled=true) may leave it unset. The check lives in
src/opengov/main.py.
3. Redeploy
Redeploy the application container first, then the worker container. The start-up step of the application container writes the key-version row at each start. The worker container runs the same step, but it writes no key row. The step is idempotent. It repairs a row at the active version in the wrong state: a retired row still fails the boot check. Find the start-up line in the log of the application container:
boot.migrated: migrated + procrastinate schema + seeded 1 deployment row(s); kek_seeded=True; ...
kek_seeded=False on a later boot is the normal, healthy answer: the row was
already there, in the right state.
The start-up line of the worker always says kek_seeded=False. At its first
start, the worker can wait up to two minutes for the row of the application.
Its log then says kek.wait.
With the vault switched off, the step writes the row when the key of the active
version is present. The registers seal values with that key when the vault is
off. With the vault off and no key, the step writes nothing, and
kek_seeded=False is the expected answer.
4. Check it
curl -s https://smartrules.<wildcard_base>/api/v1/vault/healthz
# Expected: {"status":"vault-mvp-1"} (HTTP 200)
404 means the flag did not reach the container — the vault router is not
mounted. Locally the same check is
curl -s http://localhost:8000/api/v1/vault/healthz.
Then do one real applicant login on the portal and open the vault panel. A 200 from the health probe proves the routes are mounted; only a login proves the encryption key actually decrypts.
A test applicant for the login
Registration in the applicant realm (opengov-applicants) is closed by
default. So the login check needs one test account. Make it on the host, with
the command tool of the login service (kcadm.sh) inside the login container.
- Make the password first, and keep it in your secret store. The realm asks for 12 characters, with one capital letter, one small letter, one digit and one special character.
- Put the password in a file with mode 0600 on the host.
- Run these lines on the host. They need
python3on the host. They read the administrator password from the environment of the login container, so that value never leaves the container.
APP_UUID="<app uuid>" # the compose project of the deployment
EMAIL="<address of the test account>"
PW_FILE=/root/test-applicant-password # mode 0600, from step 2
R=opengov-applicants
KC=$(docker ps -q -f label=com.docker.compose.project=$APP_UUID -f label=com.docker.compose.service=oidc)
kc() { docker exec "$KC" sh -c 'KC_CLI_PASSWORD="$KC_BOOTSTRAP_ADMIN_PASSWORD" exec /opt/keycloak/bin/kcadm.sh "$@" --no-config --server http://localhost:8080 --realm master --user "$KC_BOOTSTRAP_ADMIN_USERNAME"' kcadm "$@"; }
kci() { docker exec -i "$KC" sh -c 'KC_CLI_PASSWORD="$KC_BOOTSTRAP_ADMIN_PASSWORD" exec /opt/keycloak/bin/kcadm.sh "$@" --no-config --server http://localhost:8080 --realm master --user "$KC_BOOTSTRAP_ADMIN_USERNAME"' kcadm "$@"; }
# Python builds the JSON, so a quote, a backslash or a last newline in the file cannot break it.
pw_json() { python3 -c 'import json, sys; print(json.dumps({"type": "password", "temporary": False, "value": open(sys.argv[1]).read().rstrip("\n")}))' "$PW_FILE"; }
set_password() { pw_json | kci update "users/$1/reset-password" -r $R -n -f - && echo "password set"; }
make_applicant() { # Returns at the first fault, and keeps the password file. If only the password step failed, run set_password "$ID".
[ "$(printf '%s\n' "$KC" | grep -c .)" = 1 ] || { echo "STOP: not exactly one login container"; return 1; }
[ -s "$PW_FILE" ] || { echo "STOP: no password in $PW_FILE"; return 1; }
kc create users -r $R -s username="$EMAIL" -s email="$EMAIL" -s enabled=true -s emailVerified=true || return 1
ID=$(kc get users -r $R -q email="$EMAIL" -q exact=true --fields id --format csv --noquotes)
[ -n "$ID" ] || { echo "STOP: the login service did not make the account"; return 1; }
set_password "$ID" && rm -f "$PW_FILE"
}
make_applicant
kcdoes not read stdin, andkcireads a pipe only. In a script thatssh host 'bash -s'reads from stdin, adocker exec -iwith no pipe reads the rest of the script. The script then stops with no error.- The login page asks for the email first, and for the password on a second
screen. A script that types both on one screen puts the password in the
email field. The realm keeps login events for 90 days, and the log of the
login container keeps them too. If that happens, write a new password to
$PW_FILE. Then runset_password "$ID"in the same shell. - To change the password, do not delete the account and make a new one. The vault keys each row to the id of the account, so the rows of the old account lose their owner.
- To delete the account:
kc delete "users/$ID" -r $R.
These commands ran on the sandbox on 2026-10-15, inside the scripts of that switch-on.
When the deployment crash-loops
The vault’s boot checks fail the whole container, not just the vault — the portal and the rules editor go down with it. That is deliberate: writing rows under the wrong key would make them unreadable later. Match the message:
| Message in the log | What is wrong | Fix |
|---|---|---|
No active KEK in platform_kek_versions | the key-version row is missing | redeploy the application container: its start-up step writes the row. If it still fails, read the log of the application container. It stops on a failed migration. |
OPENGOV_VAULT_KEK_V1 is missing or is not a valid Fernet key | the key material is absent or cannot build a cipher | step 1 |
OPENGOV_VAULT_ACTIVE_KEK_VERSION not set; deployment is misprovisioned | the version variable is unset in the container | set it to 1, or switch the vault off |
KEK consistency violation: env says vN, DB says vM | half a key rotation — the two sides disagree | see docs/runbooks/vault-key-rotation.md, section “Messages at the start” |
The active key version of this container is M. The active key version of the database is N. | the same fault with the vault off: the container names a different version than the active row | set OPENGOV_VAULT_ACTIVE_KEK_VERSION to the same version on the application container and on the worker container |
OPENGOV_VAULT_KEK_Vn is missing or is not a valid Fernet key. Stored values still need this old key. Put it back. | the key of a retired version is absent or damaged. Values of that version need it. | set the old key from your secret store. See docs/runbooks/vault-key-rotation.md |
OPENGOV_VAULT_RETENTION_POLICY_URL must be set in production | step 2’s URL is missing | set the country’s real retention page |
Turning it back off
Set OPENGOV_FEATURE_VAULT=false and redeploy. Every vault path returns 404
again; the tables, the rows and the key-version row are left untouched, so
switching it back on later needs no re-seeding.
The start still checks each known key after the vault is off. The application
and the worker build the cipher of each key version that has a row. So keep
each key in place. A missing key stops the two containers, with the vault on or
off. docs/runbooks/vault-key-rotation.md gives the procedure that removes an
old key.
The switch for draft changes
The portal saves an unfinished form (“a draft”) after each pause in the typing. With the switch on, a save sends only the change of the form. The vault applies the change to the stored draft. With the switch off, each save sends the whole draft, as before this release.
Value of OPENGOV_VAULT_DRAFT_CHANGES | What the vault does |
|---|---|
on (the default) | The vault applies each change. |
off | The vault refuses each change with 409 draft_changes_off. Each portal then sends the whole draft until the page loads again. |
To change the state:
- Set
OPENGOV_VAULT_DRAFT_CHANGEStoonoroffin the same place asOPENGOV_FEATURE_VAULT(step 2). - Restart the application container.
- Find the boot line in the log of the application container:
Draft changes are on: a save of a draft can send only its change.(an information line)Draft changes are off: each save of a draft sends the whole draft.(a warning)
Read the boot line after each change. The application ignores a variable with a
wrong name, and the state then stays on. A value other than on or off
stops the start of the application.
The switch does not repair a damaged draft. It leaves each stored draft as it is.
With off, each open tab sends its whole screen at its next save. That whole
save replaces the answers that another tab merged into the draft. Each save did
the same before this release.
The count of draft changes
The application counts each answer to a change in vault_draft_changes_total,
with one label, outcome (for example applied or changes_off). The count
is on the measurements listener inside the application container (port 9100,
when OPENGOV_METRICS_ENABLED=true). Read it with Python, which the image has.
The image has no printenv, so read a setting with Python too.
APP=$(docker ps -q -f label=com.docker.compose.project=$APP_UUID -f label=com.docker.compose.service=opengov)
docker exec "$APP" python3 -c 'import urllib.request; print(urllib.request.urlopen("http://127.0.0.1:9100/metrics").read().decode())' \
| grep '^vault_draft_changes_total'
Each start of the application starts the count at zero, and each deploy
starts the application. So read the count right after the action that you
check. On the sandbox on 2026-10-15, one change with the switch off gave
outcome="changes_off" 1, and changes with the switch on gave
outcome="applied".
Related
docs/runbooks/vault-mvp1-smoke-test.md— walking the vault panel by handdocs/runbooks/provision-deployment.md— the onboarding this runbook followsdocs/runbooks/vault-sub-rebinding.md— when an applicant’s login identity changes