feat(rds): refuse role feature names the engine does not support (#5637)

* feat(rds): refuse role feature names the engine does not support

AddRoleToDBInstance, AddRoleToDBCluster and CreateDBCluster
AssociatedRoles stored any FeatureName, so Lambda on a MySQL instance
was accepted although MySQL supports no role features.

A FeatureName now has to be one the engine lists in
SupportedFeatureNames, matched without regard to case, or the call is
InvalidParameterValue; CreateDBCluster refuses before any cluster
exists. A cluster role with no feature, and an engine the catalogue
does not list, are left alone. Aurora PostgreSQL also lists Bedrock,
which the Aurora user guide offers next to Comprehend and SageMaker.

Closes #5631

* refactor(rds): keep the two-argument cluster role check

Callers that check an AssociatedRoles list without knowing the engine,
such as the CloudFormation provisioner in #5656, keep the signature they
compile against; it runs the same checks without the feature check.

* fix(rds): match feature names without regard to case in every role check

The supported-feature check matched without regard to case, but the
instance duplicate check and both removal lookups compared exactly, so
an instance could take s3Import and then s3import as two roles. All of
them now match the same way. The two-argument cluster role check, which
nothing here calls, is removed.
This commit is contained in:
David authored and GitHub committed 2026-10-14 16:59:28 -04:00
1 parent a5228a0bf7
commit ff32bae98c
8 files changed
+250 -10

No files matched your search

@@ -102,6 +102,11 @@ class RdsCatalogueReadIntegrationTest {
.body(VERSIONS + ".SupportsReadReplica", equalTo("false"))
.body(containsString("<SupportedFeatureNames></SupportedFeatureNames>"))
.body(VERSIONS + ".SupportsGlobalDatabases", equalTo("true"));
query("DescribeDBEngineVersions").formParam("Engine", "aurora-postgresql").formParam("DefaultOnly", "true")
.when().post("/").then()
.statusCode(200)
.body(VERSIONS + ".SupportedFeatureNames.member",
contains("s3Import", "s3Export", "Lambda", "Comprehend", "SageMaker", "Bedrock"));
}
@Test
@@ -0,0 +1,159 @@
package io.github.hectorvent.floci.services.rds;
import io.github.hectorvent.floci.testing.RdsMockProfile;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
import io.restassured.specification.RequestSpecification;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import static io.restassured.RestAssured.given;
import static io.restassured.http.ContentType.URLENC;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
/**
* A role's {@code FeatureName} has to be one the engine lists in {@code SupportedFeatureNames}, on
* {@code AddRoleToDBInstance}, {@code AddRoleToDBCluster} and {@code CreateDBCluster}.
*/
@QuarkusTest
@TestProfile(RdsMockProfile.class)
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class RdsRoleFeatureNameIntegrationTest {
private static final String ROLE = "arn:aws:iam::000000000000:role/rds-feature";
private static final String OTHER_ROLE = "arn:aws:iam::000000000000:role/rds-feature-other";
private static final String AUTH =
"AWS4-HMAC-SHA256 Credential=test/20261014/us-east-1/rds/aws4_request, "
+ "SignedHeaders=content-type;host, Signature=test";
private static RequestSpecification query(String action) {
return given().header("Authorization", AUTH)
.contentType(URLENC)
.formParam("Action", action)
.formParam("Version", "2014-10-31");
}
private static void createInstance(String id, String engine) {
query("CreateDBInstance")
.formParam("DBInstanceIdentifier", id)
.formParam("Engine", engine)
.formParam("DBInstanceClass", "db.t3.micro")
.formParam("MasterUsername", "admin")
.formParam("MasterUserPassword", "password123")
.formParam("AllocatedStorage", "20")
.when().post("/").then().statusCode(200);
}
private static void createCluster(String id, String engine) {
query("CreateDBCluster")
.formParam("DBClusterIdentifier", id)
.formParam("Engine", engine)
.formParam("MasterUsername", "admin")
.formParam("MasterUserPassword", "password123")
.when().post("/").then().statusCode(200);
}
@Test
@Order(1)
void instanceFeatureMustBeOneTheEngineSupports() {
createInstance("feature-mysql", "mysql");
query("AddRoleToDBInstance").formParam("DBInstanceIdentifier", "feature-mysql")
.formParam("RoleArn", ROLE).formParam("FeatureName", "Lambda")
.when().post("/").then().statusCode(400)
.body("ErrorResponse.Error.Code", equalTo("InvalidParameterValue"))
.body("ErrorResponse.Error.Message", containsString("Supported features: none"));
createInstance("feature-postgres", "postgres");
query("AddRoleToDBInstance").formParam("DBInstanceIdentifier", "feature-postgres")
.formParam("RoleArn", ROLE).formParam("FeatureName", "SageMaker")
.when().post("/").then().statusCode(400)
.body("ErrorResponse.Error.Code", equalTo("InvalidParameterValue"))
.body("ErrorResponse.Error.Message", containsString("s3Import, s3Export, Lambda"));
// Matched without regard to case, and kept as the request spelled it.
query("AddRoleToDBInstance").formParam("DBInstanceIdentifier", "feature-postgres")
.formParam("RoleArn", ROLE).formParam("FeatureName", "s3import")
.when().post("/").then().statusCode(200);
query("DescribeDBInstances").formParam("DBInstanceIdentifier", "feature-postgres")
.when().post("/").then().statusCode(200)
.body(containsString("<FeatureName>s3import</FeatureName>"));
}
@Test
@Order(5)
void theOtherFeatureChecksMatchWithoutRegardToCaseToo() {
// feature-postgres holds ROLE for "s3import" (order 1). The same feature in another case is
// the same feature: a second role for it is refused, and it finds the association to remove.
query("AddRoleToDBInstance").formParam("DBInstanceIdentifier", "feature-postgres")
.formParam("RoleArn", OTHER_ROLE).formParam("FeatureName", "s3Import")
.when().post("/").then().statusCode(400)
.body("ErrorResponse.Error.Code", equalTo("DBInstanceRoleAlreadyExists"));
query("RemoveRoleFromDBInstance").formParam("DBInstanceIdentifier", "feature-postgres")
.formParam("RoleArn", ROLE).formParam("FeatureName", "S3IMPORT")
.when().post("/").then().statusCode(200);
// feature-apg holds ROLE for "Bedrock" (order 2); a cluster removal matches it the same way.
query("RemoveRoleFromDBCluster").formParam("DBClusterIdentifier", "feature-apg")
.formParam("RoleArn", ROLE).formParam("FeatureName", "bedrock")
.when().post("/").then().statusCode(200);
}
@Test
@Order(2)
void clusterFeatureMustBeOneTheEngineSupports() {
createCluster("feature-apg", "aurora-postgresql");
query("AddRoleToDBCluster").formParam("DBClusterIdentifier", "feature-apg")
.formParam("RoleArn", ROLE).formParam("FeatureName", "Bedrock")
.when().post("/").then().statusCode(200);
query("AddRoleToDBCluster").formParam("DBClusterIdentifier", "feature-apg")
.formParam("RoleArn", OTHER_ROLE).formParam("FeatureName", "S3_INTEGRATION")
.when().post("/").then().statusCode(400)
.body("ErrorResponse.Error.Code", equalTo("InvalidParameterValue"));
// Aurora MySQL lists no features: its roles take none, and a named one is refused.
createCluster("feature-ams", "aurora-mysql");
query("AddRoleToDBCluster").formParam("DBClusterIdentifier", "feature-ams")
.formParam("RoleArn", ROLE).formParam("FeatureName", "s3Import")
.when().post("/").then().statusCode(400)
.body("ErrorResponse.Error.Code", equalTo("InvalidParameterValue"));
query("AddRoleToDBCluster").formParam("DBClusterIdentifier", "feature-ams")
.formParam("RoleArn", ROLE)
.when().post("/").then().statusCode(200);
}
@Test
@Order(3)
void createDbClusterWithAnUnsupportedFeatureCreatesNothing() {
query("CreateDBCluster")
.formParam("DBClusterIdentifier", "feature-create")
.formParam("Engine", "aurora-mysql")
.formParam("MasterUsername", "admin")
.formParam("MasterUserPassword", "password123")
.formParam("AssociatedRoles.DBClusterAssociatedRole.1.RoleArn", ROLE)
.formParam("AssociatedRoles.DBClusterAssociatedRole.1.FeatureName", "Lambda")
.when().post("/").then().statusCode(400)
.body("ErrorResponse.Error.Code", equalTo("InvalidParameterValue"));
query("DescribeDBClusters").formParam("DBClusterIdentifier", "feature-create")
.when().post("/").then().statusCode(404);
}
@Test
@Order(4)
void createDbClusterWithoutAnEngineChecksTheFeatureOnceTheClusterExists() {
// No Engine means PostgreSQL, which lists no Comprehend: the roles are refused after the
// cluster is made, and the cluster is deleted again.
query("CreateDBCluster")
.formParam("DBClusterIdentifier", "feature-no-engine")
.formParam("MasterUsername", "admin")
.formParam("MasterUserPassword", "password123")
.formParam("AssociatedRoles.DBClusterAssociatedRole.1.RoleArn", ROLE)
.formParam("AssociatedRoles.DBClusterAssociatedRole.1.FeatureName", "Comprehend")
.when().post("/").then().statusCode(400)
.body("ErrorResponse.Error.Code", equalTo("InvalidParameterValue"));
query("DescribeDBClusters").formParam("DBClusterIdentifier", "feature-no-engine")
.when().post("/").then().statusCode(404);
}
}
@@ -2948,6 +2948,17 @@ class RdsServiceTest {
RdsEngineCatalog.VERSIONS.forEach(v -> assertEquals(1L, defaults.get(v.engine()), v.engine()));
}
@Test
void supportedFeatureNamesResolveEngineAliases() {
assertEquals(List.of("S3_INTEGRATION"), RdsEngineCatalog.featureNamesForEngine("sqlserver-ee"));
assertEquals(List.of("S3_INTEGRATION"), RdsEngineCatalog.featureNamesForEngine("SQLSERVER"));
assertEquals(List.of(), RdsEngineCatalog.featureNamesForEngine("aurora"));
assertEquals(List.of("s3Import", "s3Export", "Lambda"), RdsEngineCatalog.featureNamesForEngine("POSTGRES"));
// An engine the catalogue does not list is not judged.
assertNull(RdsEngineCatalog.featureNamesForEngine("oracle-ee"));
assertNull(RdsEngineCatalog.featureNamesForEngine(null));
}
@Test
void engineVersionsSortNumericallyForUpgradeTargets() {
RdsEngineCatalog.EngineVersion pg163 = RdsEngineCatalog.VERSIONS.stream()