fix(infra): grant audit roles to current_user, not hardcoded portal #60

Merged
julien merged 1 commits from fix/infra/init-sql-current-user into main 2026-05-08 21:44:06 +02:00
Owner

Summary

The bootstrap SQL ended with:

GRANT audit_owner, audit_writer, audit_reader, audit_archiver TO portal;

— hard-coded portal. The compose file and .env.example both document POSTGRES_USER as overridable; any contributor who changed it hit:

ERROR: role "portal" does not exist
psql: /docker-entrypoint-initdb.d/01-init.sql:48: ERROR: role "portal" does not exist

Replace with current_user, which resolves at execution time to whoever is running the init SQL — i.e. the superuser Postgres just created from POSTGRES_USER, whatever its name.

Recovery for anyone hit by the bug

The half-failed init left the postgres-data volume in a partially-initialised state. To reset:

cd infra/local
docker compose -f dev.compose.yml down -v   # wipes the volume
docker compose -f dev.compose.yml up -d     # bootstrap re-runs cleanly

Test plan

  • After merge + recovery: docker compose ps shows postgres healthy.
  • psql postgres://<user>:<pwd>@localhost:5432/portal_dev -c "\du" lists the four audit_* roles, and your superuser is "Member of: {audit_owner, audit_writer, audit_reader, audit_archiver}".
  • psql ... -c "\dn" shows the audit schema.
  • Test with a non-default POSTGRES_USER value (set POSTGRES_USER=apf_portal in .env, wipe volume, re-up) — init still succeeds.
## Summary The bootstrap SQL ended with: ```sql GRANT audit_owner, audit_writer, audit_reader, audit_archiver TO portal; ``` — hard-coded `portal`. The compose file and `.env.example` both document `POSTGRES_USER` as overridable; any contributor who changed it hit: ``` ERROR: role "portal" does not exist psql: /docker-entrypoint-initdb.d/01-init.sql:48: ERROR: role "portal" does not exist ``` Replace with `current_user`, which resolves at execution time to whoever is running the init SQL — i.e. the superuser Postgres just created from `POSTGRES_USER`, whatever its name. ## Recovery for anyone hit by the bug The half-failed init left the postgres-data volume in a partially-initialised state. To reset: ```bash cd infra/local docker compose -f dev.compose.yml down -v # wipes the volume docker compose -f dev.compose.yml up -d # bootstrap re-runs cleanly ``` ## Test plan - [x] After merge + recovery: `docker compose ps` shows postgres healthy. - [ ] `psql postgres://<user>:<pwd>@localhost:5432/portal_dev -c "\du"` lists the four `audit_*` roles, and your superuser is "Member of: {audit_owner, audit_writer, audit_reader, audit_archiver}". - [ ] `psql ... -c "\dn"` shows the `audit` schema. - [ ] Test with a non-default `POSTGRES_USER` value (set `POSTGRES_USER=apf_portal` in `.env`, wipe volume, re-up) — init still succeeds.
julien added 1 commit 2026-05-08 21:43:53 +02:00
fix(infra): grant audit roles to current_user, not hardcoded portal
CI / commits (pull_request) Successful in 1m10s
CI / check (pull_request) Successful in 1m15s
CI / scan (pull_request) Successful in 1m20s
CI / a11y (pull_request) Successful in 1m22s
CI / perf (pull_request) Successful in 2m59s
44deeab35d
The bootstrap SQL ended with:

    GRANT audit_owner, audit_writer, audit_reader, audit_archiver TO portal;

which assumed POSTGRES_USER is `portal`. The compose file (and the
.env.example) document POSTGRES_USER as overridable — anyone who
changed it to something else (e.g. `apf_portal`) hit:

    ERROR: role "portal" does not exist
    psql: .../01-init.sql:48: ERROR: role "portal" does not exist

`current_user` resolves at script execution to whoever is running
the init SQL — that is, the superuser Postgres just created from
POSTGRES_USER, regardless of its name. Use it instead of hard-coding
`portal`.

Recovery for anyone hit by the original bug:

    cd infra/local
    docker compose -f dev.compose.yml down -v   # wipes the
                                                # half-initialised
                                                # postgres-data volume
    docker compose -f dev.compose.yml up -d     # bootstrap re-runs
                                                # cleanly
julien merged commit 6137486d64 into main 2026-05-08 21:44:06 +02:00
julien deleted branch fix/infra/init-sql-current-user 2026-05-08 21:44:09 +02:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: julien/apf_portal#60