Skip to content

Commit f48c090

Browse files
committed
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.
1 parent e4fa721 commit f48c090

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

ansible/files/postgresql_config/sbpostgres_apparmor

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ profile sbpostgres flags=(attach_disconnected) {
7171
/usr/bin/nix Pix -> pgbackrest_shell,
7272
/usr/bin/sudo Pix -> pgbackrest_shell,
7373

74+
# nix-built postgres popen() may use a nix store sh instead of /bin/sh
75+
/nix/store/*/bin/sh Pix -> postgres_shell,
76+
77+
# SAA called directly from sbpostgres context (e.g. shell Pix fallback)
78+
/opt/supabase-admin-agent/supabase-admin-agent Pix -> postgres_shell,
79+
/opt/supabase-admin-agent/supabase-admin-agent-linux-arm64 Pix -> postgres_shell,
80+
/opt/supabase-admin-agent/supabase-admin-agent-linux-amd64 Pix -> postgres_shell,
81+
7482
profile postgres_shell {
7583
#include <abstractions/base>
7684

@@ -93,6 +101,9 @@ profile sbpostgres flags=(attach_disconnected) {
93101
# backup things
94102
/usr/lib/postgresql/bin/pgsodium_getkey.sh ix,
95103
/usr/bin/admin-mgr ix,
104+
/opt/supabase-admin-agent/supabase-admin-agent ix,
105+
/opt/supabase-admin-agent/supabase-admin-agent-linux-arm64 ix,
106+
/opt/supabase-admin-agent/supabase-admin-agent-linux-amd64 ix,
96107
/nix/store/*/bin/.postgres-wrapped ix,
97108
/nix/store/*/bin/wal-g-2 ix,
98109
/nix/store/*/bin/pgbackrest ix,
@@ -136,8 +147,6 @@ profile sbpostgres flags=(attach_disconnected) {
136147
# tools have network access
137148
network,
138149

139-
# Block everything else
140-
deny /** x,
141150
}
142151

143152
profile pgbackrest_shell {
@@ -196,7 +205,5 @@ profile sbpostgres flags=(attach_disconnected) {
196205
# tools have network access
197206
network,
198207

199-
# Block everything else
200-
deny /** x,
201208
}
202209
}

0 commit comments

Comments
 (0)