Commit 5d39cc3
feat: additional config for pgbackrest (#2099)
* feat: additional config for pgbackrest
- pgdata-signal: add remove-pid action to remove stale postmaster.pid
via the constrained wrapper rather than a broad sudo rm entry,
keeping the sudoers scope limited to this script
* fix: address pgbackrest PR review feedback
- pgdata-chown: simplify case; use group=postgres consistently for both
ownership targets (pgbackrest:postgres and postgres:postgres)
- pgdata-signal: consolidate recovery/standby case into single pattern
- pgdata-signal: deploy at mode 0755 so postgres can execute via sudo -u
- setup-pgbackrest.yml: combine dir creation into single task with dict
loop; conf.d gets 02770 setgid, others get default 0770
- setup-pgbackrest.yml: sort logrotate task keys alphabetically
* fix: add missing pgbackrest sudoers entries and pre-create log files
Three gaps found by cross-referencing SAA commands against Ansible:
1. adminapi.sudoers.conf: add two entries so adminapi can call the
pgbackrest binary via the wrapper.
- NewRunner() path: wrapper calls sudo -u pgbackrest <real binary>,
requires adminapi -> pgbackrest NOPASSWD for the real binary path.
- NewRunnerAs("pgbackrest") path: SAA does sudo -n -u pgbackrest
/usr/bin/pgbackrest, requires adminapi -> pgbackrest NOPASSWD for
the wrapper path.
2. setup-pgbackrest.yml: add pgbackrest -> pgbackrest sudoers entry for
the real binary. When NewRunnerAs runs the wrapper as the pgbackrest
user, the wrapper still calls sudo -u pgbackrest internally; without
this entry that inner sudo fails.
3. setup-pgbackrest.yml: pre-create the three SAA log files
(saa-pgb.log, wal-push.log, wal-fetch.log) as pgbackrest:postgres
0660. SAA opens them with O_APPEND|O_WRONLY (no O_CREATE) — a missing
file causes enable to fail immediately before any pgBackRest work.
modification_time/access_time: preserve means the task is idempotent.
* Update ansible/files/supabase_admin_agent_config/pgdata-signal
Co-authored-by: Tom Ashley <tom.ashley@gmail.com>
* Update ansible/files/supabase_admin_agent_config/pgdata-signal
Co-authored-by: Tom Ashley <tom.ashley@gmail.com>
* Update ansible/tasks/internal/supabase-admin-agent.yml
Co-authored-by: Tom Ashley <tom.ashley@gmail.com>
* fix: use peer auth with saa_map for supabase_admin local connections
Replace trust with peer map=saa_map for the supabase_admin pg_hba rule.
Add saa_map entries in pg_ident.conf mapping adminapi and root OS users
to the supabase_admin PG user, as required by supabase-admin-agent.
* fix: restore pgdata-signal mode to 0755
pgdata-signal is called via sudo as postgres (other user), so it must
be world-executable. 0700 would prevent postgres from running it.
* fix: revert supabase_admin auth to trust, remove saa_map from pg_ident
peer map=saa_map cannot be cleanly implemented in pg_hba.conf.j2 while
the Dockerfiles copy it raw — pg_hba include_if_exists (PG 16+) is
needed to separate Docker from production, and that work is in progress
on a separate branch.
Trust is appropriate for this local Unix-socket-only connection; the
security boundary is OS-level access to the machine. Revisit once the
include directive infrastructure lands.
* docs: add comment to supabase_admin trust rule in pg_hba.conf
* docs: add explanatory comments to pgBackRest Ansible changes
Clarify the intent and rationale behind the less-obvious changes:
- adminapi.sudoers.conf: explain the two pgbackrest sudo chains
(NewRunner vs NewRunnerAs) and the wrapper/real-binary split
- supabase-admin-agent.yml: explain why pgdata-chown is 0700 and
pgdata-signal is 0755
- setup-pgbackrest.yml: explain the pgbackrest self-sudo entry,
why conf.d needs setgid (02770), and why SAA log files must be
pre-created before the agent runs
- pgbackrest.conf: explain expire-auto change and why the [supabase]
stanza was removed (SAA owns it via conf.d to avoid error [031])
* fix: move pgbackrest logrotate config to follow repo convention
- Move from pgbackrest_config/ to logrotate_config/ to match the
existing pattern for all other logrotate configs in the repo
- Deploy via the finalize-ami.yml loop rather than setup-pgbackrest.yml
- Add size 50M cap to prevent logs growing unbounded between daily
rotations during large backup/restore operations
* fix: run pgBackRest directory and log file setup in stage2_nix pass
The directory and log file creation tasks were gated on nixpkg_mode
only, so they were skipped during the stage 2 Nix provision pass
(nixpkg_mode=false, stage2_nix=true). SAA is installed in stage 2 but
had no log directory or pre-created log files to write to, causing
pgbackrest enable to fail immediately.
Extend both conditions to nixpkg_mode or stage2_nix so the paths are
created in whichever pass installs the software.
* fix: set data_directory to canonical path to resolve pgBackRest [058]
pgBackRest stanza-create compares the live cluster's data_directory
against the DataDir stored in pg_control. initdb resolves symlinks
internally so pg_control stores /data/pgdata, but postgresql.conf
explicitly set data_directory to /var/lib/postgresql/data (the symlink),
causing a path mismatch and [058] error on every enable attempt.
Patch data_directory to /data/pgdata immediately after deploying the
postgresql.conf template, scoped to the debpkg_mode/nixpkg_mode block
where the /data volume and symlink are always present. Docker images and
Nix test environments are unaffected as they do not use this Ansible path.
* fix: allow SAA execution from postgres AppArmor confinement
Remove explicit `deny /** x,` from postgres_shell and pgbackrest_shell
sub-profiles — the deny keyword has absolute precedence in AppArmor,
overriding all specific ix allow rules and blocking SAA execution with
exit 126.
Add SAA to the parent sbpostgres profile with Pix -> postgres_shell so
that the archive_command path (shell staying in sbpostgres due to Pix
fallback) can exec SAA and transition it into postgres_shell. Also add
/nix/store/*/bin/sh to the shell transition rules to cover nix-built
postgres popen() behaviour.
* chore: bump postgres release versions for pgbackrest AMI
* fix: align AppArmor profile with salt managed version
Sync sbpostgres_apparmor with the salt repo (PR #526, merged):
- Add WAL dir rwkl entries to parent and both sub-profiles
- Consolidate systemd notify to single /{,var/}run/systemd/notify rule
- Add /usr/bin/kill and signal hup rule to parent
- Add pg_archivecleanup ix to postgres_shell
---------
Co-authored-by: Douglas J Hunley <doug.hunley@gmail.com>
Co-authored-by: Tom Ashley <tom.ashley@gmail.com>1 parent 9313c07 commit 5d39cc3
12 files changed
Lines changed: 211 additions & 28 deletions
File tree
- ansible
- files
- logrotate_config
- pgbackrest_config
- postgresql_config
- supabase_admin_agent_config
- tasks
- internal
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
18 | 33 | | |
19 | 34 | | |
20 | 35 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
8 | 11 | | |
9 | 12 | | |
10 | 13 | | |
11 | 14 | | |
12 | 15 | | |
13 | 16 | | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | | - | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
83 | 86 | | |
84 | 87 | | |
85 | 88 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
27 | 31 | | |
28 | | - | |
29 | 32 | | |
30 | 33 | | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | 34 | | |
36 | 35 | | |
37 | 36 | | |
| |||
50 | 49 | | |
51 | 50 | | |
52 | 51 | | |
| 52 | + | |
| 53 | + | |
53 | 54 | | |
54 | 55 | | |
55 | 56 | | |
| |||
71 | 72 | | |
72 | 73 | | |
73 | 74 | | |
74 | | - | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
75 | 84 | | |
76 | 85 | | |
77 | 86 | | |
| |||
93 | 102 | | |
94 | 103 | | |
95 | 104 | | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
96 | 108 | | |
97 | 109 | | |
98 | 110 | | |
99 | 111 | | |
| 112 | + | |
100 | 113 | | |
101 | 114 | | |
102 | 115 | | |
103 | 116 | | |
104 | 117 | | |
105 | 118 | | |
106 | 119 | | |
| 120 | + | |
| 121 | + | |
107 | 122 | | |
108 | 123 | | |
109 | 124 | | |
| |||
136 | 151 | | |
137 | 152 | | |
138 | 153 | | |
139 | | - | |
140 | | - | |
141 | 154 | | |
142 | 155 | | |
143 | | - | |
| 156 | + | |
144 | 157 | | |
145 | 158 | | |
146 | 159 | | |
| |||
167 | 180 | | |
168 | 181 | | |
169 | 182 | | |
| 183 | + | |
| 184 | + | |
170 | 185 | | |
171 | 186 | | |
172 | 187 | | |
| |||
196 | 211 | | |
197 | 212 | | |
198 | 213 | | |
199 | | - | |
200 | | - | |
201 | 214 | | |
202 | 215 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
| 64 | + | |
64 | 65 | | |
65 | 66 | | |
66 | 67 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
34 | 61 | | |
35 | 62 | | |
36 | 63 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
33 | 38 | | |
34 | 39 | | |
35 | 40 | | |
| |||
43 | 48 | | |
44 | 49 | | |
45 | 50 | | |
46 | | - | |
| 51 | + | |
47 | 52 | | |
48 | | - | |
| 53 | + | |
49 | 54 | | |
50 | 55 | | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
55 | 63 | | |
56 | 64 | | |
57 | 65 | | |
58 | | - | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
59 | 87 | | |
60 | 88 | | |
61 | 89 | | |
| |||
0 commit comments