Own migrate objects as audit_core_migrate; pin snapshot-read image
All checks were successful
CI Smoke / host-smoke (push) Successful in 0s
CI Smoke / container-smoke (push) Successful in 1s

SET ROLE during migrate so tables are not owned by a disposable lease.
Current image sha256:aec5575. T02/T03 recorded done after live rotation
and rollout undo. T05 remote run is partial (port-forward dropped).
This commit is contained in:
tegwick 2026-08-13 12:36:25 +02:00
parent c404c910cd
commit 53df641866
4 changed files with 42 additions and 13 deletions

View file

@ -204,6 +204,13 @@ class PostgresAuditBackend:
applied: list[str] = []
try:
with self.pool.connection() as conn:
migrate_role = os.environ.get("AUDIT_CORE_MIGRATE_ROLE", "").strip()
if migrate_role:
if not migrate_role.isidentifier():
raise ValueError(f"unsafe migrate role: {migrate_role!r}")
# Leased login roles must SET ROLE to the group so new
# objects are owned by audit_core_migrate, not the lease.
conn.execute(f'SET ROLE "{migrate_role}"')
conn.execute(f'CREATE SCHEMA IF NOT EXISTS "{self.schema}"')
conn.execute(
f'CREATE TABLE IF NOT EXISTS "{self.schema}".schema_migrations ('