mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(rds): preserve aurora engine identity in parameter group names and managed secrets (#1920)
Aurora instances already round-trip their engine string correctly in DescribeDBInstances/DescribeDBClusters via the existing engineIdentifier field (#1829), but two other places still derived the engine string from the DatabaseEngine enum (which only distinguishes postgres/mysql/mariadb, not their Aurora variants): the default DBParameterGroupName and the managed master-user secret's "engine" field. Both now prefer engineIdentifier, matching the pattern already used for the Engine XML element. Also fixes the default DBParameterGroupName's version suffix to use major.minor for the MySQL family (default.aurora-mysql8.0) instead of always truncating to the major version alone (which is only correct for the Postgres family, e.g. default.aurora-postgresql16) - a pre-existing bug newly reachable now that Aurora MySQL instances get a distinct, correctly-hyphenated prefix. Rejects the bare legacy "aurora" engine identifier instead of silently mapping it to aurora-mysql: AWS retired that identifier in Feb 2023 and now rejects it with InvalidParameterValue for new instances/clusters. Fixes #1918. Co-authored-by: Priamo <pgermosen@gmail.com>
This commit is contained in:
1 parent
a9df872956
commit
5719e65c3c
4 files changed
+72
-9
No files matched your search
@@ -1376,16 +1376,19 @@ public class RdsQueryHandler {
|
||||
return name;
|
||||
}
|
||||
|
||||
String engine = instance.getEngine() != null
|
||||
? instance.getEngine().name().toLowerCase()
|
||||
: "unknown";
|
||||
return "default." + engine + dbEngineMajorVersion(instance);
|
||||
String engine = instanceEngine(instance);
|
||||
return "default." + (engine.isEmpty() ? "unknown" : engine) + dbEngineMajorVersion(instance, engine);
|
||||
}
|
||||
|
||||
private static String dbEngineMajorVersion(DbInstance instance) {
|
||||
/**
|
||||
* AWS uses major.minor for the MySQL family's default parameter group name
|
||||
* (e.g. {@code default.aurora-mysql8.0}), but only the major version for the
|
||||
* Postgres family ({@code default.aurora-postgresql16}).
|
||||
*/
|
||||
private static String dbEngineMajorVersion(DbInstance instance, String engine) {
|
||||
String engineVersion = instance.getEngineVersion();
|
||||
if ((engineVersion == null || engineVersion.isBlank()) && instance.getEngine() != null) {
|
||||
engineVersion = defaultEngineVersion(instance.getEngine().name());
|
||||
engineVersion = defaultEngineVersion(engine);
|
||||
}
|
||||
if (engineVersion == null || engineVersion.isBlank()) {
|
||||
return "";
|
||||
@@ -1396,7 +1399,18 @@ public class RdsQueryHandler {
|
||||
while (end < trimmed.length() && Character.isDigit(trimmed.charAt(end))) {
|
||||
end++;
|
||||
}
|
||||
return end == 0 ? "" : trimmed.substring(0, end);
|
||||
if (end == 0) {
|
||||
return "";
|
||||
}
|
||||
boolean majorMinor = engine.contains("mysql") || engine.equals("mariadb");
|
||||
if (!majorMinor || end >= trimmed.length() || trimmed.charAt(end) != '.') {
|
||||
return trimmed.substring(0, end);
|
||||
}
|
||||
int minorEnd = end + 1;
|
||||
while (minorEnd < trimmed.length() && Character.isDigit(trimmed.charAt(minorEnd))) {
|
||||
minorEnd++;
|
||||
}
|
||||
return minorEnd == end + 1 ? trimmed.substring(0, end) : trimmed.substring(0, minorEnd);
|
||||
}
|
||||
|
||||
private static void writeTags(XmlBuilder xml, Map<String, String> tags) {
|
||||
|
||||
@@ -958,7 +958,9 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
return JSON.writeValueAsString(Map.of(
|
||||
"username", instance.getMasterUsername(),
|
||||
"password", instance.getMasterPassword(),
|
||||
"engine", instance.getEngine().name().toLowerCase(),
|
||||
"engine", instance.getEngineIdentifier() != null && !instance.getEngineIdentifier().isBlank()
|
||||
? instance.getEngineIdentifier().toLowerCase()
|
||||
: instance.getEngine().name().toLowerCase(),
|
||||
"host", instance.getEndpoint().address(),
|
||||
"port", instance.getEndpoint().port(),
|
||||
"dbname", instance.getDbName() == null ? "" : instance.getDbName(),
|
||||
@@ -3226,7 +3228,11 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
}
|
||||
return switch (engineParam.toLowerCase()) {
|
||||
case "postgres", "aurora-postgresql" -> DatabaseEngine.POSTGRES;
|
||||
case "mysql", "aurora-mysql", "aurora" -> DatabaseEngine.MYSQL;
|
||||
// "aurora" (bare) is the legacy Aurora MySQL 5.6 identifier, which reached
|
||||
// end of life in February 2023; real AWS no longer accepts it for new
|
||||
// clusters and rejects it with InvalidParameterValue, so it falls through
|
||||
// to the default case below instead of silently becoming aurora-mysql.
|
||||
case "mysql", "aurora-mysql" -> DatabaseEngine.MYSQL;
|
||||
case "mariadb" -> DatabaseEngine.MARIADB;
|
||||
default -> throw new AwsException("InvalidParameterValue", invalidParameterValueMessage(), 400);
|
||||
};
|
||||
|
||||
@@ -98,6 +98,37 @@ class RdsQueryHandlerTest {
|
||||
assertTrue(body.contains("<ParameterApplyStatus>in-sync</ParameterApplyStatus>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeDbInstances_defaultParameterGroupNameUsesHyphenAndMajorOnlyForAuroraPostgresql() {
|
||||
DbInstance instance = makeInstance("aurora-pg");
|
||||
instance.setEngine(io.github.hectorvent.floci.services.rds.model.DatabaseEngine.POSTGRES);
|
||||
instance.setEngineIdentifier("aurora-postgresql");
|
||||
instance.setEngineVersion("16.3");
|
||||
when(service.listDbInstances(null, null)).thenReturn(List.of(instance));
|
||||
|
||||
Response response = handler.handle("DescribeDBInstances", params());
|
||||
|
||||
String body = (String) response.getEntity();
|
||||
assertTrue(body.contains("<DBParameterGroupName>default.aurora-postgresql16</DBParameterGroupName>"),
|
||||
"Expected hyphenated aurora-postgresql with major-only version, got: " + body);
|
||||
assertFalse(body.contains("aurora_postgresql"), "Parameter group name must not contain underscores");
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeDbInstances_defaultParameterGroupNameUsesMajorMinorForAuroraMysql() {
|
||||
DbInstance instance = makeInstance("aurora-my");
|
||||
instance.setEngine(io.github.hectorvent.floci.services.rds.model.DatabaseEngine.MYSQL);
|
||||
instance.setEngineIdentifier("aurora-mysql");
|
||||
instance.setEngineVersion("8.0.36");
|
||||
when(service.listDbInstances(null, null)).thenReturn(List.of(instance));
|
||||
|
||||
Response response = handler.handle("DescribeDBInstances", params());
|
||||
|
||||
String body = (String) response.getEntity();
|
||||
assertTrue(body.contains("<DBParameterGroupName>default.aurora-mysql8.0</DBParameterGroupName>"),
|
||||
"AWS uses major.minor for the MySQL family, got: " + body);
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeDbInstances_filterByDirectIdentifier() {
|
||||
DbInstance instance = makeInstance("mydb");
|
||||
|
||||
@@ -171,6 +171,18 @@ class RdsServiceTest {
|
||||
assertEquals("arn:aws:rds:us-east-1:123456789012:db:mydb", instance.getDbInstanceArn());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createDbInstanceRejectsLegacyBareAuroraEngine() {
|
||||
// "aurora" (bare) is the retired Aurora MySQL 5.6 identifier; real AWS no
|
||||
// longer accepts it for new instances/clusters and rejects it outright
|
||||
// rather than silently treating it as aurora-mysql.
|
||||
AwsException invalidEngine = assertThrows(AwsException.class, () ->
|
||||
rdsService.createDbInstance("mydb", "aurora", "13",
|
||||
"admin", "password", "dbname", "db.t3.micro",
|
||||
20, false, null, null, null, null, false));
|
||||
assertEquals("InvalidParameterValue", invalidEngine.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createAndModifyDbInstancePersistVpcSecurityGroups() {
|
||||
DbInstance instance = rdsService.createDbInstance("mydb", "postgres", "13",
|
||||
|
||||
Reference in new issue
Block a user