mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(rds): register instances before starting auth proxy (#3467)
* fix(rds): register instances before starting auth proxy * fix(rds): keep provisioning instances in creating state --------- Co-authored-by: xujiantop-crypto <265865031+xujiantop-crypto@users.noreply.github.com>
This commit is contained in:
1 parent
01ec7af8d5
commit
34efd8957a
2 files changed
+55
-9
No files matched your search
@@ -661,7 +661,7 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
|
||||
DbEndpoint endpoint = mock ? new DbEndpoint("localhost", proxyPort) : proxyEndpoint(proxyPort);
|
||||
DbInstance instance = new DbInstance(id, engine, engineVersion, masterUsername, masterPassword,
|
||||
dbName, dbInstanceClass, allocatedStorage, DbInstanceStatus.AVAILABLE,
|
||||
dbName, dbInstanceClass, allocatedStorage, DbInstanceStatus.CREATING,
|
||||
endpoint, iamEnabled, paramGroupName, dbClusterIdentifier, Instant.now(), proxyPort);
|
||||
instance.setOptionGroupName(optionGroupName);
|
||||
instance.setDbSubnetGroupName(dbSubnetGroupName);
|
||||
@@ -688,15 +688,26 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
attachManagedMasterUserSecret(instance, effectiveRegion, masterUserSecretKmsKeyId);
|
||||
}
|
||||
|
||||
String accountId = accountIdFromArn(instance.getDbInstanceArn());
|
||||
putInstanceForScope(accountId, effectiveRegion, id, instance);
|
||||
|
||||
if (!mock && hasBackend(backendHost, backendPort)) {
|
||||
final String accountId = accountIdFromArn(instance.getDbInstanceArn());
|
||||
final String instanceRegion = regionFromArn(instance.getDbInstanceArn());
|
||||
proxyManager.startProxy(rdsResourceRelayKey(instance.getDbInstanceArn(), id),
|
||||
engine, iamEnabled, proxyPort, backendHost, backendPort,
|
||||
instance.getEndpoint().address(),
|
||||
masterUsername, masterPassword, dbName,
|
||||
(user, pw) -> validateDbPasswordForScope(
|
||||
accountId, instanceRegion, id, user, pw));
|
||||
try {
|
||||
proxyManager.startProxy(rdsResourceRelayKey(instance.getDbInstanceArn(), id),
|
||||
engine, iamEnabled, proxyPort, backendHost, backendPort,
|
||||
instance.getEndpoint().address(),
|
||||
masterUsername, masterPassword, dbName,
|
||||
(user, pw) -> validateDbPasswordForScope(
|
||||
accountId, instanceRegion, id, user, pw));
|
||||
} catch (RuntimeException | Error e) {
|
||||
try {
|
||||
deleteInstanceForScope(accountId, effectiveRegion, id);
|
||||
} catch (RuntimeException rollbackFailure) {
|
||||
e.addSuppressed(rollbackFailure);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
if (dbClusterIdentifier != null && !dbClusterIdentifier.isBlank()) {
|
||||
@@ -709,7 +720,8 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
}
|
||||
}
|
||||
|
||||
putInstanceForScope(currentAccountId(), effectiveRegion, id, instance);
|
||||
instance.setStatus(DbInstanceStatus.AVAILABLE);
|
||||
putInstanceForScope(accountId, effectiveRegion, id, instance);
|
||||
LOG.infov("DB instance {0} created, engine={1}, endpoint={2}:{3}",
|
||||
id, engine, endpoint.address(), String.valueOf(endpoint.port()));
|
||||
return instance;
|
||||
|
||||
@@ -171,6 +171,40 @@ class RdsServiceTest {
|
||||
assertEquals("arn:aws:rds:us-east-1:123456789012:db:mydb", instance.getDbInstanceArn());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createDbInstanceMakesRequestedPasswordValidBeforeProxyStartsAcceptingConnections() {
|
||||
doAnswer(invocation -> {
|
||||
assertEquals(DbInstanceStatus.CREATING,
|
||||
rdsService.getDbInstance("mypostgres").getStatus());
|
||||
RdsAuthProxy.MasterPasswordCheck passwordCheck = invocation.getArgument(10);
|
||||
assertTrue(passwordCheck.validate("admin", "secret123"));
|
||||
assertFalse(passwordCheck.validate("admin", "wrong"));
|
||||
return null;
|
||||
}).when(proxyManager).startProxy(any(), any(), anyBoolean(), anyInt(), any(), anyInt(),
|
||||
any(), any(), any(), any(), any());
|
||||
|
||||
DbInstance instance = rdsService.createDbInstance("mypostgres", "postgres", "13",
|
||||
"admin", "secret123", null, "db.t3.micro",
|
||||
20, false, null, null, null, null, false);
|
||||
|
||||
assertEquals(DbInstanceStatus.AVAILABLE, instance.getStatus());
|
||||
assertEquals(DbInstanceStatus.AVAILABLE,
|
||||
rdsService.getDbInstance("mypostgres").getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createDbInstanceRemovesVisibleRecordWhenProxyStartupFails() {
|
||||
doThrow(new IllegalStateException("proxy down"))
|
||||
.when(proxyManager).startProxy(any(), any(), anyBoolean(), anyInt(), any(), anyInt(),
|
||||
any(), any(), any(), any(), any());
|
||||
|
||||
assertThrows(IllegalStateException.class, () -> rdsService.createDbInstance(
|
||||
"mypostgres", "postgres", "13",
|
||||
"admin", "secret123", null, "db.t3.micro",
|
||||
20, false, null, null, null, null, false));
|
||||
assertThrows(AwsException.class, () -> rdsService.getDbInstance("mypostgres"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createDbInstanceRejectsLegacyBareAuroraEngine() {
|
||||
// "aurora" (bare) is the retired Aurora MySQL 5.6 identifier; real AWS no
|
||||
|
||||
Reference in new issue
Block a user