-
-
Notifications
You must be signed in to change notification settings - Fork 235
feat: add apparmor profile #2087
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
staaldraad
wants to merge
6
commits into
develop
Choose a base branch
from
etienne/sec-256
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+225
−4
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a4d570b
feat: add apparmor profile
staaldraad a453045
fix: split commands
staaldraad 12d7d96
Update ansible/tasks/setup-postgres.yml
hunleyd 41d5a42
feat: bump version numbers
staaldraad 0415140
Merge branch 'develop' into etienne/sec-256
staaldraad 962c4e9
fix: correct indent
staaldraad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,204 @@ | ||
| #include <tunables/global> | ||
|
|
||
| # ============================================ | ||
| # POSTGRES PROFILE - With Supabase specific restrictions | ||
| # ============================================ | ||
| profile sbpostgres flags=(attach_disconnected) { | ||
| #include <abstractions/base> | ||
| #include <abstractions/nameservice> | ||
| #include <abstractions/openssl> | ||
|
|
||
| # Parent binary access to self | ||
| /var/lib/postgresql/.nix-profile/bin/postgres mr, | ||
| /nix/store/*/bin/.postgres-wrapped mr, | ||
| /nix/store/*/bin/.postgres-wrapped ix, | ||
|
|
||
| # Wide open permissions for parent - to be tuned | ||
| # some of this is managed via systemd sandboxing already | ||
| /** rw, | ||
| owner /** m, | ||
| / wr, | ||
| /nix/store/** m, | ||
| /etc r, | ||
| /usr/local r, | ||
| # lock permission for pgroonga | ||
| /data/pgdata/pgroonga.log k, | ||
|
|
||
| # Systemd notification socket (for Type=notify services) | ||
| /run/systemd/notify w, | ||
| /{,var/}run/systemd/notify w, | ||
|
|
||
| # Allow disconnected paths (for mount namespaces) | ||
| @{run}/systemd/notify w, | ||
| /run/systemd/notify w, | ||
|
|
||
| # Full network access | ||
| network inet stream, | ||
| network inet6 stream, | ||
| network unix stream, | ||
|
|
||
| # All capabilities | ||
| capability, | ||
|
|
||
| # Libraries | ||
| /lib/aarch64-linux-gnu/*.so* mr, | ||
| /usr/lib/aarch64-linux-gnu/*.so* mr, | ||
| /nix/store/*/lib/*.so* mr, | ||
|
|
||
| # safe commands | ||
| /usr/bin/true ix, | ||
| /usr/bin/false ix, | ||
| # kill needed for postgresql to reload itself | ||
| /bin/kill ix, | ||
|
|
||
| # When parent executes shell, transition to restricted profile | ||
| # This accounts for popen, which postgres uses for any child process | ||
| # Px = discrete profile transition (child gets different profile) | ||
| /bin/sh Pix -> postgres_shell, | ||
| /bin/bash Pix -> postgres_shell, | ||
| /bin/dash Pix -> postgres_shell, | ||
| /usr/bin/sh Pix -> postgres_shell, | ||
| /usr/bin/dash Pix -> postgres_shell, | ||
| /nix/store/*/bin/bash Pix -> postgres_shell, | ||
| /usr/lib/postgresql/bin/pgsodium_getkey.sh Pix -> postgres_shell, | ||
| /usr/bin/cat Pix -> postgres_shell, | ||
| /bin/cat Pix -> postgres_shell, | ||
| /usr/bin/admin-mgr Pix -> postgres_shell, | ||
| /nix/store/*/bin/wal-g-2 Pix -> postgres_shell, | ||
| /nix/store/*/bin/pgbackrest Pix -> postgres_shell, | ||
| /usr/bin/pgbackrest Pix -> pgbackrest_shell, | ||
| /usr/bin/nix Pix -> pgbackrest_shell, | ||
| /usr/bin/sudo Pix -> pgbackrest_shell, | ||
|
|
||
| profile postgres_shell { | ||
| #include <abstractions/base> | ||
|
|
||
| /usr/bin/* m, | ||
| /bin/* m, | ||
|
|
||
| # Shell binary | ||
| /usr/bin/sh mr, | ||
| /usr/bin/bash mr, | ||
| /usr/bin/dash mr, | ||
| /nix/store/*/bin/bash mr, | ||
|
|
||
| # Only allow specific commands to be executed from shell | ||
| /usr/bin/gzip ix, | ||
| /usr/bin/cat ix, | ||
| /usr/bin/pg_dump ix, | ||
| /bin/echo ix, | ||
| /bin/bash ix, | ||
| /bin/cat ix, | ||
| # pgbackrest needs nix and sudo | ||
| /usr/bin/nix ix, | ||
| /usr/bin/sudo ix, | ||
|
|
||
| # backup things | ||
| /usr/lib/postgresql/bin/pgsodium_getkey.sh ix, | ||
| /usr/bin/admin-mgr ix, | ||
| /nix/store/*/bin/.postgres-wrapped ix, | ||
| /nix/store/*/bin/wal-g-2 ix, | ||
| /nix/store/*/bin/pgbackrest ix, | ||
|
|
||
| # file path permissions | ||
| /** r, | ||
| /data/wal_fetch_dir/ rw, | ||
| /tmp/wal_fetch_dir/ rw, | ||
| /var/lib/postgresql/data rw, | ||
| /data/pgdata rw, | ||
| /data/latest-lsn-checkpoint-v2 rw, | ||
| /data/previous-lsn-checkpoint-v2 rw, | ||
| /var/lib/postgresql/data/recovery.signal rw, | ||
| /var/lib/postgresql/data/standby.signal rw, | ||
| /var/lib/pgbackrest rw, | ||
| /etc/pgbackrest/conf.d/** rw, | ||
| /var/spool/pgbackrest/** rw, | ||
| /var/log/pgbackrest/** rw, | ||
| /etc/** r, | ||
| /usr/local/** r, | ||
|
|
||
|
|
||
| deny /var/lib/supabase/** rwx, | ||
| deny /var/lib/supabase-admin-agent/** rwx, | ||
| deny /var/cache/supabase-admin-agent/** rwx, | ||
| deny /opt/saltstack/** rwx, | ||
| deny /etc/salt/** rwx, | ||
| deny /root wr, | ||
| deny /home/** wr, | ||
| # wal-g needs access to its own home directory | ||
| /home/wal-g/* wr, | ||
|
|
||
| # Libraries | ||
| /lib/aarch64-linux-gnu/*.so* mr, | ||
| /usr/lib/aarch64-linux-gnu/*.so* mr, | ||
| /nix/store/*/lib/*.so* mr, | ||
|
|
||
| # full network access | ||
| # could further break this up so that only backup | ||
| # tools have network access | ||
| network, | ||
|
|
||
| # Block everything else | ||
| deny /** x, | ||
| } | ||
|
|
||
| profile pgbackrest_shell { | ||
| #include <abstractions/base> | ||
|
|
||
| /usr/bin/* m, | ||
| /bin/* m, | ||
|
|
||
| # Shell binary | ||
| /usr/bin/sh mr, | ||
| /usr/bin/bash mr, | ||
| /usr/bin/dash mr, | ||
| /nix/store/*/bin/bash mr, | ||
|
|
||
| # pgbackrest needs nix and sudo | ||
| /usr/bin/nix ix, | ||
| /usr/bin/sudo ix, | ||
| /bin/bash ix, | ||
|
|
||
| /usr/bin/admin-mgr ix, | ||
| /nix/store/*/bin/.postgres-wrapped ix, | ||
| /nix/store/*/bin/pgbackrest ix, | ||
|
|
||
| # file path permissions | ||
| /** r, | ||
| /data/wal_fetch_dir/ rw, | ||
| /tmp/wal_fetch_dir/ rw, | ||
| /var/lib/postgresql/data rw, | ||
| /data/pgdata rw, | ||
| /data/latest-lsn-checkpoint-v2 rw, | ||
| /data/previous-lsn-checkpoint-v2 rw, | ||
| /var/lib/postgresql/data/recovery.signal rw, | ||
| /var/lib/postgresql/data/standby.signal rw, | ||
| /var/lib/pgbackrest rw, | ||
| /etc/pgbackrest/conf.d/** rw, | ||
| /var/spool/pgbackrest/** rw, | ||
| /var/log/pgbackrest/** rw, | ||
| /etc/** r, | ||
| /usr/local/** r, | ||
|
|
||
| deny /var/lib/supabase/** rwx, | ||
| deny /var/lib/supabase-admin-agent/** rwx, | ||
| deny /var/cache/supabase-admin-agent/** rwx, | ||
| deny /opt/saltstack/** rwx, | ||
| deny /etc/salt/** rwx, | ||
| deny /root wr, | ||
| deny /home/** wr, | ||
|
|
||
| # Libraries | ||
| /lib/aarch64-linux-gnu/*.so* mr, | ||
| /usr/lib/aarch64-linux-gnu/*.so* mr, | ||
| /nix/store/*/lib/*.so* mr, | ||
|
|
||
| # full network access | ||
| # could further break this up so that only backup | ||
| # tools have network access | ||
| network, | ||
|
|
||
| # Block everything else | ||
| deny /** x, | ||
| } | ||
| } |
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.