mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(rds): initialize PostgreSQL as rdsadmin, with the master user in rds_superuser (#9182)
A PostgreSQL backend started with the master user as POSTGRES_USER, so the master was the bootstrap superuser and owned the system catalog: REASSIGN OWNED BY <master> failed with "required by the database system", and rds_superuser did not exist. A new backend is now initialized as rdsadmin, as RDS initializes one. A first-boot script creates the master as LOGIN NOSUPERUSER INHERIT CREATEDB CREATEROLE NOREPLICATION VALID UNTIL 'infinity' in rds_superuser (RDS User Guide, "Understanding the rds_superuser role"). The master owns postgres, template1 and the instance's database. rds_superuser holds rds_password, rds_replication and the predefined pg_* roles RDS grants it, with ADMIN OPTION, and ADMIN OPTION alone on rds_iam on PostgreSQL 16 and later, so the master can grant rds_iam without becoming an IAM-only member. The rdsadmin database is closed to PUBLIC. rdsadmin gets a random password on every start, which only the auth proxy uses: an IAM session for a role other than the master is opened as rdsadmin and handed over, since only a superuser can SET SESSION AUTHORIZATION. No client may log in as rdsadmin. The proxy's rds_iam walk skips grants of ADMIN OPTION alone, such as the one PostgreSQL 16 gives the master on each role it creates. Snapshots, restores, exports and database renames run as rdsadmin; a restore applies the RDS roles and ownership again and gives rdsadmin back its password. A data volume first initialized by an earlier Floci keeps its master as the bootstrap superuser, and a master named rdsadmin stays one. Two tests leaned on a superuser master: the IAM replication test now turns logical replication on through rds.logical_replication in a parameter group instead of ALTER SYSTEM, and the startup-parameters test stores its superuser-only role defaults as rdsadmin and gives app_user its schema with GRANT USAGE. Closes #5885
This commit is contained in:
1 parent
d63ad7c226
commit
94c0504bca
11 files changed
+779
-60
No files matched your search
@@ -7,6 +7,17 @@ import java.io.Closeable;
|
||||
*/
|
||||
public class RdsContainerHandle {
|
||||
|
||||
/**
|
||||
* A PostgreSQL backend's superuser, and the password Floci set for it when this container started. The password
|
||||
* is null when the superuser is the master user, which logs in with the master's own password.
|
||||
*/
|
||||
public record PostgresSuperuser(String user, String password) {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PostgresSuperuser[user=" + user + "]";
|
||||
}
|
||||
}
|
||||
|
||||
private final String containerId;
|
||||
private final String runtimeId;
|
||||
private final String instanceId;
|
||||
@@ -15,6 +26,7 @@ public class RdsContainerHandle {
|
||||
private final String storageKey;
|
||||
private final String containerKey;
|
||||
private Closeable logStream;
|
||||
private volatile PostgresSuperuser postgresSuperuser;
|
||||
|
||||
public RdsContainerHandle(String containerId, String instanceId, String host, int port) {
|
||||
this(containerId, instanceId, instanceId, host, port, null);
|
||||
@@ -52,4 +64,6 @@ public class RdsContainerHandle {
|
||||
public String getContainerKey() { return containerKey; }
|
||||
public Closeable getLogStream() { return logStream; }
|
||||
public void setLogStream(Closeable logStream) { this.logStream = logStream; }
|
||||
public PostgresSuperuser getPostgresSuperuser() { return postgresSuperuser; }
|
||||
public void setPostgresSuperuser(PostgresSuperuser postgresSuperuser) { this.postgresSuperuser = postgresSuperuser; }
|
||||
}
|
||||
@@ -34,9 +34,11 @@ import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Path;
|
||||
import java.security.SecureRandom;
|
||||
import java.time.Clock;
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HexFormat;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
@@ -80,6 +82,15 @@ public class RdsContainerManager implements RdsBackendGate, RdsBackendEndpointRe
|
||||
private static final Map<String, String> MYSQL_OPTION_NAMES = Map.of("time_zone", "default-time-zone");
|
||||
/** How long a server started with a parameter group's options gets to start listening. */
|
||||
private static final int PARAMETER_GROUP_START_SECONDS = 120;
|
||||
/**
|
||||
* The role RDS for PostgreSQL runs its own management tasks as ("rdsadmin – A role that's created to handle
|
||||
* many of the management tasks that the administrator with superuser privileges would perform on a
|
||||
* standalone PostgreSQL database", RDS User Guide, "Understanding the rds_superuser role"). A PostgreSQL
|
||||
* backend is initialized as this role, and the master user is created as an ordinary role beside it.
|
||||
*/
|
||||
static final String POSTGRES_ADMIN_ROLE = "rdsadmin";
|
||||
/** The bootstrap superuser of a PostgreSQL cluster, whatever initdb named it. */
|
||||
private static final String POSTGRES_SUPERUSER_SQL = "SELECT rolname FROM pg_catalog.pg_roles WHERE oid = 10";
|
||||
|
||||
private final ContainerBuilder containerBuilder;
|
||||
private final ContainerLifecycleManager lifecycleManager;
|
||||
@@ -412,6 +423,9 @@ public class RdsContainerManager implements RdsBackendGate, RdsBackendEndpointRe
|
||||
if (needsMasterGrant(engine, masterUsername)) {
|
||||
installMasterGrantInitScript(createdContainerId, masterUsername);
|
||||
}
|
||||
if (engine == DatabaseEngine.POSTGRES && bootstrapsAsAdminRole(masterUsername)) {
|
||||
installPostgresMasterInitScript(createdContainerId, masterUsername, masterPassword, dbName);
|
||||
}
|
||||
ContainerInfo info = lifecycleManager.startCreated(createdContainerId, spec);
|
||||
EndpointInfo endpoint = info.getEndpoint(enginePort);
|
||||
|
||||
@@ -419,11 +433,13 @@ public class RdsContainerManager implements RdsBackendGate, RdsBackendEndpointRe
|
||||
if (!engineParameterOptions(engine, engineParameters).isEmpty()) {
|
||||
awaitServerWithParameterGroup(containerName, info.containerId(), enginePort);
|
||||
}
|
||||
initializeEngine(containerName, info.containerId(), engine, masterUsername, masterPassword, dbName);
|
||||
RdsContainerHandle.PostgresSuperuser postgresSuperuser = initializeEngine(
|
||||
containerName, info.containerId(), engine, masterUsername, masterPassword, dbName);
|
||||
|
||||
handle = new RdsContainerHandle(
|
||||
info.containerId(), effectiveRuntimeId, instanceId,
|
||||
endpoint.host(), endpoint.port(), storageKey, containerKey);
|
||||
handle.setPostgresSuperuser(postgresSuperuser);
|
||||
|
||||
// Attach log streaming
|
||||
if (!ephemeral) {
|
||||
@@ -634,6 +650,7 @@ public class RdsContainerManager implements RdsBackendGate, RdsBackendEndpointRe
|
||||
newInstanceId, handle.getHost(), handle.getPort(),
|
||||
handle.getStorageKey(), handle.getContainerKey());
|
||||
moved.setLogStream(handle.getLogStream());
|
||||
moved.setPostgresSuperuser(handle.getPostgresSuperuser());
|
||||
activeContainers.put(newRuntimeId, moved);
|
||||
}
|
||||
activeStorageOwners.replaceAll((key, owner) -> owner.equals(oldRuntimeId) ? newRuntimeId : owner);
|
||||
@@ -879,15 +896,127 @@ public class RdsContainerManager implements RdsBackendGate, RdsBackendEndpointRe
|
||||
return Integer.parseInt(tag.substring(0, end));
|
||||
}
|
||||
|
||||
private void initializeEngine(String containerName, String containerId, DatabaseEngine engine,
|
||||
String masterUsername, String masterPassword, String dbName) {
|
||||
/** Returns a PostgreSQL backend's superuser, and null for the other engines. */
|
||||
private RdsContainerHandle.PostgresSuperuser initializeEngine(String containerName, String containerId,
|
||||
DatabaseEngine engine, String masterUsername,
|
||||
String masterPassword, String dbName) {
|
||||
switch (engine) {
|
||||
case POSTGRES -> initializePostgresIamRole(containerName, containerId, masterUsername);
|
||||
case POSTGRES -> {
|
||||
return initializePostgres(containerName, containerId, masterUsername);
|
||||
}
|
||||
case SQLSERVER -> initializeSqlServerMaster(containerName, containerId,
|
||||
masterUsername, masterPassword);
|
||||
case MYSQL, MARIADB -> {
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** The master user a PostgreSQL backend is created with: the requested one, else {@code postgres}. */
|
||||
static String effectivePostgresMaster(String masterUsername) {
|
||||
return (masterUsername != null && !masterUsername.isBlank()) ? masterUsername : "postgres";
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a new PostgreSQL backend is initialized as {@link #POSTGRES_ADMIN_ROLE} with the master user created
|
||||
* beside it, as on RDS. A master user that is itself named after that role stays the bootstrap superuser.
|
||||
*/
|
||||
static boolean bootstrapsAsAdminRole(String masterUsername) {
|
||||
return !POSTGRES_ADMIN_ROLE.equals(effectivePostgresMaster(masterUsername));
|
||||
}
|
||||
|
||||
/**
|
||||
* What a new PostgreSQL backend runs once, as {@link #POSTGRES_ADMIN_ROLE}, while its data directory is
|
||||
* initialized: the master user, created as RDS creates it, then {@link #postgresRdsRolesSql}, then the
|
||||
* requested database handed to the master. The image creates that database, so an image's own init scripts
|
||||
* (PostGIS installs its extension) still run in it. One requested under the name {@code rdsadmin} is the
|
||||
* master's too, so the master can open it although the role setup closes it to everyone else.
|
||||
*/
|
||||
static String postgresMasterInitSql(String masterUsername, String masterPassword, String dbName) {
|
||||
String master = effectivePostgresMaster(masterUsername);
|
||||
String database = (dbName != null && !dbName.isBlank()) ? dbName : master;
|
||||
StringBuilder sql = new StringBuilder()
|
||||
.append("CREATE ROLE ").append(quotePostgresIdentifier(master)).append(" WITH LOGIN PASSWORD ")
|
||||
.append(postgresLiteral(masterPassword == null ? "" : masterPassword)).append(";\n")
|
||||
.append(postgresRdsRolesSql(master));
|
||||
if (!Set.of("postgres", "template0", "template1").contains(database)) {
|
||||
sql.append("ALTER DATABASE ").append(quotePostgresIdentifier(database))
|
||||
.append(" OWNER TO ").append(quotePostgresIdentifier(master)).append(";\n");
|
||||
}
|
||||
return sql.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* The roles and ownership RDS gives an instance, applied as {@link #POSTGRES_ADMIN_ROLE} when a backend is
|
||||
* initialized and again after a snapshot is restored into one; it may run any number of times. A psql
|
||||
* script, not one statement: it creates the {@code rdsadmin} database with {@code \gexec} when it is missing.
|
||||
*
|
||||
* <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>
|
||||
* <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
|
||||
* PostgreSQL 16 and later, so the master can grant it without becoming a member, which would make the
|
||||
* master an IAM-only role; before 16 {@code CREATEROLE} already lets it.</li>
|
||||
* <li>The {@code rdsadmin} database is closed to everyone but its owner.</li>
|
||||
* </ul>
|
||||
*/
|
||||
static String postgresRdsRolesSql(String masterUsername) {
|
||||
String master = quotePostgresIdentifier(effectivePostgresMaster(masterUsername));
|
||||
return """
|
||||
DO $floci$
|
||||
DECLARE
|
||||
predefined text;
|
||||
BEGIN
|
||||
FOREACH predefined IN ARRAY ARRAY['rds_superuser', 'rds_password', 'rds_replication', 'rds_iam']
|
||||
LOOP
|
||||
IF NOT EXISTS (SELECT 1 FROM pg_catalog.pg_roles WHERE rolname = predefined) THEN
|
||||
EXECUTE pg_catalog.format('CREATE ROLE %I', predefined);
|
||||
END IF;
|
||||
END LOOP;
|
||||
FOREACH predefined IN ARRAY ARRAY['pg_checkpoint', 'pg_create_subscription', 'pg_maintain',
|
||||
'pg_monitor', 'pg_read_all_data', 'pg_signal_backend', 'pg_use_reserved_connections',
|
||||
'pg_write_all_data', 'rds_password', 'rds_replication']
|
||||
LOOP
|
||||
IF EXISTS (SELECT 1 FROM pg_catalog.pg_roles WHERE rolname = predefined) THEN
|
||||
EXECUTE pg_catalog.format('GRANT %I TO rds_superuser WITH ADMIN OPTION', predefined);
|
||||
END IF;
|
||||
END LOOP;
|
||||
IF pg_catalog.current_setting('server_version_num')::int >= 160000 THEN
|
||||
EXECUTE 'GRANT rds_iam TO rds_superuser WITH ADMIN OPTION, INHERIT FALSE, SET FALSE';
|
||||
END IF;
|
||||
END
|
||||
$floci$;
|
||||
"""
|
||||
+ "ALTER ROLE " + master + " WITH LOGIN NOSUPERUSER INHERIT CREATEDB CREATEROLE NOREPLICATION"
|
||||
+ " NOBYPASSRLS VALID UNTIL 'infinity';\n"
|
||||
+ "GRANT rds_superuser TO " + master + ";\n"
|
||||
+ "ALTER DATABASE postgres OWNER TO " + master + ";\n"
|
||||
+ "ALTER DATABASE template1 OWNER TO " + master + ";\n"
|
||||
+ "SELECT 'CREATE DATABASE " + POSTGRES_ADMIN_ROLE + "' WHERE NOT EXISTS "
|
||||
+ "(SELECT 1 FROM pg_catalog.pg_database WHERE datname = '" + POSTGRES_ADMIN_ROLE + "')\n"
|
||||
+ "\\gexec\n"
|
||||
+ "REVOKE ALL ON DATABASE " + POSTGRES_ADMIN_ROLE + " FROM PUBLIC;\n";
|
||||
}
|
||||
|
||||
/** A PostgreSQL string literal: wrapped in single quotes, with each embedded one doubled. */
|
||||
static String postgresLiteral(String value) {
|
||||
return "'" + value.replace("'", "''") + "'";
|
||||
}
|
||||
|
||||
/**
|
||||
* Delivered as a {@code /docker-entrypoint-initdb.d} script, as {@link #installMasterGrantInitScript} is, so
|
||||
* it runs only against an empty data directory: a volume the backend has used before keeps the roles it
|
||||
* has, including one whose master user is still the bootstrap superuser.
|
||||
*/
|
||||
private void installPostgresMasterInitScript(String containerId, String masterUsername, String masterPassword,
|
||||
String dbName) {
|
||||
byte[] sql = postgresMasterInitSql(masterUsername, masterPassword, dbName).getBytes(StandardCharsets.UTF_8);
|
||||
RetryingTarCopier.copyBytes(lifecycleManager.getDockerClient(), containerId,
|
||||
"/docker-entrypoint-initdb.d", "floci-rds-master.sql", sql, 0644,
|
||||
RetryingTarCopier.DEFAULT_MAX_ATTEMPTS, uploadBackoffMillis);
|
||||
}
|
||||
|
||||
private void initializeSqlServerMaster(String containerName, String containerId,
|
||||
@@ -960,23 +1089,85 @@ public class RdsContainerManager implements RdsBackendGate, RdsBackendEndpointRe
|
||||
* temporary server that listens only on the Unix socket, so a socket connection can succeed
|
||||
* before the final server is up. Loopback is trusted by the generated pg_hba.conf.
|
||||
*/
|
||||
private void initializePostgresIamRole(String containerName, String containerId, String masterUsername) {
|
||||
String effectiveUser = (masterUsername != null && !masterUsername.isBlank()) ? masterUsername : "postgres";
|
||||
private RdsContainerHandle.PostgresSuperuser initializePostgres(String containerName, String containerId,
|
||||
String masterUsername) {
|
||||
String master = effectivePostgresMaster(masterUsername);
|
||||
String[] lookup = {
|
||||
"psql",
|
||||
"-h", "127.0.0.1",
|
||||
"-X", "-q", "-A", "-t",
|
||||
"-v", "ON_ERROR_STOP=1",
|
||||
"-U", master,
|
||||
"-d", "postgres",
|
||||
"-c", POSTGRES_SUPERUSER_SQL
|
||||
};
|
||||
PostgresStartupSignal startup = new PostgresStartupSignal();
|
||||
String superuser = master;
|
||||
// This path receives a newly created container, so replay cannot include a prior start.
|
||||
try (Closeable observation = logStreamer.observe(containerId, startup)) {
|
||||
String found = execUntilSuccess(containerName, containerId, lookup, "PostgreSQL superuser lookup",
|
||||
startup.signal).trim();
|
||||
if (!found.isEmpty()) {
|
||||
superuser = found;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
LOG.warnv(e, "Could not close PostgreSQL startup observation for {0}", containerName);
|
||||
}
|
||||
// A backend Floci initialized as rdsadmin gets a password for this start only, which the proxy alone
|
||||
// knows; one whose master user is the bootstrap superuser keeps logging in with the master's password.
|
||||
String password = superuser.equals(master) ? null : randomPostgresPassword();
|
||||
String sql = postgresIamRoleInitSql() + (password == null ? ""
|
||||
: "ALTER ROLE " + quotePostgresIdentifier(superuser) + " WITH PASSWORD " + postgresLiteral(password)
|
||||
+ ";\n");
|
||||
String[] cmd = {
|
||||
"psql",
|
||||
"-h", "127.0.0.1",
|
||||
"-v", "ON_ERROR_STOP=1",
|
||||
"-U", effectiveUser,
|
||||
"-U", superuser,
|
||||
"-d", "postgres",
|
||||
"-c", postgresIamRoleInitSql()
|
||||
"-c", sql
|
||||
};
|
||||
PostgresStartupSignal startup = new PostgresStartupSignal();
|
||||
// This path receives a newly created container, so replay cannot include a prior start.
|
||||
try (Closeable observation = logStreamer.observe(containerId, startup)) {
|
||||
execUntilSuccess(containerName, containerId, cmd, "PostgreSQL IAM role", startup.signal);
|
||||
} catch (IOException e) {
|
||||
LOG.warnv(e, "Could not close PostgreSQL startup observation for {0}", containerName);
|
||||
execUntilSuccess(containerName, containerId, cmd, "PostgreSQL IAM role");
|
||||
return new RdsContainerHandle.PostgresSuperuser(superuser, password);
|
||||
}
|
||||
|
||||
private static String randomPostgresPassword() {
|
||||
byte[] bytes = new byte[24];
|
||||
new SecureRandom().nextBytes(bytes);
|
||||
return HexFormat.of().formatHex(bytes);
|
||||
}
|
||||
|
||||
/**
|
||||
* The superuser Floci runs its own SQL in a PostgreSQL backend as: {@link #POSTGRES_ADMIN_ROLE} for a backend
|
||||
* initialized as it, the master user for one whose master is the bootstrap superuser, as found when the
|
||||
* container started, and the master user for a container this manager did not start.
|
||||
*/
|
||||
String postgresSuperuser(String containerId, String masterUsername) {
|
||||
RdsContainerHandle handle = activeHandleOfContainer(containerId);
|
||||
RdsContainerHandle.PostgresSuperuser superuser = handle == null ? null : handle.getPostgresSuperuser();
|
||||
return superuser != null ? superuser.user() : effectivePostgresMaster(masterUsername);
|
||||
}
|
||||
|
||||
/**
|
||||
* The login the auth proxy hands an IAM session over through: the {@link #POSTGRES_ADMIN_ROLE} superuser
|
||||
* with this start's password, or null when the runtime has none, so the master user's login serves.
|
||||
*/
|
||||
public RdsContainerHandle.PostgresSuperuser postgresHandoverLogin(String runtimeId) {
|
||||
RdsContainerHandle handle = runtimeId == null ? null : activeContainers.get(runtimeId);
|
||||
RdsContainerHandle.PostgresSuperuser superuser = handle == null ? null : handle.getPostgresSuperuser();
|
||||
return superuser == null || superuser.password() == null ? null : superuser;
|
||||
}
|
||||
|
||||
private RdsContainerHandle activeHandleOfContainer(String containerId) {
|
||||
if (containerId == null) {
|
||||
return null;
|
||||
}
|
||||
for (RdsContainerHandle handle : activeContainers.values()) {
|
||||
if (containerId.equals(handle.getContainerId())) {
|
||||
return handle;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1074,12 +1265,13 @@ public class RdsContainerManager implements RdsBackendGate, RdsBackendEndpointRe
|
||||
RetryingTarCopier.DEFAULT_MAX_ATTEMPTS, uploadBackoffMillis);
|
||||
}
|
||||
|
||||
private void execUntilSuccess(String containerName, String containerId, String[] cmd, String description) {
|
||||
execUntilSuccess(containerName, containerId, cmd, description, new Semaphore(0));
|
||||
private String execUntilSuccess(String containerName, String containerId, String[] cmd, String description) {
|
||||
return execUntilSuccess(containerName, containerId, cmd, description, new Semaphore(0));
|
||||
}
|
||||
|
||||
private void execUntilSuccess(String containerName, String containerId, String[] cmd, String description,
|
||||
Semaphore startupSignal) {
|
||||
/** Runs {@code cmd} until it exits 0, for up to a minute, and returns what it wrote to stdout. */
|
||||
private String execUntilSuccess(String containerName, String containerId, String[] cmd, String description,
|
||||
Semaphore startupSignal) {
|
||||
String lastOutput = "";
|
||||
for (int attempt = 1; attempt <= 60; attempt++) {
|
||||
try {
|
||||
@@ -1087,7 +1279,7 @@ public class RdsContainerManager implements RdsBackendGate, RdsBackendEndpointRe
|
||||
lastOutput = result.stdout() + (result.stderr().isEmpty() ? "" : "\n" + result.stderr());
|
||||
if (result.exitCode() == 0) {
|
||||
LOG.infov("Initialized {0} in RDS container {1}", description, containerName);
|
||||
return;
|
||||
return result.stdout();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
lastOutput = e.getMessage();
|
||||
@@ -1219,7 +1411,7 @@ public class RdsContainerManager implements RdsBackendGate, RdsBackendEndpointRe
|
||||
}
|
||||
|
||||
public String createPostgresSnapshot(String containerId, String masterUsername) {
|
||||
String effectiveUser = (masterUsername != null && !masterUsername.isBlank()) ? masterUsername : "postgres";
|
||||
String effectiveUser = postgresSuperuser(containerId, masterUsername);
|
||||
String[] cmd = {
|
||||
"pg_dumpall",
|
||||
"-U", effectiveUser
|
||||
@@ -1236,8 +1428,8 @@ public class RdsContainerManager implements RdsBackendGate, RdsBackendEndpointRe
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs one query as the master user and returns its rows, one per line, unaligned and without
|
||||
* headers. The session uses ISO dates in UTC, so a value's text output does not depend on the
|
||||
* Runs one query as the backend's superuser ({@link #postgresSuperuser}) and returns its rows, one per
|
||||
* line, unaligned and without headers. The session uses ISO dates in UTC, so a value's text output does not depend on the
|
||||
* image's defaults.
|
||||
*/
|
||||
public String queryPostgres(String containerId, String masterUsername, String database, String sql) {
|
||||
@@ -1252,7 +1444,7 @@ public class RdsContainerManager implements RdsBackendGate, RdsBackendEndpointRe
|
||||
*/
|
||||
public void queryPostgres(String containerId, String masterUsername, String database, String sql,
|
||||
OutputStream rows, int timeoutSeconds) {
|
||||
String effectiveUser = (masterUsername != null && !masterUsername.isBlank()) ? masterUsername : "postgres";
|
||||
String effectiveUser = postgresSuperuser(containerId, masterUsername);
|
||||
String[] cmd = {
|
||||
"env", "PGOPTIONS=-c DateStyle=ISO -c TimeZone=UTC -c IntervalStyle=postgres",
|
||||
"psql", "-X", "-q", "-A", "-t", "-v", "ON_ERROR_STOP=1",
|
||||
@@ -1269,13 +1461,32 @@ public class RdsContainerManager implements RdsBackendGate, RdsBackendEndpointRe
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Replays a {@link #createPostgresSnapshot} dump as the backend's superuser. In a backend initialized as
|
||||
* {@link #POSTGRES_ADMIN_ROLE}, the roles and ownership RDS gives an instance are applied again afterwards,
|
||||
* so a dump of an older backend, whose master user was the bootstrap superuser, restores with the master
|
||||
* as RDS has it, and that role gets back the password of this start, which the dump replaced.
|
||||
*/
|
||||
public void restorePostgresSnapshot(String containerId, String masterUsername, String sqlDump) {
|
||||
String effectiveUser = (masterUsername != null && !masterUsername.isBlank()) ? masterUsername : "postgres";
|
||||
String master = effectivePostgresMaster(masterUsername);
|
||||
String superuser = postgresSuperuser(containerId, master);
|
||||
boolean adminBackend = !superuser.equals(master);
|
||||
Map<String, String> files = new LinkedHashMap<>();
|
||||
files.put("dump.sql", sqlDump);
|
||||
files.put("restore.sh", postgresRestoreScript());
|
||||
files.put("restore.sh", postgresRestoreScript(
|
||||
adminBackend ? postgresRdsRolesSql(master) : postgresIamRoleInitSql()));
|
||||
runSnapshotScript(containerId, "postgres-restore", files,
|
||||
new String[]{"sh", "/tmp/restore.sh", effectiveUser}, List.of(), 60, 120, "psql restore");
|
||||
new String[]{"sh", "/tmp/restore.sh", superuser}, List.of(), 60, 120, "psql restore");
|
||||
RdsContainerHandle handle = activeHandleOfContainer(containerId);
|
||||
RdsContainerHandle.PostgresSuperuser login = handle == null ? null : handle.getPostgresSuperuser();
|
||||
if (adminBackend && login != null && login.password() != null) {
|
||||
String[] cmd = {"psql", "-v", "ON_ERROR_STOP=1", "-U", superuser, "-d", "postgres", "-c",
|
||||
"ALTER ROLE " + quotePostgresIdentifier(superuser) + " WITH PASSWORD "
|
||||
+ postgresLiteral(login.password()) + ";"};
|
||||
try (Lease _ = holdContainer(containerId)) {
|
||||
execUntilSuccess(containerId, containerId, cmd, "PostgreSQL superuser password");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1495,7 +1706,7 @@ public class RdsContainerManager implements RdsBackendGate, RdsBackendEndpointRe
|
||||
* template1, so it also works when {@code from} is {@code postgres}.
|
||||
*/
|
||||
public void renamePostgresDatabase(String containerId, String masterUsername, String from, String to) {
|
||||
String effectiveUser = (masterUsername != null && !masterUsername.isBlank()) ? masterUsername : "postgres";
|
||||
String effectiveUser = postgresSuperuser(containerId, masterUsername);
|
||||
String sql = "ALTER DATABASE " + quotePostgresIdentifier(from) + " RENAME TO " + quotePostgresIdentifier(to);
|
||||
String[] cmd = {"psql", "-v", "ON_ERROR_STOP=1", "-U", effectiveUser, "-d", "template1", "-c", sql};
|
||||
try (Lease _ = holdContainer(containerId)) {
|
||||
@@ -1517,6 +1728,14 @@ public class RdsContainerManager implements RdsBackendGate, RdsBackendEndpointRe
|
||||
}
|
||||
|
||||
static String postgresRestoreScript() {
|
||||
return postgresRestoreScript(postgresIamRoleInitSql());
|
||||
}
|
||||
|
||||
/**
|
||||
* The restore script, run as the backend's superuser, ending with {@code closingSql}, a psql script run once
|
||||
* the dump is replayed.
|
||||
*/
|
||||
static String postgresRestoreScript(String closingSql) {
|
||||
return """
|
||||
#!/bin/sh
|
||||
set -e
|
||||
@@ -1541,6 +1760,11 @@ public class RdsContainerManager implements RdsBackendGate, RdsBackendEndpointRe
|
||||
mv /tmp/dump_filtered.sql /tmp/dump.sql
|
||||
chmod 600 /tmp/dump.sql
|
||||
|
||||
# The databases kept above may belong to a role dropped below, as postgres and template1
|
||||
# belong to the master user of an instance initialized as rdsadmin
|
||||
psql -v ON_ERROR_STOP=1 -U "$USER" -d postgres -c "ALTER DATABASE postgres OWNER TO CURRENT_USER"
|
||||
psql -v ON_ERROR_STOP=1 -U "$USER" -d postgres -c "ALTER DATABASE template1 OWNER TO CURRENT_USER"
|
||||
|
||||
# Drop all non-current-user, non-system roles
|
||||
psql -v ON_ERROR_STOP=1 -U "$USER" -d postgres -tAc \\
|
||||
"SELECT rolname FROM pg_roles WHERE rolname <> current_user AND rolname NOT LIKE 'pg_%'" \\
|
||||
@@ -1552,9 +1776,10 @@ public class RdsContainerManager implements RdsBackendGate, RdsBackendEndpointRe
|
||||
# Replay the dump connected to postgres
|
||||
psql -v ON_ERROR_STOP=1 -U "$USER" -d postgres -f /tmp/dump.sql
|
||||
|
||||
# A dump taken before Floci created a predefined role does not recreate it
|
||||
# What a dump does not bring back: the predefined roles of a dump taken before Floci created
|
||||
# them, and in an instance initialized as rdsadmin the roles and ownership RDS gives it
|
||||
psql -v ON_ERROR_STOP=1 -U "$USER" -d postgres <<'SQL'
|
||||
""" + postgresIamRoleInitSql() + "SQL\n";
|
||||
""" + closingSql + "SQL\n";
|
||||
}
|
||||
|
||||
private static void addTarEntry(
|
||||
@@ -1638,16 +1863,19 @@ public class RdsContainerManager implements RdsBackendGate, RdsBackendEndpointRe
|
||||
return value;
|
||||
}
|
||||
|
||||
private List<String> buildEnvVars(DatabaseEngine engine, String masterUsername,
|
||||
String masterPassword, String dbName) {
|
||||
static List<String> buildEnvVars(DatabaseEngine engine, String masterUsername,
|
||||
String masterPassword, String dbName) {
|
||||
String effectiveUser = (masterUsername != null && !masterUsername.isBlank()) ? masterUsername : "postgres";
|
||||
String effectiveDb = (dbName != null && !dbName.isBlank()) ? dbName : effectiveUser;
|
||||
|
||||
List<String> envs = new ArrayList<>();
|
||||
switch (engine) {
|
||||
case POSTGRES -> {
|
||||
envs.add("POSTGRES_USER=" + effectiveUser);
|
||||
envs.add("POSTGRES_PASSWORD=" + masterPassword);
|
||||
// Initialized as rdsadmin, whose password Floci sets again on every start; the master user is
|
||||
// created by the init script installPostgresMasterInitScript adds.
|
||||
boolean adminBootstrap = bootstrapsAsAdminRole(masterUsername);
|
||||
envs.add("POSTGRES_USER=" + (adminBootstrap ? POSTGRES_ADMIN_ROLE : effectiveUser));
|
||||
envs.add("POSTGRES_PASSWORD=" + (adminBootstrap ? randomPostgresPassword() : masterPassword));
|
||||
envs.add("POSTGRES_DB=" + effectiveDb);
|
||||
envs.add("POSTGRES_HOST_AUTH_METHOD=md5");
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ import java.util.function.BiConsumer;
|
||||
* <li>For IAM logins, hand the session over to the role named in the token, then apply the
|
||||
* client's startup parameters as that role
|
||||
* <li>Send AuthOK + buffered messages to client, then bridge, guarding an IAM
|
||||
* session against being handed back to the master role
|
||||
* session against being handed back to the role the proxy connected as
|
||||
* </ol>
|
||||
*/
|
||||
public class PostgresProtocolHandler {
|
||||
@@ -91,7 +91,12 @@ public class PostgresProtocolHandler {
|
||||
}
|
||||
|
||||
/** The username/password the proxy opens the backend PostgreSQL connection with. */
|
||||
record BackendLogin(String user, String password) {}
|
||||
public record BackendLogin(String user, String password) {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BackendLogin[user=" + user + "]";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the backend connection. Called only once the client's startup message and credentials
|
||||
@@ -223,6 +228,27 @@ public class PostgresProtocolHandler {
|
||||
StartupObserver startupObserver,
|
||||
SessionRoleHandover roleHandover,
|
||||
boolean requireSsl) throws IOException {
|
||||
return authenticate(client, backendConnector, masterUsername, masterPassword, dbName,
|
||||
iamEnabled, sigV4, binding, tlsCertificates, passwordValidator, handshakeTimeoutMillis,
|
||||
forwardStartupParameters, databaseIamAuthentication, startupObserver, roleHandover, requireSsl,
|
||||
null);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code handoverLogin} is the superuser an IAM session for a role other than the master is opened as and
|
||||
* handed over from, {@code rdsadmin} in an instance initialized as RDS initializes one, since only a
|
||||
* superuser may {@code SET SESSION AUTHORIZATION}; null when the master user is that superuser. No client
|
||||
* may log in as it.
|
||||
*/
|
||||
public static AuthenticatedSession authenticate(Socket client, BackendConnector backendConnector,
|
||||
String masterUsername, String masterPassword, String dbName,
|
||||
boolean iamEnabled, RdsSigV4Validator sigV4,
|
||||
RdsProxyBinding binding, RdsProxyTlsCertificates tlsCertificates,
|
||||
PasswordValidator passwordValidator, int handshakeTimeoutMillis,
|
||||
boolean forwardStartupParameters, boolean databaseIamAuthentication,
|
||||
StartupObserver startupObserver,
|
||||
SessionRoleHandover roleHandover,
|
||||
boolean requireSsl, BackendLogin handoverLogin) throws IOException {
|
||||
|
||||
client.setSoTimeout(handshakeTimeoutMillis);
|
||||
|
||||
@@ -263,6 +289,17 @@ public class PostgresProtocolHandler {
|
||||
boolean isIam = iamEnabled && clientPassword.contains("X-Amz-Signature");
|
||||
boolean isMaster = masterUsername.equals(clientUsername);
|
||||
|
||||
// The superuser IAM sessions are handed over from is RDS's own role, which no client logs in as.
|
||||
if (handoverLogin != null && !isMaster && handoverLogin.user().equals(clientUsername)) {
|
||||
LOG.infov("RDS login refused for the internal superuser {0}",
|
||||
SigV4RequestValidator.sanitizeForLog(clientUsername));
|
||||
sendErrorResponse(clientOut, "FATAL", "28P01",
|
||||
"password authentication failed for user \"" + clientUsername + "\"");
|
||||
clientOut.flush();
|
||||
closeQuietly(client);
|
||||
return null;
|
||||
}
|
||||
|
||||
PasswordValidator.AuthResult authResult = PasswordValidator.AuthResult.PASSTHROUGH;
|
||||
if (isIam) {
|
||||
if (!sigV4.validate(clientPassword, clientUsername, binding)) {
|
||||
@@ -350,11 +387,15 @@ public class PostgresProtocolHandler {
|
||||
backendUser = handoverOutcome.databaseRole();
|
||||
backendPass = handoverOutcome.backendPassword() != null
|
||||
? handoverOutcome.backendPassword() : masterPassword;
|
||||
} else if (iamHandover && handoverLogin != null) {
|
||||
backendUser = handoverLogin.user();
|
||||
backendPass = handoverLogin.password();
|
||||
}
|
||||
// An IAM login for any role but the master runs on a session opened as the master and
|
||||
// handed over below, so PostgreSQL would apply the client's parameters with the
|
||||
// master's privileges: a "-c role=<master>" would outlive the handover and RESET ROLE
|
||||
// would regain the master. Those logins open with only "replication", which cannot be
|
||||
// An IAM login for any role but the master runs on a session opened as a superuser
|
||||
// (rdsadmin, or the master where it is the bootstrap superuser) and handed over below, so
|
||||
// PostgreSQL would apply the client's parameters with that superuser's privileges: a
|
||||
// "-c role=<superuser>" would outlive the handover and RESET ROLE would regain it.
|
||||
// Those logins open with only "replication", which cannot be
|
||||
// chosen later, and their other parameters are applied once the session belongs to the
|
||||
// role (Phase 5c). The proxy reads that session's results and sends it SQL of its own,
|
||||
// so it fixes the encoding to UTF-8.
|
||||
@@ -459,7 +500,7 @@ public class PostgresProtocolHandler {
|
||||
}
|
||||
|
||||
// Phase 5b: An IAM token is issued for one specific database role, so the session must
|
||||
// run as that role even though the backend connection was opened as master. Handing it
|
||||
// run as that role even though the backend connection was opened as a superuser. Handing it
|
||||
// over gives the session the role's own privileges and object ownership, and refuses a
|
||||
// token naming a role the database does not have instead of silently granting a master
|
||||
// session.
|
||||
@@ -502,7 +543,7 @@ public class PostgresProtocolHandler {
|
||||
// does when the role logs in directly. A parameter PostgreSQL refuses fails the
|
||||
// login with PostgreSQL's own reason, as it would at startup. One check cannot be
|
||||
// left to PostgreSQL: it authorizes session_authorization against the user the
|
||||
// backend connection authenticated as, the superuser master, so a change of it is
|
||||
// backend connection authenticated as, a superuser, so a change of it is
|
||||
// refused here before anything is applied, and the outcome is checked again below.
|
||||
if (forwardStartupParameters) {
|
||||
List<SessionSetting> settings;
|
||||
@@ -577,7 +618,7 @@ public class PostgresProtocolHandler {
|
||||
return null;
|
||||
}
|
||||
// PostgreSQL checks the replication privilege only when the WAL sender starts,
|
||||
// which it did as the master, and never again for replication commands.
|
||||
// which it did as the superuser, and never again for replication commands.
|
||||
if (requestsReplication(startup.parameters()) && !hasReplicationPrivilege(backendIn, backendOut)) {
|
||||
LOG.infov("RDS IAM replication connection refused for role {0}: replication privilege required",
|
||||
SigV4RequestValidator.sanitizeForLog(clientUsername));
|
||||
@@ -897,9 +938,22 @@ public class PostgresProtocolHandler {
|
||||
/**
|
||||
* Follow catalog membership edges, including indirect grants. pg_has_role treats a
|
||||
* superuser as privileged without a grant, which is not an IAM authentication opt-in.
|
||||
* A grant of ADMIN OPTION alone (PostgreSQL 16 and later), such as the one a role gets on each
|
||||
* role it creates, or rds_superuser's on rds_iam, which lets the master grant it, makes no
|
||||
* member, so it is not followed; servers before 16 record no such grant.
|
||||
* All SQL is ASCII even when the client selected a non-UTF8 encoding, and catalog
|
||||
* objects and operators are qualified independently of the client's search_path.
|
||||
*/
|
||||
/**
|
||||
* Whether a {@code pg_auth_members} row {@code a} makes its member a member of its role: a grant with INHERIT
|
||||
* or SET. The options are read through {@code to_jsonb}, so the query also runs on a server before 16, whose
|
||||
* rows have neither column and are memberships.
|
||||
*/
|
||||
private static final String MAKES_MEMBER = "(COALESCE((pg_catalog.to_jsonb(a) "
|
||||
+ "OPERATOR(pg_catalog.->>) 'inherit_option')::pg_catalog.bool, true) "
|
||||
+ "OR COALESCE((pg_catalog.to_jsonb(a) OPERATOR(pg_catalog.->>) 'set_option')"
|
||||
+ "::pg_catalog.bool, true))";
|
||||
|
||||
static String databaseRoleQuery(String role, boolean iam, boolean sessionRole) {
|
||||
return databaseRoleQuery(role, iam, sessionRole, true);
|
||||
}
|
||||
@@ -920,8 +974,9 @@ public class PostgresProtocolHandler {
|
||||
return "WITH RECURSIVE memberships(oid) AS ("
|
||||
+ "SELECT a.roleid FROM pg_catalog.pg_auth_members a JOIN pg_catalog.pg_roles r "
|
||||
+ "ON r.oid OPERATOR(pg_catalog.=) a.member WHERE r.rolname OPERATOR(pg_catalog.=) " + name
|
||||
+ " AND " + MAKES_MEMBER
|
||||
+ " UNION SELECT a.roleid FROM pg_catalog.pg_auth_members a JOIN memberships m "
|
||||
+ "ON a.member OPERATOR(pg_catalog.=) m.oid) "
|
||||
+ "ON a.member OPERATOR(pg_catalog.=) m.oid WHERE " + MAKES_MEMBER + ") "
|
||||
+ "SELECT r.oid::pg_catalog.text, " + admission
|
||||
+ " FROM pg_catalog.pg_roles r WHERE r.rolname OPERATOR(pg_catalog.=) " + name;
|
||||
}
|
||||
@@ -1226,7 +1281,7 @@ public class PostgresProtocolHandler {
|
||||
}
|
||||
|
||||
/**
|
||||
* The StartupMessage parameters of a backend session opened as the master for a handover:
|
||||
* The StartupMessage parameters of a backend session opened as a superuser for a handover:
|
||||
* {@code base}, UTF-8 for the proxy's own queries, and the client's {@code replication},
|
||||
* which can only be chosen at connection start.
|
||||
*/
|
||||
@@ -1293,7 +1348,7 @@ public class PostgresProtocolHandler {
|
||||
/**
|
||||
* Refuses a {@code session_authorization} setting naming anyone but {@code role}. PostgreSQL
|
||||
* would authorize it against the superuser the backend connection authenticated as, not the
|
||||
* token's role, so it would hand the session back to the master.
|
||||
* token's role, so it would hand the session back to that superuser.
|
||||
*/
|
||||
static void refuseSessionAuthorizationChange(List<SessionSetting> settings, String role)
|
||||
throws StartupParameterException {
|
||||
@@ -1509,8 +1564,8 @@ public class PostgresProtocolHandler {
|
||||
* Relays the authenticated session until either side closes.
|
||||
*
|
||||
* <p>An IAM session gets its backend→client direction read message by message so the proxy
|
||||
* sees PostgreSQL report the session's identity. The backend connection underneath is the
|
||||
* master one, so a client that talks the session back to the master role, via {@code RESET
|
||||
* sees PostgreSQL report the session's identity. The backend connection underneath is a
|
||||
* superuser's, so a client that talks the session back to that role, via {@code RESET
|
||||
* SESSION AUTHORIZATION} and its variants, would otherwise regain superuser, which the
|
||||
* token never granted. Watching the server's own {@code session_authorization} report catches
|
||||
* that whatever SQL produced it; the session is then terminated, since a handover that already
|
||||
|
||||
@@ -47,6 +47,7 @@ public class RdsAuthProxy {
|
||||
private final Semaphore connectionPermits;
|
||||
private final RdsBackendGate backendGate;
|
||||
private final BooleanSupplier forceSsl;
|
||||
private final HandoverLoginResolver handoverLoginResolver;
|
||||
|
||||
private volatile boolean running;
|
||||
private ServerSocket serverSocket;
|
||||
@@ -143,6 +144,24 @@ public class RdsAuthProxy {
|
||||
MySqlProtocolHandler.IamUserChecker iamUserChecker,
|
||||
RdsBackendGate backendGate, EndpointKind endpointKind,
|
||||
BooleanSupplier forceSsl) {
|
||||
this(instanceId, backendHost, backendPort, backendEndpointResolver, backendRuntimeId,
|
||||
engine, iamEnabled, masterUsername, masterPassword, dbName, sigV4,
|
||||
tlsCertificates, passwordValidator, handshakeTimeoutMillis,
|
||||
backendConnectTimeoutMillis, maxConnections, binding, iamUserChecker,
|
||||
backendGate, endpointKind, forceSsl, () -> null);
|
||||
}
|
||||
|
||||
public RdsAuthProxy(String instanceId, String backendHost, int backendPort,
|
||||
BackendEndpointResolver backendEndpointResolver, String backendRuntimeId,
|
||||
DatabaseEngine engine, boolean iamEnabled,
|
||||
String masterUsername, String masterPassword, String dbName,
|
||||
RdsSigV4Validator sigV4, RdsProxyTlsCertificates tlsCertificates,
|
||||
MasterPasswordCheck passwordValidator,
|
||||
int handshakeTimeoutMillis, int backendConnectTimeoutMillis,
|
||||
int maxConnections, RdsProxyBinding binding,
|
||||
MySqlProtocolHandler.IamUserChecker iamUserChecker,
|
||||
RdsBackendGate backendGate, EndpointKind endpointKind,
|
||||
BooleanSupplier forceSsl, HandoverLoginResolver handoverLoginResolver) {
|
||||
if (backendRuntimeId == null || backendRuntimeId.isBlank()) {
|
||||
throw new IllegalArgumentException("RDS backend runtime ID is required");
|
||||
}
|
||||
@@ -167,6 +186,7 @@ public class RdsAuthProxy {
|
||||
this.connectionPermits = new Semaphore(Math.max(1, maxConnections));
|
||||
this.backendGate = backendGate;
|
||||
this.forceSsl = forceSsl;
|
||||
this.handoverLoginResolver = handoverLoginResolver;
|
||||
}
|
||||
|
||||
public void start(int proxyPort) throws IOException {
|
||||
@@ -290,7 +310,8 @@ public class RdsAuthProxy {
|
||||
client, connector, masterUsername, masterPassword, dbName,
|
||||
iamEnabled, sigV4, binding, tlsCertificates, authAdapter,
|
||||
handshakeTimeoutMillis, true, endpointKind == EndpointKind.DATABASE,
|
||||
(user, database, parameters) -> { }, null, forceSsl.getAsBoolean());
|
||||
(user, database, parameters) -> { }, null, forceSsl.getAsBoolean(),
|
||||
handoverLoginResolver.resolve());
|
||||
if (session != null) {
|
||||
PostgresProtocolHandler.bridge(session);
|
||||
}
|
||||
@@ -359,4 +380,13 @@ public class RdsAuthProxy {
|
||||
public interface MasterPasswordCheck {
|
||||
boolean validate(String username, String password);
|
||||
}
|
||||
|
||||
/**
|
||||
* The login a PostgreSQL IAM session is opened as before it is handed over to the token's role, read for each
|
||||
* connection since the backend may have restarted since; null to use the master user's.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface HandoverLoginResolver {
|
||||
PostgresProtocolHandler.BackendLogin resolve();
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package io.floci.aws.services.rds.proxy;
|
||||
import io.floci.aws.config.EmulatorConfig;
|
||||
import io.floci.aws.core.common.docker.ContainerLifecycleManager.EndpointInfo;
|
||||
import io.floci.aws.services.rds.container.RdsBackendGate;
|
||||
import io.floci.aws.services.rds.container.RdsContainerHandle;
|
||||
import io.floci.aws.services.rds.container.RdsContainerManager;
|
||||
import io.floci.aws.services.rds.model.DatabaseEngine;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
@@ -86,6 +87,18 @@ public class RdsProxyManager {
|
||||
masterPassword, dbName, passwordValidator, binding, endpointKind);
|
||||
}
|
||||
|
||||
/**
|
||||
* The rdsadmin login of the runtime's current PostgreSQL container, which an IAM session is handed over from,
|
||||
* or null where the master user is the container's superuser.
|
||||
*/
|
||||
private RdsAuthProxy.HandoverLoginResolver handoverLogin(String backendRuntimeId) {
|
||||
return () -> {
|
||||
RdsContainerHandle.PostgresSuperuser superuser = containerManager.postgresHandoverLogin(backendRuntimeId);
|
||||
return superuser == null ? null
|
||||
: new PostgresProtocolHandler.BackendLogin(superuser.user(), superuser.password());
|
||||
};
|
||||
}
|
||||
|
||||
private void startProxy(String instanceId, String backendRuntimeId,
|
||||
DatabaseEngine engine, boolean iamEnabled,
|
||||
int proxyPort, String backendHost, int backendPort,
|
||||
@@ -110,7 +123,7 @@ public class RdsProxyManager {
|
||||
tlsCertificates, passwordValidator, rdsConfig.proxyHandshakeTimeoutMillis(),
|
||||
rdsConfig.proxyBackendConnectTimeoutMillis(), rdsConfig.proxyMaxConnections(),
|
||||
binding, username -> binding != null, backendGate, endpointKind,
|
||||
() -> forceSsl.test(instanceId));
|
||||
() -> forceSsl.test(instanceId), handoverLogin(backendRuntimeId));
|
||||
try {
|
||||
proxy.start(proxyPort);
|
||||
} catch (IOException e) {
|
||||
|
||||
Reference in new issue
Block a user