mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 14:10:49 -05:00
fix(docdb): refuse an engine version a live account does not list (#2682)
* fix(docdb): refuse an engine version a live account does not list CreateDBCluster and ModifyDBCluster derived a parameter group family from any engine version string and assigned "default.<family>" without checking that the family exists. The versions a live account lists for docdb are now the catalogue: 3.6.0, 4.0.0, 5.0.0, 5.0.1, 8.0.0, 8.0.1 and the major.minor form of one; anything else is refused before any change with "Cannot find version X for docdb". default.docdb8.0 joins the managed cluster parameter groups. Closes #2681 * test(docdb): refuse an unlisted engine version through the CLI
This commit is contained in:
1 parent
6c96f47f73
commit
46d2f4e70f
7 files changed
+84
-10
No files matched your search
@@ -220,6 +220,19 @@ teardown() {
|
||||
aws_cmd ec2 delete-vpc --vpc-id "$VPC_ID" >/dev/null 2>&1 || true
|
||||
}
|
||||
|
||||
@test "docdb: an engine version a live account does not list is refused" {
|
||||
CLUSTER_ID="bats-docdb-version-$(unique_name)"
|
||||
run aws_cmd docdb create-db-cluster --db-cluster-identifier "$CLUSTER_ID" --engine docdb \
|
||||
--engine-version 9.9.9 --master-username u --master-user-password pw12345678
|
||||
assert_failure
|
||||
assert_output --partial 'InvalidParameterCombination'
|
||||
assert_output --partial 'Cannot find version 9.9.9 for docdb'
|
||||
|
||||
run aws_cmd docdb describe-db-clusters --db-cluster-identifier "$CLUSTER_ID"
|
||||
assert_failure
|
||||
assert_output --partial 'DBClusterNotFoundFault'
|
||||
}
|
||||
|
||||
@test "docdb: cluster settings given on create are returned by describe" {
|
||||
CLUSTER_ID="bats-docdb-settings-$(unique_name)"
|
||||
run aws_cmd kms create-key --description "$CLUSTER_ID"
|
||||
|
||||
@@ -43,7 +43,9 @@ and so are the windows (30-minute minimum, no overlap). Omitted values take the
|
||||
`default`, `default.docdb<family>`, the VPC's default security group, one day of backups — with
|
||||
deterministic windows `04:00-06:00` / `mon:00:00-mon:03:00` where AWS picks random ones.
|
||||
`CreateDBInstance` keeps `AutoMinorVersionUpgrade`, `PreferredMaintenanceWindow`,
|
||||
`CopyTagsToSnapshot`, `PromotionTier` and `Tags`.
|
||||
`CopyTagsToSnapshot`, `PromotionTier` and `Tags`. `EngineVersion` must be one a live account lists
|
||||
(`3.6.0`, `4.0.0`, `5.0.0`, `5.0.1`, `8.0.0`, `8.0.1`, or the `major.minor` form of one); any other
|
||||
is refused with `Cannot find version X for docdb`, on create and on modify.
|
||||
|
||||
## Configuration
|
||||
|
||||
|
||||
@@ -40,6 +40,15 @@ public class DocDbService {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(DocDbService.class);
|
||||
private static final String ENGINE_VERSION_DEFAULT = "5.0.0";
|
||||
|
||||
/** The engine versions a live account lists for docdb, each with its parameter group family. */
|
||||
static final Map<String, String> ENGINE_VERSION_FAMILIES = Map.of(
|
||||
"3.6.0", "docdb3.6",
|
||||
"4.0.0", "docdb4.0",
|
||||
"5.0.0", "docdb5.0",
|
||||
"5.0.1", "docdb5.0",
|
||||
"8.0.0", "docdb8.0",
|
||||
"8.0.1", "docdb8.0");
|
||||
private static final int MONGO_PORT = 27017;
|
||||
|
||||
private final StorageBackend<String, DocDbCluster> clusters;
|
||||
@@ -195,7 +204,7 @@ public class DocDbService {
|
||||
Map<String, String> tags) {
|
||||
String region = regionResolver.getRegion();
|
||||
settings.validate();
|
||||
String effectiveEngineVersion = engineVersion != null ? engineVersion : ENGINE_VERSION_DEFAULT;
|
||||
String effectiveEngineVersion = requireKnownEngineVersion(engineVersion);
|
||||
// every reference checked and every default chosen before a container is started
|
||||
DocDbClusterSettings resolved = resolveClusterSettings(settings, null, effectiveEngineVersion, region);
|
||||
synchronized (lockFor("cluster:" + key(region, id))) {
|
||||
@@ -207,7 +216,7 @@ public class DocDbService {
|
||||
DocDbCluster cluster = new DocDbCluster();
|
||||
cluster.setDbClusterIdentifier(id);
|
||||
cluster.setStatus("available");
|
||||
cluster.setEngineVersion(engineVersion != null ? engineVersion : ENGINE_VERSION_DEFAULT);
|
||||
cluster.setEngineVersion(effectiveEngineVersion);
|
||||
cluster.setMasterUsername(masterUsername);
|
||||
cluster.setIamDatabaseAuthenticationEnabled(iamEnabled);
|
||||
cluster.setDbClusterArn(regionResolver.buildArn("rds", region, "cluster:" + id));
|
||||
@@ -388,9 +397,33 @@ public class DocDbService {
|
||||
}
|
||||
}
|
||||
|
||||
/** The parameter group family an engine version belongs to: {@code 5.0.0} is {@code docdb5.0}. */
|
||||
/**
|
||||
* The version a request names, refused as a live account refuses one it does not list. The
|
||||
* {@code major.minor} form of a listed version is accepted as given.
|
||||
*/
|
||||
static String requireKnownEngineVersion(String engineVersion) {
|
||||
if (engineVersion == null || engineVersion.isBlank()) {
|
||||
return ENGINE_VERSION_DEFAULT;
|
||||
}
|
||||
if (ENGINE_VERSION_FAMILIES.containsKey(engineVersion)
|
||||
|| ENGINE_VERSION_FAMILIES.containsValue("docdb" + engineVersion)) {
|
||||
return engineVersion;
|
||||
}
|
||||
throw new AwsException("InvalidParameterCombination",
|
||||
"Cannot find version " + engineVersion + " for docdb", 400);
|
||||
}
|
||||
|
||||
/**
|
||||
* The parameter group family an engine version belongs to: {@code 5.0.0} is {@code docdb5.0}.
|
||||
* A version outside the catalogue can only come from a record persisted before versions were
|
||||
* checked; its family is still derived so the record keeps describing the way it always has.
|
||||
*/
|
||||
static String parameterGroupFamily(String engineVersion) {
|
||||
String version = engineVersion == null || engineVersion.isBlank() ? ENGINE_VERSION_DEFAULT : engineVersion;
|
||||
String known = ENGINE_VERSION_FAMILIES.get(version);
|
||||
if (known != null) {
|
||||
return known;
|
||||
}
|
||||
String[] parts = version.split("\\.");
|
||||
return "docdb" + parts[0] + "." + (parts.length > 1 ? parts[1] : "0");
|
||||
}
|
||||
@@ -573,7 +606,7 @@ public class DocDbService {
|
||||
DocDbCluster cluster = getDbCluster(id);
|
||||
// every check before any change: the store hands out its own object
|
||||
String effectiveEngineVersion = engineVersion != null && !engineVersion.isBlank()
|
||||
? engineVersion : cluster.getEngineVersion();
|
||||
? requireKnownEngineVersion(engineVersion) : cluster.getEngineVersion();
|
||||
DocDbClusterSettings resolved = resolveClusterSettings(settings, cluster, effectiveEngineVersion, region);
|
||||
cluster.setEngineVersion(effectiveEngineVersion);
|
||||
if (iamEnabled != null) {
|
||||
|
||||
@@ -95,7 +95,8 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
// versions map to); DocDbService validates a cluster's parameter group here
|
||||
managedDefault("docdb3.6"),
|
||||
managedDefault("docdb4.0"),
|
||||
managedDefault("docdb5.0"));
|
||||
managedDefault("docdb5.0"),
|
||||
managedDefault("docdb8.0"));
|
||||
|
||||
/**
|
||||
* Engines AWS accepts for {@code EngineName} on an option group. Floci can only run
|
||||
|
||||
@@ -117,12 +117,12 @@ class DocDbIntegrationTest {
|
||||
.contentType(FORM)
|
||||
.formParam("Action", "ModifyDBCluster")
|
||||
.formParam("DBClusterIdentifier", CLUSTER_ID)
|
||||
.formParam("EngineVersion", "6.0.0")
|
||||
.formParam("EngineVersion", "8.0.0")
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString(CLUSTER_ID))
|
||||
.body(containsString("6.0.0"));
|
||||
.body(containsString("8.0.0"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -67,7 +67,7 @@ class DocDbServiceTest {
|
||||
kmsService = Mockito.mock(KmsService.class);
|
||||
when(kmsService.describeKey(any(), any())).thenThrow(new AwsException("NotFoundException", "Key not found", 404));
|
||||
when(rdsService.isManagedClusterParameterGroup(any())).thenAnswer(inv ->
|
||||
List.of("default.docdb3.6", "default.docdb4.0", "default.docdb5.0").contains(inv.<String>getArgument(0)));
|
||||
List.of("default.docdb3.6", "default.docdb4.0", "default.docdb5.0", "default.docdb8.0").contains(inv.<String>getArgument(0)));
|
||||
docDbService = new DocDbService(config, regionResolver, containerManager, storageFactory,
|
||||
rdsService, ec2Service, kmsService);
|
||||
}
|
||||
@@ -459,6 +459,30 @@ class DocDbServiceTest {
|
||||
assertFalse(BackupWindows.overlap(stored.getPreferredBackupWindow(), stored.getPreferredMaintenanceWindow()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void engineVersionsOutsideTheCatalogueAreRefusedBeforeAnythingChanges() {
|
||||
for (String version : List.of("9.9.9", "5", "abc", "5.0.2")) {
|
||||
AwsException e = assertThrows(AwsException.class, () -> docDbService.createDbCluster(
|
||||
"c1", version, "u", "pw", false, DocDbClusterSettings.unchanged(), Map.of()));
|
||||
assertEquals("InvalidParameterCombination", e.getErrorCode());
|
||||
assertEquals("Cannot find version " + version + " for docdb", e.getMessage());
|
||||
assertThrows(AwsException.class, () -> docDbService.getDbCluster("c1"));
|
||||
}
|
||||
|
||||
docDbService.createDbCluster("c1", "8.0.1", "u", "pw", false);
|
||||
assertEquals("default.docdb8.0", docDbService.getDbCluster("c1").getDbClusterParameterGroupName());
|
||||
docDbService.createDbCluster("c2", "5.0", "u", "pw", false);
|
||||
assertEquals("5.0", docDbService.getDbCluster("c2").getEngineVersion());
|
||||
assertEquals("default.docdb5.0", docDbService.getDbCluster("c2").getDbClusterParameterGroupName());
|
||||
docDbService.createDbCluster("c3", null, "u", "pw", false);
|
||||
assertEquals("5.0.0", docDbService.getDbCluster("c3").getEngineVersion());
|
||||
|
||||
AwsException e = assertThrows(AwsException.class, () -> docDbService.modifyDbCluster("c1", "9.9.9", null));
|
||||
assertEquals("Cannot find version 9.9.9 for docdb", e.getMessage());
|
||||
assertEquals("8.0.1", docDbService.getDbCluster("c1").getEngineVersion());
|
||||
assertEquals("default.docdb8.0", docDbService.getDbCluster("c1").getDbClusterParameterGroupName());
|
||||
}
|
||||
|
||||
private AwsException refused(DocDbClusterSettings settings) {
|
||||
return assertThrows(AwsException.class, () -> docDbService.createDbCluster(
|
||||
"c1", "5.0.0", "u", "pw", false, settings, Map.of()));
|
||||
|
||||
@@ -96,7 +96,8 @@ class RdsServiceTest {
|
||||
"postgres18",
|
||||
"docdb3.6",
|
||||
"docdb4.0",
|
||||
"docdb5.0");
|
||||
"docdb5.0",
|
||||
"docdb8.0");
|
||||
|
||||
private RdsService rdsService;
|
||||
private RdsContainerManager containerManager;
|
||||
|
||||
Reference in new issue
Block a user