Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import software.amazon.awssdk.services.rds.model.OptionSetting;
import software.amazon.awssdk.services.rds.model.RdsException;
import software.amazon.awssdk.services.rds.model.RegisterDbProxyTargetsResponse;
import software.amazon.awssdk.services.rds.model.ResourceNotFoundException;
import software.amazon.awssdk.services.rds.model.Tag;
import software.amazon.awssdk.services.rds.model.UpgradeTarget;
import software.amazon.awssdk.services.rds.model.ValidStorageOptions;
Expand Down Expand Up @@ -764,6 +765,32 @@ void sdkRoundTripsCustomClusterEndpoints() {
}
}

@Test
@DisplayName("Data API endpoint: enable, describe and disable on an Aurora cluster")
void sdkTogglesTheDataApiEndpoint() {
String clusterName = TestFixtures.uniqueName("rds-data-api");
try {
String arn = rds.createDBCluster(b -> b
.dbClusterIdentifier(clusterName)
.engine("aurora-postgresql")
.engineVersion("16.3")
.masterUsername("admin")
.masterUserPassword("data-api-secret")).dbCluster().dbClusterArn();
assertThat(rds.enableHttpEndpoint(b -> b.resourceArn(arn)).httpEndpointEnabled()).isTrue();
assertThat(rds.describeDBClusters(b -> b.dbClusterIdentifier(clusterName))
.dbClusters().get(0).httpEndpointEnabled()).isTrue();
assertThat(rds.disableHttpEndpoint(b -> b.resourceArn(arn)).httpEndpointEnabled()).isFalse();
assertThatThrownBy(() -> rds.enableHttpEndpoint(b -> b.resourceArn(arn + "-missing")))
.isInstanceOf(ResourceNotFoundException.class);
} finally {
try {
rds.deleteDBCluster(b -> b.dbClusterIdentifier(clusterName).skipFinalSnapshot(true));
} catch (Exception e) {
LOG.log(Level.WARNING, "Failed to clean up RDS cluster " + clusterName, e);
}
}
}

