Repository navigation
create supabase_admin_monitor role for monitoring services - #2642
TheOtherBrian1 wants to merge 9 commits into
Conversation
|
@copilot resolve the merge conflicts in this pull request |
PostgreSQL Extension Dependency Analysis: PR #2642
SummaryNo extensions had dependencies with MAJOR version updates. Full Analysis ResultsPostgreSQL 15 Extension DependenciesPostgreSQL 17 Extension DependenciesOrioleDB 17 Extension Dependencies |
PostgreSQL Package Dependency Analysis: PR #2642
SummaryNo packages had MAJOR version updates. Full Analysis ResultsPostgreSQL 15 Dependency ChangesExtracting PostgreSQL 15 dependencies...
Runtime Closure Size
Raw Dependency ClosurePostgreSQL 17 Dependency ChangesExtracting PostgreSQL 17 dependencies...
Runtime Closure Size
Raw Dependency Closure |
Package version diffCompares built package versions in legacyPackages between this PR and the tip of the base branch, per system. aarch64-linux: Closure size: 372 -> 372 (2 paths added, 2 paths removed, delta +0, disk usage +3.0KiB).x86_64-linux: Closure size: 370 -> 370 (2 paths added, 2 paths removed, delta +0, disk usage +3.0KiB). |
… test, no connection limit
6623665 to
6703218
Compare
This comment has been minimized.
This comment has been minimized.
tates. Also granted the role the ability to disable pg_stat_statements.track
Is this set anywhere? @TheOtherBrian1 |
| create role supabase_monitor_admin with login bypassrls; | ||
| grant pg_read_all_data, pg_monitor to supabase_monitor_admin; | ||
| alter role supabase_monitor_admin set default_transaction_read_only = on; | ||
| alter role supabase_monitor_admin set transaction_read_only = on; |
There was a problem hiding this comment.
I think this is not needed, only default_transaction_read_only is
| -- The monitor's own queries must not show up in the customer's | ||
| -- pg_stat_statements. Off by default at login, and the role may also pass | ||
| -- `-c pg_stat_statements.track=none` itself (like postgres_exporter does), | ||
| -- which otherwise fails with "permission denied to set parameter" because | ||
| -- the parameter is superuser-only. Same for temp_file_limit, which the | ||
| -- fleet's postgres_exporter passes outside prod; the default is unlimited, | ||
| -- so being able to set it gives the role nothing. Outside the | ||
| -- `if not exists` block so that a role created by an earlier revision of | ||
| -- this migration also gets them. | ||
| alter role supabase_monitor_admin set pg_stat_statements.track = 'none'; | ||
| grant set on parameter pg_stat_statements.track to supabase_monitor_admin; | ||
| grant set on parameter temp_file_limit to supabase_monitor_admin; | ||
|
|
||
| -- The per-role default_transaction_read_only = on above hides the | ||
| -- system-wide value, so `show default_transaction_read_only` cannot tell the | ||
| -- monitor whether the project has been put into read-only mode | ||
| -- (manage_readonly_mode.sh: ALTER SYSTEM SET default_transaction_read_only). | ||
| -- pg_file_settings shows the configuration files' values, including | ||
| -- postgresql.auto.conf. initdb revokes the view and its function from | ||
| -- PUBLIC; the view calls the function as the caller, so both grants are | ||
| -- needed (SELECT also comes with pg_read_all_data, but is granted explicitly | ||
| -- so this does not depend on that membership). Nothing secret: pg_monitor | ||
| -- already reads every live setting. | ||
| -- | ||
| -- Deliberately NOT granted: pg_hba_file_rules() and pg_ident_file_mappings(). | ||
| -- They would show who may connect from where and how; pg_read_all_data | ||
| -- gives SELECT on the views, but without EXECUTE on the functions reading | ||
| -- them still fails with "permission denied". |
There was a problem hiding this comment.
Mind rewording the comments to be more succinct? I find them really hard to parse
There was a problem hiding this comment.
I don't think the "Deliberately NOT granted" part is needed
| grant select on pg_catalog.pg_file_settings to supabase_monitor_admin; | ||
| grant execute on function pg_catalog.pg_show_all_file_settings() to supabase_monitor_admin; |
There was a problem hiding this comment.
Does this mean we need to update postgres_exporter queries to use pg_file_settings/pg_show_all_file_settings? How do we roll that out safely? It seems to me both the introduction of supabase_monitor_admin and the postgres_exporter query changes need to happen atomically
What kind of change does this PR introduce?
Adds a new read-only role called
supabase_admin_monitorWhat is the current behavior?
Some monitor roles are not
read-only.What is the new behavior?
This is supposed to be a new monitoring role for advisors and other tools
Additional context
Our monitoring tools should not use roles with any write priveleges. The new
supabase_admin_monitorhas the following properties:DEFAULT CONFIGS:
Read all attributes and grants: BYPASSRLS, pg_read_all_data, pg_monitor to supabase_monitor_adminRead all configs: "default_transaction_read_only, transaction_read_only" (redundancy safe-guard against postgres granting the role write permissions over its tables)Connection limit: connection limit set to 2. May be worth setting it to 5 to account for future usagetimeout management: "statement_timeout, lock_timeout, idle_in_transaction_session_timeout" (lock mitigation)search_path: removes risks of path hijacking