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

@@ -85,7 +85,7 @@ final class RdsEngineCatalog {
private static final Map<String, List<String>> FEATURE_NAMES = Map.of(
"postgres", List.of("s3Import", "s3Export", "Lambda"),
"sqlserver-se", List.of("S3_INTEGRATION"),
"aurora-postgresql", List.of("s3Import", "s3Export", "Lambda", "Comprehend", "SageMaker"));
"aurora-postgresql", List.of("s3Import", "s3Export", "Lambda", "Comprehend", "SageMaker", "Bedrock"));
static List<String> exportableLogTypes(EngineVersion version) {
return EXPORTABLE_LOG_TYPES.getOrDefault(version.engine(), List.of());
@@ -95,6 +95,26 @@ final class RdsEngineCatalog {
return FEATURE_NAMES.getOrDefault(version.engine(), List.of());
}
/**
* The role feature names an engine supports, or null when the catalogue does not list the
* engine. {@code aurora} is Aurora MySQL's older name, and the SQL Server editions (or the bare
* {@code sqlserver} older state records) share one entry.
*/
static List<String> featureNamesForEngine(String engine) {
if (engine == null) {
return null;
}
String catalogued = switch (engine.toLowerCase(Locale.ROOT)) {
case "aurora" -> "aurora-mysql";
case "sqlserver", "sqlserver-ee", "sqlserver-ex", "sqlserver-web" -> "sqlserver-se";
default -> engine.toLowerCase(Locale.ROOT);
};
if (VERSIONS.stream().noneMatch(v -> v.engine().equals(catalogued))) {
return null;
}
return FEATURE_NAMES.getOrDefault(catalogued, List.of());
}
/** Floci creates read replicas of PostgreSQL instances only. */
static boolean supportsReadReplica(EngineVersion version) {
return version.engine().equals("postgres");
@@ -1179,7 +1179,7 @@ public class RdsQueryHandler {
try {
List<DbRoleAssociation> associatedRoles = parseAssociatedRoles(params);
service.validateClusterRoleAssociations(id, associatedRoles);
service.validateClusterRoleAssociations(id, engine, associatedRoles);
Double serverlessV2Min = parseDoubleParam(params, "ServerlessV2ScalingConfiguration.MinCapacity");
Double serverlessV2Max = parseDoubleParam(params, "ServerlessV2ScalingConfiguration.MaxCapacity");
Integer serverlessV2SecondsUntilAutoPause = parseIntegerParam(
@@ -9743,6 +9743,7 @@ public class RdsService implements Resettable, ResourceProvider {
String effectiveRegion = effectiveRegion(region);
DbCluster cluster = getDbCluster(clusterId, effectiveRegion);
requireAvailableCluster(cluster, clusterId);
requireSupportedFeature(engineName(cluster), featureName);
requireRoleNotAssociated(cluster, clusterId, roleArn);
cluster.getAssociatedRoles().add(new DbRoleAssociation(roleArn, blankToNull(featureName)));
putClusterForScope(currentAccountId(), effectiveRegion, clusterId, cluster);
@@ -9761,6 +9762,7 @@ public class RdsService implements Resettable, ResourceProvider {
DbCluster cluster = getDbCluster(clusterId, effectiveRegion);
requireAvailableCluster(cluster, clusterId);
for (DbRoleAssociation role : roles) {
requireSupportedFeature(engineName(cluster), role.getFeatureName());
requireRoleNotAssociated(cluster, clusterId, role.getRoleArn());
}
for (DbRoleAssociation role : roles) {
@@ -9793,7 +9795,7 @@ public class RdsService implements Resettable, ResourceProvider {
requireAvailableCluster(cluster, clusterId);
String feature = blankToNull(featureName);
boolean removed = cluster.getAssociatedRoles().removeIf(existing -> existing.getRoleArn().equals(roleArn)
&& (feature == null || feature.equals(existing.getFeatureName())));
&& (feature == null || feature.equalsIgnoreCase(existing.getFeatureName())));
if (!removed) {
throw new AwsException("DBClusterRoleNotFound", "Role ARN " + roleArn
+ (feature == null ? "" : " for feature " + feature)
@@ -9816,8 +9818,9 @@ public class RdsService implements Resettable, ResourceProvider {
String effectiveRegion = effectiveRegion(region);
DbInstance instance = getDbInstance(instanceId, effectiveRegion);
requireAvailableInstance(instance, instanceId);
requireSupportedFeature(engineName(instance), featureName);
for (DbRoleAssociation existing : instance.getAssociatedRoles()) {
if (existing.getRoleArn().equals(roleArn) || featureName.equals(existing.getFeatureName())) {
if (existing.getRoleArn().equals(roleArn) || featureName.equalsIgnoreCase(existing.getFeatureName())) {
throw new AwsException("DBInstanceRoleAlreadyExists", "Role ARN " + existing.getRoleArn()
+ " is already associated with DB instance " + instanceId + " for feature "
+ existing.getFeatureName() + ".", 400);
@@ -9839,7 +9842,7 @@ public class RdsService implements Resettable, ResourceProvider {
DbInstance instance = getDbInstance(instanceId, effectiveRegion);
requireAvailableInstance(instance, instanceId);
boolean removed = instance.getAssociatedRoles().removeIf(existing -> existing.getRoleArn().equals(roleArn)
&& featureName.equals(existing.getFeatureName()));
&& featureName.equalsIgnoreCase(existing.getFeatureName()));
if (!removed) {
throw new AwsException("DBInstanceRoleNotFound", "Role ARN " + roleArn
+ " is not associated with DB instance " + instanceId + " for feature " + featureName + ".", 404);
@@ -9852,12 +9855,17 @@ public class RdsService implements Resettable, ResourceProvider {
/**
* Checks the roles a {@code CreateDBCluster} request names before the cluster exists, by the
* rules {@link #addRoleToDbCluster} applies one at a time, so a list that would be refused part
* way through refuses the create instead of leaving a cluster with half its roles.
* way through refuses the create instead of leaving a cluster with half its roles. The feature
* names are checked against {@code engine} when the request names one; a create that takes its
* engine from a global cluster has them checked once the cluster exists.
*/
public void validateClusterRoleAssociations(String clusterId, List<DbRoleAssociation> roles) {
public void validateClusterRoleAssociations(String clusterId, String engine, List<DbRoleAssociation> roles) {
Set<String> roleArns = new HashSet<>();
for (DbRoleAssociation role : roles) {
requireParameter(role.getRoleArn(), "AssociatedRoles.RoleArn");
if (!isBlank(engine)) {
requireSupportedFeature(engine, role.getFeatureName());
}
if (!roleArns.add(role.getRoleArn())) {
throw new AwsException("DBClusterRoleAlreadyExists", "Role ARN " + role.getRoleArn()
+ " is named more than once for DB cluster " + clusterId + ".", 400);
@@ -9869,6 +9877,35 @@ public class RdsService implements Resettable, ResourceProvider {
return isBlank(value) ? null : value;
}
/**
* Refuses a feature name the engine's {@code SupportedFeatureNames} does not list, matched
* without regard to case. No feature name (a cluster role may have none) and an engine the
* catalogue does not list pass, so Floci never refuses a feature it cannot judge.
*/
private static void requireSupportedFeature(String engine, String featureName) {
if (isBlank(featureName)) {
return;
}
List<String> supported = RdsEngineCatalog.featureNamesForEngine(engine);
if (supported == null || supported.stream().anyMatch(name -> name.equalsIgnoreCase(featureName))) {
return;
}
throw new AwsException("InvalidParameterValue", "The feature " + featureName
+ " is not supported for engine " + engine.toLowerCase(Locale.ROOT) + ". Supported features: "
+ (supported.isEmpty() ? "none" : String.join(", ", supported)) + ".", 400);
}
/** The engine name the request gave, or the engine's own name for state recorded without one. */
private static String engineName(DbCluster cluster) {
return !isBlank(cluster.getEngineIdentifier()) ? cluster.getEngineIdentifier()
: cluster.getEngine() != null ? cluster.getEngine().name() : null;
}
private static String engineName(DbInstance instance) {
return !isBlank(instance.getEngineIdentifier()) ? instance.getEngineIdentifier()
: instance.getEngine() != null ? instance.getEngine().name() : null;
}
private static void requireParameter(String value, String name) {
if (isBlank(value)) {
throw new AwsException("MissingParameter", "The request must contain the parameter " + name + ".", 400);