@Test
@DisplayName("IAM role associations: add, describe and remove for a cluster and an instance")
void sdkRoundTripsIamRoleAssociations() {
Expand Down
2 changes: 1 addition & 1 deletion docs/services/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Operation counts are exact. For dispatch-table services (Query and JSON 1.1) eac
| [Amazon Data Lifecycle Manager](dlm.md) | `/policies`, `/policies/{policyId}`, `/tags/{resourceArn}` | REST JSON | 8 |
| [ElastiCache](elasticache.md) | `POST /` with `Action=` param + TCP proxy | Query + RESP | 30 |
| [MemoryDB](memorydb.md) | `POST /` + `X-Amz-Target: AmazonMemoryDB.*` + TCP proxy | JSON 1.1 + RESP | 13 |
| [RDS](rds.md) | `POST /` with `Action=` param + TCP proxy | Query + wire | 98 |
| [RDS](rds.md) | `POST /` with `Action=` param + TCP proxy | Query + wire | 100 |
| [RDS Data API](rds-data.md) | `/Execute`, `/BeginTransaction`, `/CommitTransaction`, `/RollbackTransaction` | REST JSON | 4 |
| [Timestream for InfluxDB](timestream-influxdb.md) | `POST /` + `X-Amz-Target: AmazonTimestreamInfluxDB.*` + InfluxDB container | JSON 1.0 + InfluxDB HTTP | 24 |
| [MSK](msk.md) | `/v1/clusters/...`, `/api/v2/clusters/...` + Redpanda broker | REST JSON + Kafka | 8 |
Expand Down
2 changes: 1 addition & 1 deletion docs/services/rds-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ The deprecated `ExecuteSql` operation is recognized at `POST /ExecuteSql` and re
- SQL errors are returned as `DatabaseErrorException` so AWS SDK callers can handle database failures with normal AWS error decoding.
- If `secretArn` points to a local Secrets Manager secret with JSON credentials (`username` or `user`, plus `password`), those credentials are used. A missing or unavailable secret returns `SecretsErrorException`; malformed or incomplete credentials return `InvalidSecretException`. Floci does not fall back to the resolved RDS resource's master credentials when a secret ARN was supplied.
- `formatRecordsAs=JSON`, `formattedRecords`, and `resultSetOptions` are not implemented yet, and `ExecuteStatement` requests asking for those result modes return `BadRequestException`. They are `ExecuteStatement`-only fields in the AWS API, so `BatchExecuteStatement` — whose input is limited to `resourceArn`, `secretArn`, `sql`, `database`, `schema`, `parameterSets`, and `transactionId` — ignores them as AWS does rather than rejecting them.
- RDS `HttpEndpointEnabled` control-plane gating is not modeled locally; availability is controlled by `FLOCI_SERVICES_RDS_DATA_ENABLED` and whether the target local RDS resource is running.
- RDS records a cluster's `HttpEndpointEnabled` (`EnableHttpEndpoint` / `DisableHttpEndpoint`, see [RDS](rds.md#data-api-endpoint)), but the Data API does not check it: availability is controlled by `FLOCI_SERVICES_RDS_DATA_ENABLED` and whether the target local RDS resource is running.

## Configuration

Expand Down
15 changes: 15 additions & 0 deletions docs/services/rds.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ RDS Data API (`rds-data`) is documented separately because it uses REST JSON rou
| `DescribeDBClusterEndpoints` | List a cluster's built-in writer and reader endpoints and its custom endpoints, with the four documented filters |
| `ModifyDBClusterEndpoint` | Change a custom endpoint's type or member list |
| `DeleteDBClusterEndpoint` | Delete a custom endpoint |
| `EnableHttpEndpoint` | Turn on an Aurora cluster's Data API endpoint by ARN; see [Data API endpoint](#data-api-endpoint) |
| `DisableHttpEndpoint` | Turn off a cluster's Data API endpoint by ARN |
| `AddRoleToDBCluster` | Associate an IAM role with a cluster, optionally for a feature; see [IAM role associations](#iam-role-associations) |
| `RemoveRoleFromDBCluster` | Remove a role from a cluster |
| `AddRoleToDBInstance` | Associate an IAM role with an instance for a feature |
Expand Down Expand Up @@ -616,6 +618,19 @@ Custom endpoints are modelled, not routed: a custom endpoint reports the cluster
reachable, but connections through it go where the cluster endpoint sends them rather than being
spread across the chosen members.

## Data API endpoint

`EnableHttpEndpoint` and `DisableHttpEndpoint` turn a cluster's Data API endpoint on and off by the
cluster's ARN, and `DescribeDBClusters` reports it as `HttpEndpointEnabled`. `CreateDBCluster` and
`ModifyDBCluster` take `EnableHttpEndpoint` too, as does the `AWS::RDS::DBCluster` CloudFormation
property, so Terraform's `enable_http_endpoint` and CDK's `enableDataApi` read back what they set.

The Data API is offered for Aurora PostgreSQL and Aurora MySQL clusters, so turning it on for any
other engine is `InvalidParameterCombination` (a create checks before the cluster exists); turning
it off is always accepted. An ARN that names no cluster in the caller's account and Region is
`ResourceNotFoundFault`, and a cluster that is not available is `InvalidResourceStateFault`. The flag
is recorded and reported only: the Data API (`rds-data`) does not refuse a cluster with it off.

## IAM role associations

`AddRoleToDBCluster` and `AddRoleToDBInstance` associate an IAM role with an available cluster or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ private Response handleCognitoQuery(String action, MultivaluedMap<String, String
"AddTagsToResource", "ListTagsForResource", "RemoveTagsFromResource",
"CreateDBCluster", "DescribeDBClusters", "DeleteDBCluster", "ModifyDBCluster",
"AddRoleToDBCluster", "RemoveRoleFromDBCluster", "AddRoleToDBInstance", "RemoveRoleFromDBInstance",
"EnableHttpEndpoint", "DisableHttpEndpoint",
"DescribeGlobalClusters",
"CreateDBParameterGroup", "DescribeDBParameterGroups",
"DeleteDBParameterGroup", "ModifyDBParameterGroup", "DescribeDBParameters",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,11 @@ private void provisionDbCluster(StackResource r, JsonNode props, CloudFormationT
if (!roles.isEmpty()) {
rdsService.validateClusterRoleAssociations(id, resolveOptional(props, "Engine", engine), roles);
}
boolean httpEndpoint = parseStrictBoolProp(props, "EnableHttpEndpoint", engine);
if (httpEndpoint) {
// Refused before a new cluster exists, rather than leaving one behind.
RdsService.requireDataApiEngine(resolveOptional(props, "Engine", engine));
}
boolean created = cluster == null;
if (cluster != null) {
cluster = rdsService.modifyDbCluster(
Expand Down Expand Up @@ -470,6 +475,10 @@ private void provisionDbCluster(StackResource r, JsonNode props, CloudFormationT
false, null, engineMode, storageEncrypted);
}
cluster = reconcileClusterRoles(r, cluster, roles, created, ctx.isUpdate(), region);
// EnableHttpEndpoint updates with no interruption; a template that leaves it out wants it off.
if (httpEndpoint != cluster.isHttpEndpointEnabled()) {
cluster = rdsService.setHttpEndpoint(region, cluster.getDbClusterIdentifier(), httpEndpoint);
Comment on lines +479 to +480

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

2. A failed update leaves the endpoint changed 🐞 Bug ☼ Reliability

provisionDbCluster persists an in-place EnableHttpEndpoint change without recording its previous
value for rollbackUpdate. If a later stack resource fails, rollback neither restores the flag nor
redeploys the old template, and the stack enters UPDATE_ROLLBACK_FAILED with the cluster still in
the failed update's state.
Agent Prompt
## Issue description
An in-place CloudFormation endpoint update survives a failed stack update and leaves rollback incomplete.
## Fix Focus Areas
- src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/RdsCfnProvisioner.java[478-481]
- src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/RdsCfnProvisioner.java[192-221]
## Recommended Fix
Record the prior endpoint flag before changing it, restore that flag in `rollbackUpdate` for in-place cluster updates, and clear the rollback record after a successful update. Add a stack-level test in which a later resource fails.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗

}
r.setPhysicalId(cluster.getDbClusterIdentifier());
r.getAttributes().put("DBClusterIdentifier", cluster.getDbClusterIdentifier());
if (cluster.getEndpoint() != null) {
Expand Down Expand Up @@ -1063,6 +1072,29 @@ private Integer parseOptionalIntProp(JsonNode props, String name, CloudFormation
}
}

/**
* A Boolean property read strictly: absent, or resolving to {@code AWS::NoValue}, is false; true
* and false (in any case, as JSON booleans or strings) are themselves; anything else is a
* {@code ValidationError} rather than a silent false.
*/
private boolean parseStrictBoolProp(JsonNode props, String name, CloudFormationTemplateEngine engine) {
if (props == null || !props.has(name)) {
return false;
}
JsonNode value = engine.resolveNodeOmittingNoValue(props.get(name));
if (value == null || value.isMissingNode() || value.isNull()) {
return false;
}
if (value.isBoolean()) {
return value.booleanValue();
}
String text = value.asText();
if ("true".equalsIgnoreCase(text) || "false".equalsIgnoreCase(text)) {
return Boolean.parseBoolean(text);
}
throw new AwsException("ValidationError", name + " must be true or false, not " + text + ".", 400);
}

private boolean parseBoolProp(JsonNode props, String name, CloudFormationTemplateEngine engine) {
return Boolean.parseBoolean(resolveOptional(props, name, engine));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ public Response handle(String action, MultivaluedMap<String, String> params, Str
case "DescribeDBClusterEndpoints" -> handleDescribeDbClusterEndpoints(params, region);
case "ModifyDBClusterEndpoint" -> handleModifyDbClusterEndpoint(params, region);
case "DeleteDBClusterEndpoint" -> handleDeleteDbClusterEndpoint(params, region);
case "EnableHttpEndpoint" -> handleSetHttpEndpoint("EnableHttpEndpoint", params, region, true);
case "DisableHttpEndpoint" -> handleSetHttpEndpoint("DisableHttpEndpoint", params, region, false);
case "AddRoleToDBCluster" -> handleAddRoleToDbCluster(params, region);
case "RemoveRoleFromDBCluster" -> handleRemoveRoleFromDbCluster(params, region);
case "AddRoleToDBInstance" -> handleAddRoleToDbInstance(params, region);
Expand Down Expand Up @@ -368,6 +370,16 @@ private Response handleDeleteEventSubscription(MultivaluedMap<String, String> pa
new XmlBuilder().raw(eventSubscriptionXml(subscription)).build())).build();
}

private Response handleSetHttpEndpoint(String action, MultivaluedMap<String, String> params, String region,
boolean enabled) {
DbCluster cluster = service.setHttpEndpointByArn(region, params.getFirst("ResourceArn"), enabled);
String result = new XmlBuilder()
.elem("ResourceArn", cluster.getDbClusterArn())
.elem("HttpEndpointEnabled", cluster.isHttpEndpointEnabled())
.build();
return Response.ok(AwsQueryResponse.envelope(action, AwsNamespaces.RDS, result)).build();
}

private Response handleAddRoleToDbCluster(MultivaluedMap<String, String> params, String region) {
service.addRoleToDbCluster(region, params.getFirst("DBClusterIdentifier"),
params.getFirst("RoleArn"), params.getFirst("FeatureName"));
Expand Down Expand Up @@ -1180,6 +1192,12 @@ private Response handleCreateDbCluster(MultivaluedMap<String, String> params, St
try {
List<DbRoleAssociation> associatedRoles = parseAssociatedRoles(params);
service.validateClusterRoleAssociations(id, engine, associatedRoles);
boolean enableHttpEndpoint = Boolean.TRUE.equals(parseOptionalBoolean(params, "EnableHttpEndpoint"));
String globalCluster = params.getFirst("GlobalClusterIdentifier");
if (enableHttpEndpoint && (globalCluster == null || globalCluster.isBlank())) {
// A global cluster's members take its Aurora engine; any other create names its own.
RdsService.requireDataApiEngine(engine);
}
Double serverlessV2Min = parseDoubleParam(params, "ServerlessV2ScalingConfiguration.MinCapacity");
Double serverlessV2Max = parseDoubleParam(params, "ServerlessV2ScalingConfiguration.MaxCapacity");
Integer serverlessV2SecondsUntilAutoPause = parseIntegerParam(
Expand Down Expand Up @@ -1222,6 +1240,9 @@ private Response handleCreateDbCluster(MultivaluedMap<String, String> params, St
throw e;
}
}
if (enableHttpEndpoint) {
cluster = service.setHttpEndpoint(region, id, true);
}
String result = dbClusterXml(cluster);
return Response.ok(AwsQueryResponse.envelope("CreateDBCluster", AwsNamespaces.RDS, result)).build();
} catch (AwsException e) {
Expand Down Expand Up @@ -1331,9 +1352,16 @@ private Response handleModifyDbCluster(
Double serverlessV2Max = parseDoubleParam(params, "ServerlessV2ScalingConfiguration.MaxCapacity");
Integer serverlessV2SecondsUntilAutoPause = parseIntegerParam(
params, "ServerlessV2ScalingConfiguration.SecondsUntilAutoPause");
Boolean enableHttpEndpoint = parseOptionalBoolean(params, "EnableHttpEndpoint");
if (Boolean.TRUE.equals(enableHttpEndpoint)) {
RdsService.requireDataApiEngine(service.getDbCluster(id, region).getEngineIdentifier());
}
DbCluster cluster = service.modifyDbCluster(id, newPassword, iamEnabled,
serverlessV2Min, serverlessV2Max, serverlessV2SecondsUntilAutoPause,
manageMasterUserPassword, masterUserSecretKmsKeyId, region);
if (enableHttpEndpoint != null) {
cluster = service.setHttpEndpoint(region, id, enableHttpEndpoint);
}
String result = dbClusterXml(cluster);
return Response.ok(AwsQueryResponse.envelope("ModifyDBCluster", AwsNamespaces.RDS, result)).build();
} catch (AwsException e) {
Expand Down Expand Up @@ -2918,6 +2946,7 @@ private String dbClusterInnerXml(DbCluster c) {
.elem("LatestRestorableTime", Instant.now().toString());
}
xml.elem("IAMDatabaseAuthenticationEnabled", c.isIamDatabaseAuthenticationEnabled())
.elem("HttpEndpointEnabled", c.isHttpEndpointEnabled())
.elem("MultiAZ", c.isMultiAz())
.elem("StorageEncrypted", c.isStorageEncrypted())
.elem("AvailabilityZone", c.getAvailabilityZone() != null ? c.getAvailabilityZone() : config.defaultAvailabilityZone())
Expand Down
Loading
Loading