fix(rds): give the PostgreSQL master user rds_superuser with ADMIN OPTION (#9953)

The master user joined rds_superuser without ADMIN OPTION. From
PostgreSQL 16, CREATEROLE no longer lets a role add members to a role
it holds no ADMIN OPTION on, so the master could not GRANT rds_superuser
to another role, which RDS documents a member of rds_superuser can do.
The master now joins rds_superuser WITH ADMIN OPTION, on initialization
and again after a snapshot restore.

Closes #9952
This commit is contained in:
Ignas authored and GitHub committed 2026-12-01 22:35:07 -04:00
1 parent 3f351fa0ca
commit 9e5ab0c3ca
4 files changed
+9 -4

No files matched your search

+1
View File
@@ -1444,6 +1444,7 @@ FLOCI_STORAGE_HOST_PERSISTENT_PATH=/absolute/host/path/data
A PostgreSQL instance or cluster is initialized as RDS initializes one. The bootstrap superuser is `rdsadmin`, the
role RDS keeps for its own management tasks, and the master user is an ordinary role created as RDS creates it:
`LOGIN NOSUPERUSER INHERIT CREATEDB CREATEROLE NOREPLICATION VALID UNTIL 'infinity'`, a member of `rds_superuser`
with ADMIN OPTION, so it can grant `rds_superuser` to other roles
(RDS User Guide, [Understanding the rds_superuser role](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Appendix.PostgreSQL.CommonDBATasks.Roles.rds_superuser.html)).
The master owns the `postgres` and `template1` databases and the instance's own database, so the objects it
owns can be handed to another role with `REASSIGN OWNED BY <master> TO <role>` once the master is a member of
@@ -959,8 +959,9 @@ public class RdsContainerManager implements RdsBackendGate, RdsBackendEndpointRe
*
* <ul>
* <li>The master user is {@code LOGIN NOSUPERUSER INHERIT CREATEDB CREATEROLE NOREPLICATION VALID UNTIL
* 'infinity'} and a member of {@code rds_superuser} (RDS User Guide, "Understanding the rds_superuser
* role"), and owns the {@code postgres} and {@code template1} databases.</li>
* 'infinity'} and a member of {@code rds_superuser} with ADMIN OPTION, so it can grant the role to other
* users (RDS User Guide, "Understanding the rds_superuser role"), which PostgreSQL 16 and later refuse to a
* {@code CREATEROLE} role without it. It owns the {@code postgres} and {@code template1} databases.</li>
* <li>{@code rds_superuser} holds, with ADMIN OPTION, the predefined roles an RDS instance grants it, where
* the server has them, and {@code rds_password} and {@code rds_replication}, which the master can
* therefore grant to other users. {@code rds_iam} is granted to it with ADMIN OPTION alone on
@@ -998,7 +999,7 @@ public class RdsContainerManager implements RdsBackendGate, RdsBackendEndpointRe
"""
+ "ALTER ROLE " + master + " WITH LOGIN NOSUPERUSER INHERIT CREATEDB CREATEROLE NOREPLICATION"
+ " NOBYPASSRLS VALID UNTIL 'infinity';\n"
+ "GRANT rds_superuser TO " + master + ";\n"
+ "GRANT rds_superuser TO " + master + " WITH ADMIN OPTION;\n"
+ "ALTER DATABASE postgres OWNER TO " + master + ";\n"
+ "ALTER DATABASE template1 OWNER TO " + master + ";\n"
+ "SELECT 'CREATE DATABASE " + POSTGRES_ADMIN_ROLE + "' WHERE NOT EXISTS "
@@ -361,7 +361,7 @@ class RdsContainerManagerTest {
assertTrue(sql.startsWith("CREATE ROLE \"ad\"\"min\" WITH LOGIN PASSWORD 'it''s';\n"));
assertTrue(sql.contains("ALTER ROLE \"ad\"\"min\" WITH LOGIN NOSUPERUSER INHERIT CREATEDB CREATEROLE"
+ " NOREPLICATION NOBYPASSRLS VALID UNTIL 'infinity';"));
assertTrue(sql.contains("GRANT rds_superuser TO \"ad\"\"min\";"));
assertTrue(sql.contains("GRANT rds_superuser TO \"ad\"\"min\" WITH ADMIN OPTION;"));
assertTrue(sql.contains("ALTER DATABASE postgres OWNER TO \"ad\"\"min\";"));
assertTrue(sql.contains("ALTER DATABASE template1 OWNER TO \"ad\"\"min\";"));
assertTrue(sql.endsWith("ALTER DATABASE \"appdb\" OWNER TO \"ad\"\"min\";\n"));
@@ -59,6 +59,9 @@ class RdsPostgresMasterRoleIntegrationTest {
sql.execute("CREATE ROLE cdc LOGIN");
sql.execute("GRANT rds_replication TO cdc");
sql.execute("CREATE ROLE dba LOGIN");
sql.execute("GRANT rds_superuser TO dba");
assertEquals("true", row(sql, "SELECT pg_has_role('dba', 'rds_superuser', 'member')::text"));
sql.execute("CREATE ROLE app_user LOGIN");
sql.execute("GRANT rds_iam TO app_user");
}