-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
408 additions
and
16 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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,205 @@ | ||
-- non-superuser privileged role | ||
set role privileged_role; | ||
\echo | ||
|
||
-- can set privileged_role_allowed_configs | ||
set session_replication_role to 'replica'; | ||
begin; | ||
set local session_replication_role to 'origin'; | ||
commit; | ||
reset session_replication_role; | ||
\echo | ||
|
||
-- non-superuser non-privileged role cannot set privileged_role_allowed_configs | ||
set role rolecreator; | ||
set session_replication_role to 'replica'; | ||
ERROR: permission denied to set parameter "session_replication_role" | ||
begin; | ||
set local session_replication_role to 'origin'; | ||
ERROR: permission denied to set parameter "session_replication_role" | ||
commit; | ||
reset session_replication_role; | ||
ERROR: permission denied to set parameter "session_replication_role" | ||
set role privileged_role; | ||
\echo | ||
|
||
-- superuser can set privileged_role_allowed_configs | ||
set role postgres; | ||
set session_replication_role to 'replica'; | ||
begin; | ||
set local session_replication_role to 'origin'; | ||
commit; | ||
reset session_replication_role; | ||
set role privileged_role; | ||
\echo | ||
|
||
-- can set privileged_role_allowed_configs for a role | ||
create role r; | ||
alter role r set session_replication_role to 'replica'; | ||
drop role r; | ||
\echo | ||
|
||
-- can manage bypassrls role attribute | ||
create role r bypassrls; | ||
select rolbypassrls from pg_roles where rolname = 'r'; | ||
rolbypassrls | ||
-------------- | ||
t | ||
(1 row) | ||
|
||
alter role r nobypassrls; | ||
select rolbypassrls from pg_roles where rolname = 'r'; | ||
rolbypassrls | ||
-------------- | ||
f | ||
(1 row) | ||
|
||
alter role r bypassrls; | ||
select rolbypassrls from pg_roles where rolname = 'r'; | ||
rolbypassrls | ||
-------------- | ||
t | ||
(1 row) | ||
|
||
drop role r; | ||
\echo | ||
|
||
-- can manage replication role attribute | ||
create role r replication; | ||
select rolreplication from pg_roles where rolname = 'r'; | ||
rolreplication | ||
---------------- | ||
t | ||
(1 row) | ||
|
||
alter role r noreplication; | ||
select rolreplication from pg_roles where rolname = 'r'; | ||
rolreplication | ||
---------------- | ||
f | ||
(1 row) | ||
|
||
alter role r replication; | ||
select rolreplication from pg_roles where rolname = 'r'; | ||
rolreplication | ||
---------------- | ||
t | ||
(1 row) | ||
|
||
drop role r; | ||
\echo | ||
|
||
-- can manage foreign data wrappers | ||
create extension postgres_fdw; | ||
create foreign data wrapper new_fdw | ||
handler postgres_fdw_handler | ||
validator postgres_fdw_validator; | ||
drop extension postgres_fdw cascade; | ||
NOTICE: drop cascades to foreign-data wrapper new_fdw | ||
\echo | ||
|
||
-- non-superuser non-privileged role cannot manage bypassrls role attribute | ||
set role rolecreator; | ||
\echo | ||
|
||
-- the error message changed in PG14 | ||
do $$ | ||
begin | ||
create role r bypassrls; | ||
exception when insufficient_privilege then null; | ||
end; | ||
$$ language plpgsql; | ||
create role r; | ||
alter role r nobypassrls; | ||
ERROR: permission denied to alter role | ||
DETAIL: Only roles with the BYPASSRLS attribute may change the BYPASSRLS attribute. | ||
alter role r bypassrls; | ||
ERROR: permission denied to alter role | ||
DETAIL: Only roles with the BYPASSRLS attribute may change the BYPASSRLS attribute. | ||
drop role r; | ||
set role privileged_role; | ||
\echo | ||
|
||
-- superuser can manage bypassrls role attribute | ||
set role postgres; | ||
create role r bypassrls; | ||
select rolbypassrls from pg_roles where rolname = 'r'; | ||
rolbypassrls | ||
-------------- | ||
t | ||
(1 row) | ||
|
||
alter role r nobypassrls; | ||
select rolbypassrls from pg_roles where rolname = 'r'; | ||
rolbypassrls | ||
-------------- | ||
f | ||
(1 row) | ||
|
||
alter role r bypassrls; | ||
select rolbypassrls from pg_roles where rolname = 'r'; | ||
rolbypassrls | ||
-------------- | ||
t | ||
(1 row) | ||
|
||
drop role r; | ||
set role privileged_role; | ||
\echo | ||
|
||
-- regression: https://github.com/supabase/supautils/issues/34 | ||
create role tmp; | ||
alter role tmp; | ||
\echo | ||
|
||
-- privileged_role can modify reserved roles GUCs | ||
set role privileged_role; | ||
alter role authenticator set search_path to public; | ||
alter role authenticator set statement_timeout = '15s'; | ||
\echo | ||
|
||
-- privileged_role can do GRANT <role> to <reserved_role> | ||
grant testme to authenticator; | ||
\echo | ||
|
||
-- privileged_role can set wildcard privileged_role_allowed_configs | ||
alter role authenticator set pgrst.db_plan_enabled to true; | ||
alter role authenticator set pgrst.db_prepared_statements to false; | ||
alter role authenticator set other.nested.foo to true; | ||
alter role authenticator set other.nested.bar to true; | ||
\echo | ||
|
||
-- privileged_role cannot drop, rename or nologin reserved role | ||
drop role authenticator; | ||
ERROR: "authenticator" is a reserved role, only superusers can modify it | ||
alter role authenticator rename to authorized; | ||
ERROR: "authenticator" is a reserved role, only superusers can modify it | ||
alter role authenticator nologin; | ||
ERROR: "authenticator" is a reserved role, only superusers can modify it | ||
\echo | ||
|
||
-- privileged_role cannot manage [no]superuser attribute | ||
create role r superuser; | ||
ERROR: permission denied to create role | ||
DETAIL: Only roles with the SUPERUSER attribute may create roles with the SUPERUSER attribute. | ||
create role r; | ||
alter role r superuser; | ||
ERROR: permission denied to alter role | ||
DETAIL: Only roles with the SUPERUSER attribute may alter roles with the SUPERUSER attribute. | ||
alter role postgres nosuperuser; | ||
ERROR: permission denied to alter role | ||
DETAIL: Only superusers can alter privileged roles. | ||
drop role r; | ||
\echo | ||
|
||
-- member of privileged_role can do privileged role stuff | ||
set role privileged_role_member; | ||
grant testme to authenticator; | ||
NOTICE: role "authenticator" has already been granted membership in role "testme" by role "privileged_role" | ||
set role privileged_role; | ||
\echo | ||
|
||
-- privileged_role can manage publications | ||
create publication p for all tables; | ||
drop publication p; | ||
-- not testing `create publication ... for tables in schema ...` because it's PG15+ |
File renamed without changes.
File renamed without changes.
This file contains 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 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
File renamed without changes.
File renamed without changes.
Oops, something went wrong.