Repository navigation
RV-S1: align Terraform, deployer and entrypoint on the prod database (#172) - #211
Closed
amar-python wants to merge 1 commit into
Closed
amar-python wants to merge 1 commit into
amar-python wants to merge 1 commit into
Conversation
…172) Terraform created te_prod for pgadmin; build/deploy_all.sh created te_mgmt_prod for postgres, hardcoded; infra/entrypoint.sh needed an env_prod.sql that a freshly built image does not contain, so a first deploy would stop at "Environment file not found". Canonical (product owner, 9 Nov): database te_prod, owner pgadmin. - build/environments/env_prod.example.sql is the single statement of db_name and db_owner. deploy_all.sh now reads both from the launcher it runs instead of keeping its own copy, which is what drifted. db_owner was declared in every launcher but never used. - deploy_all.sh creates the owner role NOLOGIN when it does not exist (CI, dev servers, the offline install; on Azure it is the server admin), and reports, but does not change, an existing database with another owner. - infra/entrypoint.sh generates env_<env>.sql at run time from the image's .example.sql template and APP_USER_PASSWORD, writes it 0600, and deletes it on exit. The image still holds no launcher with a password (RV-S4, #174). It refuses to run without APP_USER_PASSWORD, and refuses when PGDATABASE is not the launcher's db_name, before changing anything. - infra/terraform-prod: Key Vault secret and job wiring for APP_USER_PASSWORD, mirroring pg_password; comment tying the database to the launcher. - Consumers of the old name follow: CI, evals Tier E, parity and env tests, config examples, provisioning script, offline installer, docs. CI now creates te_prod owned by pgadmin, as Azure has it. - Dockerfile default PGDATABASE was te_dev, a schema name, not a database. tests/test_prod_db_naming.py: static checks that the artefacts agree, and a behavioural run of the real entrypoint from committed files only. DECISIONS/2026-11-09-prod-db-naming.md records the choice. Test and staging have the same Terraform/deployer disagreement and are not changed here. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011T6WqjTEDRRQGLEYPPFVXx
Owner
Author
|
Closing in favour of #213, which implements the same fix (#172) more completely. Nothing here is lost: the branch Why
Independent check of #213 (head Closed by Claude at the owner's request. Generated by Claude Code |
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.
Closes #172.
Decision
Canonical production database:
te_prod, owned bypgadmin(option (a); name chosen by the product owner on 9 Nov). Recorded inDECISIONS/2026-11-09-prod-db-naming.md.What was wrong, and what changed
infra/terraform-prodte_prod, adminpgadminbuild/deploy_all.shte_mgmt_prod,OWNER = postgres, hardcodeddb_nameanddb_ownerfrom the launcher it runsinfra/entrypoint.shenv_prod.sqlnothing in a clean image creates.example.sqltemplateThe root cause of the drift was that the deployer kept its own copy of the name and owner.
db_ownerwas declared in every launcher but never read by anything. The launcher is now the single statement of both, andtests/test_prod_db_naming.pyfails if Terraform, the launcher, the deployer or the entrypoint disagree.Entrypoint (per the issue's "preferred approach"; no populated launcher is ever committed or baked, so #174 is not reintroduced):
env_<env>.sqlfrom the template +APP_USER_PASSWORD, mode0600, deleted on exit;APP_USER_PASSWORD, naming it, rather than creatingte_prod_userwith the template's placeholder password;PGDATABASEis not the launcher'sdb_name, before touching anything. This is the exact Terraform/deployer drift, now caught at run time.Deployer: if the owner role does not exist (CI, dev server, offline install) it creates it
NOLOGIN, so it owns the database and adds no way in. On Azure it is the server admin and already exists. An existing database with a different owner is reported, never altered.Terraform: a Key Vault secret
pg-app-user-passwordand the job'sAPP_USER_PASSWORDenv, mirroring the existingpg_passwordpattern. Without it the first Azure deploy would fail at the entrypoint with the new, clear error.Consumers of the old name updated so nothing breaks: CI (the database-creation step now makes
te_prodowned bypgadmin, as Azure has it), evals Tier E,test_parity,test_env_prod,run_tests.sh, config examples,provision_full_test_env.sh, the offline installer and the docs. I also fixed the Dockerfile's defaultPGDATABASE=te_dev, which is a schema name, not a database; the new guard would otherwise reject every dev run.Verification (the issue's "Done when")
No Docker daemon was available. I emulated the image faithfully instead: the tree comes from
git archiveof the commit (committed files only, so no gitignored launcher orconfig.local.env), laid out asinfra/Dockerfiledoes at/opt/migration, run as the non-rootappuser (uid 1001). Servers are brand-new PostgreSQL 16 clusters withscram-sha-256auth and no role setup.Baseline, unfixed
origin/main(74c248f), Azure-shaped server (only rolepgadmin),te_prodpre-created as Terraform does:Fixed (5c9b930), same server:
The password used was
a'b\c&d/e"f g!, chosen to break naive quoting.te_prodpre-createdpgadminCreating database: te_prod (owner: pgadmin)postgres(nopgadmin)pgadmin(nologin)created, ownerpgadminAPP_USER_PASSWORDERROR: APP_USER_PASSWORD is not set…PGDATABASE=te_mgmt_prodPGDATABASE is 'te_mgmt_prod' but env_prod.sql deploys to 'te_prod'; nothing createdterraform validatepasses oninfra/terraform-prod(Terraform 1.9.8, installed from a checksum-verified download).terraform planwas not run: it needs Azure credentials.CI replica
Run on a live PostgreSQL 16, in CI's order on freshly created databases:
tests/test_prod_db_naming.pyadds 13 tests: 8 static (free-tier job) and 5 that run the real entrypoint (integration job). On unfixed code 10 failed and 3 passed.Not cited here: an earlier local run showed 1 Tier-S failure (
A01 — Row count = 5, got 32). That was my ownte_devdata left by earlier pytest runs; it passes on fresh databases, as above and as in CI.Please read before merging
COPYblock to an explicit list that includesbuild/environments/*.example.sql, which is exactly what runtime generation needs. This branch does not depend on it and edits different Dockerfile lines, but the generation only stays correct after RV-S4: stop the migration image baking local credentials (#174) #204 if that pattern survives.infra/terraform-testand-stagingcreatete_testandte_staging; the deployer buildste_mgmt_testandte_mgmt_staging. Decide those names before One-time cloud setup needed before infra/terraform-test and infra/terraform-staging can be applied #31 resumes. Noted in the decision record.te_prod, notte_mgmt_prod, and leaves a harmlessNOLOGINpgadminrole on the customer's server. I exercised the deployer path it uses, but notinstall.shitself (it needs the offline bundle, apt and systemd). The 2026-11-15: ship air-gapped install procedure or keep interim wording #60 dry run due 15 Nov should be the first real run of this change.docker build/docker run, and a real Azure deploy. Azure may report the owner of the Terraform-created database as something other thanpgadmin; the deployer will then warn and leave it, not fail.Generated by Claude Code