mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(rds): apply IAM auth toggles to running proxies (#3668)
Signed-off-by: 7487 <1042653432@qq.com>
This commit is contained in:
1 parent
2ee3aa67c0
commit
e1e98fd8dc
5 files changed
+43
-9
No files matched your search
+20
-8
@@ -2,7 +2,6 @@ package com.floci.test;
|
||||
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.Assumptions;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -191,15 +190,10 @@ class RdsJdbcCompatTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Disabled("modifyDbInstance does not propagate iamEnabled to running proxy (RdsAuthProxy.iamEnabled is final)")
|
||||
@Test
|
||||
@Order(5)
|
||||
@DisplayName("Enable IAM via modify on instance created without IAM")
|
||||
void enableIamViaModifyAndConnect() throws Exception {
|
||||
// This test documents the expected toggle behavior: create without IAM,
|
||||
// verify rejection, enable via modify, verify acceptance. Currently blocked
|
||||
// because RdsAuthProxy captures iamEnabled at startup and ModifyDBInstance
|
||||
// does not restart the proxy.
|
||||
@DisplayName("Toggle IAM via modify on a running instance")
|
||||
void toggleIamViaModifyOnRunningInstance() throws Exception {
|
||||
assumeInstanceCreated();
|
||||
|
||||
String toggleId = TestFixtures.uniqueName("rds-toggle");
|
||||
@@ -233,6 +227,7 @@ class RdsJdbcCompatTest {
|
||||
rds.modifyDBInstance(ModifyDbInstanceRequest.builder()
|
||||
.dbInstanceIdentifier(toggleId)
|
||||
.enableIAMDatabaseAuthentication(true)
|
||||
.applyImmediately(true)
|
||||
.build());
|
||||
|
||||
// Should accept IAM after enable
|
||||
@@ -250,6 +245,23 @@ class RdsJdbcCompatTest {
|
||||
} finally {
|
||||
connection.close();
|
||||
}
|
||||
|
||||
rds.modifyDBInstance(ModifyDbInstanceRequest.builder()
|
||||
.dbInstanceIdentifier(toggleId)
|
||||
.enableIAMDatabaseAuthentication(false)
|
||||
.applyImmediately(true)
|
||||
.build());
|
||||
|
||||
String token3 = rds.utilities().generateAuthenticationToken(GenerateAuthenticationTokenRequest.builder()
|
||||
.hostname(TestFixtures.proxyHost())
|
||||
.port(togglePort)
|
||||
.username(USERNAME)
|
||||
.region(REGION)
|
||||
.credentialsProvider(CREDENTIALS)
|
||||
.build());
|
||||
|
||||
assertThatThrownBy(() -> openPostgresConnection(USERNAME, token3, togglePort))
|
||||
.isInstanceOf(SQLException.class);
|
||||
} finally {
|
||||
try {
|
||||
rds.deleteDBInstance(DeleteDbInstanceRequest.builder()
|
||||
|
||||
@@ -1523,6 +1523,8 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
}
|
||||
instance.setMasterPassword(newPassword);
|
||||
}
|
||||
boolean iamChanged = iamEnabled != null
|
||||
&& iamEnabled != instance.isIamDatabaseAuthenticationEnabled();
|
||||
if (iamEnabled != null) {
|
||||
instance.setIamDatabaseAuthenticationEnabled(iamEnabled);
|
||||
}
|
||||
@@ -1549,6 +1551,10 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
proxyManager.updateMasterPassword(
|
||||
rdsResourceRelayKey(instance.getDbInstanceArn(), id), instance.getMasterPassword());
|
||||
}
|
||||
if (iamChanged) {
|
||||
proxyManager.updateIamEnabled(
|
||||
rdsResourceRelayKey(instance.getDbInstanceArn(), id), iamEnabled);
|
||||
}
|
||||
|
||||
LOG.infov("DB instance {0} modified", id);
|
||||
return instance;
|
||||
|
||||
@@ -19,7 +19,7 @@ public class RdsAuthProxy {
|
||||
private static final Logger LOG = Logger.getLogger(RdsAuthProxy.class);
|
||||
|
||||
private final int backendPort;
|
||||
private final boolean iamEnabled;
|
||||
private volatile boolean iamEnabled;
|
||||
private final String instanceId;
|
||||
private final String backendHost;
|
||||
private final String masterUsername;
|
||||
@@ -74,6 +74,11 @@ public class RdsAuthProxy {
|
||||
this.masterPassword = newPassword;
|
||||
}
|
||||
|
||||
/** Apply an IAM-auth setting change to new connections without restarting the listener. */
|
||||
public void updateIamEnabled(boolean enabled) {
|
||||
this.iamEnabled = enabled;
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
running = false;
|
||||
try {
|
||||
|
||||
@@ -88,6 +88,14 @@ public class RdsProxyManager {
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void updateIamEnabled(String instanceId, boolean enabled) {
|
||||
RdsAuthProxy proxy = proxies.get(instanceId);
|
||||
if (proxy != null) {
|
||||
proxy.updateIamEnabled(enabled);
|
||||
LOG.infov("Updated RDS proxy IAM authentication for instance {0}", instanceId);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void stopProxy(String instanceId) {
|
||||
RdsAuthProxy proxy = proxies.get(instanceId);
|
||||
if (proxy != null) {
|
||||
|
||||
@@ -1135,6 +1135,9 @@ class RdsServiceTest {
|
||||
|
||||
assertEquals("original-password", modified.getMasterPassword());
|
||||
assertTrue(modified.isIamDatabaseAuthenticationEnabled());
|
||||
verify(proxyManager).updateIamEnabled(anyString(), eq(true));
|
||||
verify(proxyManager, never()).updateMasterPassword(anyString(), anyString());
|
||||
verify(proxyManager, never()).stopProxy(anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in new issue
Block a user