how-to deployer

Release runbook

Pre-deploy checklist for shipping a new build to a country instance.

Migration round-trip

The full alembic chain (upgrade heads → downgrade base → upgrade heads) is exercised every night by .github/workflows/nightly-migration-roundtrip.yml. That workflow is the primary guard against downgrade() bit-rot in any revision under migrations/versions/.

Before deploying a build that includes a new migration:

  1. Confirm the most recent run of nightly-migration-roundtrip is green (Actions tab → nightly-migration-roundtrip). If a migration has been merged since the last nightly, dispatch the workflow manually:

    gh workflow run nightly-migration-roundtrip.yml
    
  2. As a belt-and-braces check against a real staging database, run the -1 round-trip locally or on the staging host:

    OPENGOV_DATABASE_URL_SYNC=<staging-dsn> alembic downgrade -1
    OPENGOV_DATABASE_URL_SYNC=<staging-dsn> alembic upgrade heads
    

    This catches data-shape problems the empty-DB nightly cannot see (e.g. a NOT NULL column added without a default while staging has live rows).

If either check fails, do not deploy — fix the migration and re-run.

Backup restore and vault erasures

Before you promote a build to the stable channel or deploy it to a country host:

  1. Confirm that the latest run of Nightly restore drill is green. That run tests scripts/restore.sh with the world-model archive, both login realms, and post-backup vault erasures.

  2. Run the vault proof on a host with Docker and the shared test Postgres:

    export OPENGOV_RESTORE_PROOF_DB_PASSWORD='<the password of the test account>'
    .venv/bin/python scripts/restore_vault_proof.py
    

    The last line of a good run is <n> checks, 0 failed, and the exit status is 0.

If either check fails, stop the release and fix the cause first. Read “Proving that a restore repeats the vault erasures” in docs/runbooks/backup-restore.md.

Pre-traffic security configuration

Before serving real applicant traffic on a country instance, set the following environment variables. The backend logs a WARNING at startup for any item left at its dev default (gated on OPENGOV_COUNTRY_CODE != "local", so dev shells stay quiet); production deployments must take the warning seriously — each one corresponds to a real exposure surface.

VariableWhy it mattersGeneration
OPENGOV_COUNTRY_CODEISO3 deployment label on Prometheus metrics; also gates the security warnings below. Boot fails (exit 78) if unset alongside a missing OPENGOV_DEPLOYMENT_CODE (src/opengov/main.py:41-62).Per-country constant, e.g. lso, sen.
OPENGOV_DEPLOYMENT_CODEIdentifier for the row in the deployment registry; backend resolves it at boot via load_current_deployment (src/opengov/platform/deployments/current.py).Per-country constant matching scripts/deployments_seed.yml.
OPENGOV_OIDC_ISSUER + OPENGOV_OIDC_AUDIENCEWithout an audience, any RS256 token from the issuer is accepted. Refused at startup by assert_oidc_settings_consistent (src/opengov/platform/auth.py:56-79).Issuer URL of the country’s Keycloak realm + the resource-server client ID (e.g. opengov-api).
OPENGOV_TRUSTED_PROXIESComma-separated list of reverse-proxy IPs in front of the backend. With this unset, extract_client_ip (src/opengov/platform/network.py:20-48) trusts the rightmost X-Forwarded-For value, which a remote attacker can spoof to evade per-IP rate-limiting on /api/public/v1/procedures/{id}/lookup/{field} and to forge IPs in notification-consent audit rows.List every reverse-proxy hop terminating XFF (LB, ingress, …) as an address or a CIDR range (e.g. 10.0.0.0/8). The shipped stack files set 10.0.0.0/8, the Docker address pool of a Coolify host; write a narrower range when the host uses another pool.
OPENGOV_ANON_HASH_SALTSalts the SHA-256 used to anonymize caller IPs in smartlink_query_log. With the public default (opengov-default-salt), anyone with the source can pre-compute the hash for any IP and deanonymize the audit trail — a GDPR/CNDP exposure.32+ random bytes, e.g. python -c "import secrets; print(secrets.token_hex(32))". Rotate only if you accept that existing rate-limit windows and response-cache entries reset.
OPENGOV_ENCRYPTION_KEYFernet key for SmartLink credential encryption + Phase 2C webhook rotation. Refused at startup if missing in production (src/opengov/smartlink/crypto.py).python -c "from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())". Rotate via the documented rotation procedure, never by replacement.
OPENGOV_CORS_ORIGINSBackend refuses * when auth is enabled (src/opengov/main.py:87-91).Comma-separated list of SPA origins for the country (e.g. https://editor.lso.opengov.example,https://approval.lso…).

After boot, confirm the startup log contains no WARNING lines from opengov.platform or opengov.platform.auth. A clean log is the acceptance signal — the warnings are deliberately loud so a missed configuration cannot ship silently.