From 1108bc75dcfb0ff54e8926365a48616856bf4bdd Mon Sep 17 00:00:00 2001 From: David Date: Wed, 21 Oct 2026 11:47:06 +0100 Subject: [PATCH] feat(rds): DB proxy endpoints (#6062) * feat(rds): DB proxy endpoints CreateDBProxyEndpoint, DescribeDBProxyEndpoints, ModifyDBProxyEndpoint and DeleteDBProxyEndpoint store endpoints per account and Region, checked against the service model. Each endpoint reports its proxy's own host, so a client connects through it as through the proxy. DescribeDBProxyEndpoints lists each proxy's default endpoint first; it cannot be modified or deleted. Deleting a proxy deletes its endpoints, and endpoint ARNs take tags. Closes #5805 * fix(rds): report each proxy endpoint at the proxy's current host A custom endpoint kept the proxy's host from when it was created, so after a restore gave the proxy a new host, every custom endpoint still reported the old one while default reported the new one. The host is no longer stored with the endpoint: create, describe, modify and delete take it from the proxy when they answer. A missing DBProxyName, DBProxyEndpointName or VpcSubnetIds is now MissingParameter, checked before the proxy is looked up. * test(rds): import Executable and assertTrue instead of naming them inline --- .../sdk-test-awscli/test/rds.bats | 40 +++ .../com/floci/test/RdsControlPlaneTest.java | 56 ++++ docs/services/index.md | 2 +- docs/services/rds.md | 15 +- .../floci/services/rds/RdsQueryHandler.java | 83 +++++ .../floci/services/rds/RdsService.java | 234 ++++++++++++++ .../services/rds/model/DbProxyEndpoint.java | 85 +++++ .../rds/RdsProxyEndpointIntegrationTest.java | 217 +++++++++++++ .../floci/services/rds/RdsServiceTest.java | 291 ++++++++++++++++++ 9 files changed, 1021 insertions(+), 2 deletions(-) create mode 100644 src/main/java/io/github/hectorvent/floci/services/rds/model/DbProxyEndpoint.java create mode 100644 src/test/java/io/github/hectorvent/floci/services/rds/RdsProxyEndpointIntegrationTest.java diff --git a/compatibility-tests/sdk-test-awscli/test/rds.bats b/compatibility-tests/sdk-test-awscli/test/rds.bats index 49c8189f72..00d7391359 100644 --- a/compatibility-tests/sdk-test-awscli/test/rds.bats +++ b/compatibility-tests/sdk-test-awscli/test/rds.bats @@ -6,12 +6,14 @@ setup() { DB_ID="bats-rds-$(unique_name)" DB_ID_2="bats-rds-2-$(unique_name)" RDS_CLUSTER_ID="bats-rds-cluster-$(unique_name)" + PROXY_NAME="bats-proxy-$(unique_name)" } teardown() { aws_cmd rds delete-db-instance --db-instance-identifier "$DB_ID" --skip-final-snapshot >/dev/null 2>&1 || true aws_cmd rds delete-db-instance --db-instance-identifier "$DB_ID_2" --skip-final-snapshot >/dev/null 2>&1 || true aws_cmd rds delete-db-cluster --db-cluster-identifier "$RDS_CLUSTER_ID" --skip-final-snapshot >/dev/null 2>&1 || true + aws_cmd rds delete-db-proxy --db-proxy-name "$PROXY_NAME" >/dev/null 2>&1 || true if [ -n "${MANAGED_SECRET_ARN:-}" ]; then aws_cmd secretsmanager delete-secret --secret-id "$MANAGED_SECRET_ARN" \ --force-delete-without-recovery >/dev/null 2>&1 || true @@ -432,3 +434,41 @@ teardown() { assert_failure assert_output --partial 'InvalidParameterValue' } + +@test "rds: a proxy endpoint is added, renamed and deleted" { + run aws_cmd ec2 describe-subnets --query 'Subnets[?DefaultForAz].SubnetId' + assert_success + subnet_a=$(json_get "$output" '.[0]') + subnet_b=$(json_get "$output" '.[1]') + + run aws_cmd rds create-db-proxy --db-proxy-name "$PROXY_NAME" --engine-family POSTGRESQL \ + --role-arn arn:aws:iam::000000000000:role/rds-proxy \ + --vpc-subnet-ids "$subnet_a" "$subnet_b" \ + --auth AuthScheme=SECRETS,SecretArn=arn:aws:secretsmanager:us-east-1:000000000000:secret:db-AbCdEf + assert_success + + reader="$PROXY_NAME-reader" + run aws_cmd rds create-db-proxy-endpoint --db-proxy-name "$PROXY_NAME" \ + --db-proxy-endpoint-name "$reader" --vpc-subnet-ids "$subnet_a" "$subnet_b" --target-role READ_ONLY + assert_success + [ "$(json_get "$output" '.DBProxyEndpoint.TargetRole')" = "READ_ONLY" ] + [ "$(json_get "$output" '.DBProxyEndpoint.IsDefault')" = "false" ] + + run aws_cmd rds describe-db-proxy-endpoints --db-proxy-name "$PROXY_NAME" + assert_success + [ "$(json_get "$output" '.DBProxyEndpoints[0].DBProxyEndpointName')" = "default" ] + [ "$(json_get "$output" '.DBProxyEndpoints[0].IsDefault')" = "true" ] + [ "$(json_get "$output" '.DBProxyEndpoints[1].DBProxyEndpointName')" = "$reader" ] + + renamed="$PROXY_NAME-analytics" + run aws_cmd rds modify-db-proxy-endpoint --db-proxy-endpoint-name "$reader" \ + --new-db-proxy-endpoint-name "$renamed" + assert_success + [ "$(json_get "$output" '.DBProxyEndpoint.DBProxyEndpointName')" = "$renamed" ] + + run aws_cmd rds delete-db-proxy-endpoint --db-proxy-endpoint-name "$renamed" + assert_success + run aws_cmd rds delete-db-proxy-endpoint --db-proxy-endpoint-name "$renamed" + assert_failure + assert_output --partial 'DBProxyEndpointNotFoundFault' +} diff --git a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/RdsControlPlaneTest.java b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/RdsControlPlaneTest.java index f649c1598c..dccd65bba6 100644 --- a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/RdsControlPlaneTest.java +++ b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/RdsControlPlaneTest.java @@ -14,6 +14,7 @@ import software.amazon.awssdk.services.rds.model.ConnectionPoolConfigurationInfo import software.amazon.awssdk.services.rds.model.CreateDbClusterEndpointResponse; import software.amazon.awssdk.services.rds.model.CreateDbClusterResponse; import software.amazon.awssdk.services.rds.model.CreateDbInstanceResponse; +import software.amazon.awssdk.services.rds.model.CreateDbProxyEndpointResponse; import software.amazon.awssdk.services.rds.model.CreateDbProxyResponse; import software.amazon.awssdk.services.rds.model.CreateDbSubnetGroupResponse; import software.amazon.awssdk.services.rds.model.CreateOptionGroupResponse; @@ -25,6 +26,7 @@ import software.amazon.awssdk.services.rds.model.DBClusterSnapshot; import software.amazon.awssdk.services.rds.model.DBEngineVersion; import software.amazon.awssdk.services.rds.model.DBInstance; import software.amazon.awssdk.services.rds.model.DBInstanceRole; +import software.amazon.awssdk.services.rds.model.DBProxyEndpointTargetRole; import software.amazon.awssdk.services.rds.model.DBProxyTarget; import software.amazon.awssdk.services.rds.model.DBSnapshot; import software.amazon.awssdk.services.rds.model.DbClusterEndpointAlreadyExistsException; @@ -35,10 +37,12 @@ import software.amazon.awssdk.services.rds.model.DbClusterSnapshotNotFoundExcept import software.amazon.awssdk.services.rds.model.DbInstanceRoleAlreadyExistsException; import software.amazon.awssdk.services.rds.model.DbInstanceRoleNotFoundException; import software.amazon.awssdk.services.rds.model.DbLogFileNotFoundException; +import software.amazon.awssdk.services.rds.model.DbProxyEndpointNotFoundException; import software.amazon.awssdk.services.rds.model.DbSnapshotAlreadyExistsException; import software.amazon.awssdk.services.rds.model.DbSnapshotNotFoundException; import software.amazon.awssdk.services.rds.model.DescribeDBLogFilesDetails; import software.amazon.awssdk.services.rds.model.DescribeDbProxiesResponse; +import software.amazon.awssdk.services.rds.model.DescribeDbProxyEndpointsResponse; import software.amazon.awssdk.services.rds.model.DescribeDbProxyTargetGroupsResponse; import software.amazon.awssdk.services.rds.model.DescribeDbProxyTargetsResponse; import software.amazon.awssdk.services.rds.model.DescribeDbSubnetGroupsResponse; @@ -47,11 +51,13 @@ import software.amazon.awssdk.services.rds.model.DescribeOrderableDbInstanceOpti import software.amazon.awssdk.services.rds.model.DownloadDbLogFilePortionResponse; import software.amazon.awssdk.services.rds.model.EngineDefaults; import software.amazon.awssdk.services.rds.model.InvalidDbInstanceStateException; +import software.amazon.awssdk.services.rds.model.InvalidDbProxyEndpointStateException; import software.amazon.awssdk.services.rds.model.InvalidOptionGroupStateException; import software.amazon.awssdk.services.rds.model.InvalidRestoreException; import software.amazon.awssdk.services.rds.model.ListTagsForResourceResponse; import software.amazon.awssdk.services.rds.model.ModifyDbClusterEndpointResponse; import software.amazon.awssdk.services.rds.model.ModifyDbClusterResponse; +import software.amazon.awssdk.services.rds.model.ModifyDbProxyEndpointResponse; import software.amazon.awssdk.services.rds.model.ModifyDbProxyResponse; import software.amazon.awssdk.services.rds.model.ModifyDbProxyTargetGroupResponse; import software.amazon.awssdk.services.rds.model.ModifyOptionGroupResponse; @@ -317,6 +323,56 @@ class RdsControlPlaneTest { } } + @Test + void sdkRoundTripsDbProxyEndpoints() { + String proxyName = TestFixtures.uniqueName("rds-proxy-endpoints"); + String endpointName = TestFixtures.uniqueName("reader"); + String renamed = TestFixtures.uniqueName("analytics"); + try { + CreateDbProxyResponse proxy = rds.createDBProxy(b -> b + .dbProxyName(proxyName) + .engineFamily("POSTGRESQL") + .roleArn("arn:aws:iam::000000000000:role/rds-proxy") + .vpcSubnetIds(subnetIds) + .auth(a -> a.authScheme("SECRETS") + .secretArn("arn:aws:secretsmanager:us-east-1:000000000000:secret:db-AbCdEf"))); + + CreateDbProxyEndpointResponse created = rds.createDBProxyEndpoint(b -> b + .dbProxyName(proxyName) + .dbProxyEndpointName(endpointName) + .vpcSubnetIds(subnetIds) + .vpcSecurityGroupIds("sg-endpoint") + .targetRole(DBProxyEndpointTargetRole.READ_ONLY) + .tags(t -> t.key("team").value("data"))); + assertThat(created.dbProxyEndpoint().targetRole()).isEqualTo(DBProxyEndpointTargetRole.READ_ONLY); + assertThat(created.dbProxyEndpoint().isDefault()).isFalse(); + assertThat(created.dbProxyEndpoint().endpoint()).isEqualTo(proxy.dbProxy().endpoint()); + assertThat(created.dbProxyEndpoint().createdDate()).isNotNull(); + assertThat(rds.listTagsForResource(b -> b.resourceName(created.dbProxyEndpoint().dbProxyEndpointArn())) + .tagList()).extracting("key").containsExactly("team"); + + DescribeDbProxyEndpointsResponse described = rds.describeDBProxyEndpoints(b -> b.dbProxyName(proxyName)); + assertThat(described.dbProxyEndpoints()).extracting("dbProxyEndpointName") + .containsExactly("default", endpointName); + assertThat(described.dbProxyEndpoints().get(0).isDefault()).isTrue(); + + ModifyDbProxyEndpointResponse modified = rds.modifyDBProxyEndpoint(b -> b + .dbProxyEndpointName(endpointName) + .newDBProxyEndpointName(renamed) + .vpcSecurityGroupIds("sg-other")); + assertThat(modified.dbProxyEndpoint().dbProxyEndpointName()).isEqualTo(renamed); + assertThat(modified.dbProxyEndpoint().vpcSecurityGroupIds()).containsExactly("sg-other"); + + assertThatThrownBy(() -> rds.deleteDBProxyEndpoint(b -> b.dbProxyEndpointName("default"))) + .isInstanceOf(InvalidDbProxyEndpointStateException.class); + rds.deleteDBProxyEndpoint(b -> b.dbProxyEndpointName(renamed)); + assertThatThrownBy(() -> rds.describeDBProxyEndpoints(b -> b.dbProxyEndpointName(renamed))) + .isInstanceOf(DbProxyEndpointNotFoundException.class); + } finally { + deleteProxy(rds, proxyName); + } + } + @Test void sdkScopesTheSameDbProxyNameBySignedRegion() { String regionalProxyName = TestFixtures.uniqueName("rds-proxy-regional"); diff --git a/docs/services/index.md b/docs/services/index.md index 86bcf83ffd..b518b7efaa 100644 --- a/docs/services/index.md +++ b/docs/services/index.md @@ -64,7 +64,7 @@ Operation counts are exact. For dispatch-table services (Query and JSON 1.1) eac | [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 | | [Aurora DSQL](dsql.md) | `/cluster`, `/cluster/{identifier}`, `/cluster/{identifier}/policy` | REST JSON | 9 | -| [RDS](rds.md) | `POST /` with `Action=` param + TCP proxy | Query + wire | 105 | +| [RDS](rds.md) | `POST /` with `Action=` param + TCP proxy | Query + wire | 109 | | [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 | diff --git a/docs/services/rds.md b/docs/services/rds.md index cc1d2ea22e..cfe4f20bcb 100644 --- a/docs/services/rds.md +++ b/docs/services/rds.md @@ -126,7 +126,11 @@ RDS Data API (`rds-data`) is documented separately because it uses REST JSON rou | `DescribeDBProxies` | List DB proxies | | `CreateDBProxy` | Create a DB proxy | | `ModifyDBProxy` | Update mutable DB proxy authentication, logging, timeout, TLS, role, and security-group settings | -| `DeleteDBProxy` | Delete a DB proxy | +| `DeleteDBProxy` | Delete a DB proxy and its endpoints | +| `CreateDBProxyEndpoint` | Add a read/write or read-only endpoint to a DB proxy; see the proxy note below | +| `DescribeDBProxyEndpoints` | List proxy endpoints, each proxy's default endpoint first, filtered by `DBProxyName` and `DBProxyEndpointName` | +| `ModifyDBProxyEndpoint` | Rename a proxy endpoint or replace its security groups | +| `DeleteDBProxyEndpoint` | Delete a proxy endpoint | | `RegisterDBProxyTargets` | Register a cluster or instance as a proxy target | | `DeregisterDBProxyTargets` | Remove a cluster or instance from a proxy target group | | `DescribeDBProxyTargetGroups` | List a proxy's target groups | @@ -346,6 +350,15 @@ services: is rejected with `InvalidParameterValue` unless the proxy's VPC and every subnet in `VpcSubnetIds` already carry an associated IPv6 CIDR block, matching AWS's own network prerequisites for RDS Proxy. + Proxy endpoints report the proxy's own host, so a client connects through one as through the + proxy, and an IAM token signed for that host verifies there. The host is read from the proxy + for each response, so when a restore gives the proxy a new host every endpoint reports it. `TargetRole` is recorded: Floci + proxies have one target, so a `READ_ONLY` endpoint reaches the same target as the proxy rather + than an Aurora reader. Each proxy's default endpoint (`default`, `IsDefault` true, `READ_WRITE`) + is built from the proxy, has no ARN, and cannot be modified or deleted + (`InvalidDBProxyEndpointStateFault`). Endpoint names are unique per account and Region, a proxy + holds at most 20 endpoints (`DBProxyEndpointQuotaExceededFault`), and an endpoint with no + `VpcSecurityGroupIds` gets its VPC's default security group. ## Aurora Serverless v2 scaling diff --git a/src/main/java/io/github/hectorvent/floci/services/rds/RdsQueryHandler.java b/src/main/java/io/github/hectorvent/floci/services/rds/RdsQueryHandler.java index 84aa59e3ce..2a993c5600 100644 --- a/src/main/java/io/github/hectorvent/floci/services/rds/RdsQueryHandler.java +++ b/src/main/java/io/github/hectorvent/floci/services/rds/RdsQueryHandler.java @@ -22,6 +22,7 @@ import io.github.hectorvent.floci.services.rds.model.DbInstanceStatus; import io.github.hectorvent.floci.services.rds.model.DbParameterGroup; import io.github.hectorvent.floci.services.rds.model.DbProxy; import io.github.hectorvent.floci.services.rds.model.DbProxyAuth; +import io.github.hectorvent.floci.services.rds.model.DbProxyEndpoint; import io.github.hectorvent.floci.services.rds.model.DbProxyTarget; import io.github.hectorvent.floci.services.rds.model.DbProxyTargetGroup; import io.github.hectorvent.floci.services.rds.model.DbRoleAssociation; @@ -169,6 +170,10 @@ public class RdsQueryHandler { case "CreateDBProxy" -> handleCreateDbProxy(params, region); case "ModifyDBProxy" -> handleModifyDbProxy(params, region); case "DeleteDBProxy" -> handleDeleteDbProxy(params, region); + case "CreateDBProxyEndpoint" -> handleCreateDbProxyEndpoint(params, region); + case "DescribeDBProxyEndpoints" -> handleDescribeDbProxyEndpoints(params, region); + case "ModifyDBProxyEndpoint" -> handleModifyDbProxyEndpoint(params, region); + case "DeleteDBProxyEndpoint" -> handleDeleteDbProxyEndpoint(params, region); case "RegisterDBProxyTargets" -> handleRegisterDbProxyTargets(params, region); case "DeregisterDBProxyTargets" -> handleDeregisterDbProxyTargets(params, region); case "DescribeDBProxyTargetGroups" -> handleDescribeDbProxyTargetGroups(params, region); @@ -2205,6 +2210,84 @@ public class RdsQueryHandler { return Response.ok(AwsQueryResponse.envelope("DeleteDBProxy", AwsNamespaces.RDS, result)).build(); } + private Response handleCreateDbProxyEndpoint(MultivaluedMap params, String region) { + DbProxyEndpoint endpoint = service.createDbProxyEndpoint(region, + params.getFirst("DBProxyName"), + params.getFirst("DBProxyEndpointName"), + memberList(params, "VpcSubnetIds"), + memberList(params, "VpcSecurityGroupIds"), + params.getFirst("TargetRole"), + params.getFirst("EndpointNetworkType"), + parseTags(params)); + return Response.ok(AwsQueryResponse.envelope("CreateDBProxyEndpoint", AwsNamespaces.RDS, + dbProxyEndpointXml(endpoint))).build(); + } + + private Response handleDescribeDbProxyEndpoints(MultivaluedMap params, String region) { + RdsService.ProxyEndpointPage page = service.describeDbProxyEndpoints(region, + params.getFirst("DBProxyName"), + params.getFirst("DBProxyEndpointName"), + optionalInt(params.getFirst("MaxRecords")), + params.getFirst("Marker")); + XmlBuilder xml = new XmlBuilder().start("DBProxyEndpoints"); + for (DbProxyEndpoint endpoint : page.endpoints()) { + xml.start("member").raw(dbProxyEndpointInnerXml(endpoint)).end("member"); + } + xml.end("DBProxyEndpoints"); + if (page.marker() != null) { + xml.elem("Marker", page.marker()); + } + return Response.ok(AwsQueryResponse.envelope("DescribeDBProxyEndpoints", AwsNamespaces.RDS, + xml.build())).build(); + } + + private Response handleModifyDbProxyEndpoint(MultivaluedMap params, String region) { + // Security groups left out of the request are kept; a list given replaces them. + DbProxyEndpoint endpoint = service.modifyDbProxyEndpoint(region, + params.getFirst("DBProxyEndpointName"), + params.getFirst("NewDBProxyEndpointName"), + hasMemberKeys(params, "VpcSecurityGroupIds") ? memberList(params, "VpcSecurityGroupIds") : null); + return Response.ok(AwsQueryResponse.envelope("ModifyDBProxyEndpoint", AwsNamespaces.RDS, + dbProxyEndpointXml(endpoint))).build(); + } + + private Response handleDeleteDbProxyEndpoint(MultivaluedMap params, String region) { + DbProxyEndpoint endpoint = service.deleteDbProxyEndpoint(region, params.getFirst("DBProxyEndpointName")); + return Response.ok(AwsQueryResponse.envelope("DeleteDBProxyEndpoint", AwsNamespaces.RDS, + dbProxyEndpointXml(endpoint))).build(); + } + + private static String dbProxyEndpointXml(DbProxyEndpoint e) { + return new XmlBuilder().start("DBProxyEndpoint").raw(dbProxyEndpointInnerXml(e)).end("DBProxyEndpoint").build(); + } + + /** The DBProxyEndpoint members; a proxy's default endpoint has no ARN. */ + private static String dbProxyEndpointInnerXml(DbProxyEndpoint e) { + XmlBuilder xml = new XmlBuilder().elem("DBProxyEndpointName", e.getDbProxyEndpointName()); + if (e.getDbProxyEndpointArn() != null) { + xml.elem("DBProxyEndpointArn", e.getDbProxyEndpointArn()); + } + xml.elem("DBProxyName", e.getDbProxyName()) + .elem("Status", e.getStatus()); + if (e.getVpcId() != null) { + xml.elem("VpcId", e.getVpcId()); + } + xml.start("VpcSecurityGroupIds"); + e.getVpcSecurityGroupIds().forEach(id -> xml.elem("member", id)); + xml.end("VpcSecurityGroupIds"); + xml.start("VpcSubnetIds"); + e.getVpcSubnetIds().forEach(id -> xml.elem("member", id)); + xml.end("VpcSubnetIds"); + xml.elem("Endpoint", e.getEndpoint()); + if (e.getCreatedDate() != null) { + xml.elem("CreatedDate", e.getCreatedDate().toString()); + } + xml.elem("TargetRole", e.getTargetRole()) + .elem("IsDefault", String.valueOf(e.isDefault())) + .elem("EndpointNetworkType", e.getEndpointNetworkType() != null ? e.getEndpointNetworkType() : "IPV4"); + return xml.build(); + } + private Response handleRegisterDbProxyTargets(MultivaluedMap params, String region) { String name = params.getFirst("DBProxyName"); String tgName = params.getFirst("TargetGroupName"); diff --git a/src/main/java/io/github/hectorvent/floci/services/rds/RdsService.java b/src/main/java/io/github/hectorvent/floci/services/rds/RdsService.java index f7d1ca39d6..f2a725eef4 100644 --- a/src/main/java/io/github/hectorvent/floci/services/rds/RdsService.java +++ b/src/main/java/io/github/hectorvent/floci/services/rds/RdsService.java @@ -48,6 +48,7 @@ import io.github.hectorvent.floci.services.rds.model.DbInstanceStatus; import io.github.hectorvent.floci.services.rds.model.DbParameterGroup; import io.github.hectorvent.floci.services.rds.model.DbProxy; import io.github.hectorvent.floci.services.rds.model.DbProxyAuth; +import io.github.hectorvent.floci.services.rds.model.DbProxyEndpoint; import io.github.hectorvent.floci.services.rds.model.DbProxyTarget; import io.github.hectorvent.floci.services.rds.model.DbProxyTargetGroup; import io.github.hectorvent.floci.services.rds.model.DbRoleAssociation; @@ -182,6 +183,7 @@ public class RdsService implements Resettable, ResourceProvider { private StorageBackend events = new InMemoryStorage<>(); private final StorageBackend eventSubscriptions; private final StorageBackend clusterEndpoints; + private final StorageBackend proxyEndpoints; private final RdsContainerManager containerManager; private final RdsProxyManager proxyManager; // CreateDBCluster/CreateDBInstance register the new resource only after the @@ -257,6 +259,8 @@ public class RdsService implements Resettable, ResourceProvider { new TypeReference>() {}); this.clusterEndpoints = storageFactory.create("rds", "rds-cluster-endpoints.json", new TypeReference>() {}); + this.proxyEndpoints = storageFactory.create("rds", "rds-proxy-endpoints.json", + new TypeReference>() {}); this.clusters = storageFactory.create("rds", "rds-clusters.json", new TypeReference>() {}); this.parameterGroups = storageFactory.create("rds", "rds-parameter-groups.json", @@ -419,6 +423,7 @@ public class RdsService implements Resettable, ResourceProvider { this.snapshotData = new io.github.hectorvent.floci.core.storage.InMemoryStorage<>(); this.eventSubscriptions = new InMemoryStorage<>(); this.clusterEndpoints = new InMemoryStorage<>(); + this.proxyEndpoints = new InMemoryStorage<>(); } public void restorePersistedRuntime() { @@ -2525,6 +2530,16 @@ public class RdsService implements Resettable, ResourceProvider { eventSubscriptions.put(eventSubscriptionKey(effectiveRegion, resourceId), subscription); }); } + case "db-proxy-endpoint" -> { + DbProxyEndpoint endpoint = proxyEndpoints.scan(k -> k.startsWith(effectiveRegion + "::")).stream() + .filter(candidate -> resourceName.equals(candidate.getDbProxyEndpointArn())) + .findFirst() + .orElseThrow(() -> proxyEndpointNotFound(resourceId)); + yield new TagHandle(endpoint.getTags(), updated -> { + endpoint.setTags(updated); + proxyEndpoints.put(proxyEndpointKey(effectiveRegion, endpoint.getDbProxyEndpointName()), endpoint); + }); + } case "db-proxy" -> { DbProxy proxy = proxies.scan(k -> true).stream() .filter(candidate -> effectiveRegion.equals(regionFromArn(candidate.getDbProxyArn()))) @@ -6310,6 +6325,7 @@ public class RdsService implements Resettable, ResourceProvider { .or(() -> legacyTargetGroup .filter(candidate -> targetGroupMatchesProxy(candidate, proxy))) .orElse(null); + List endpoints = proxyEndpointsOf(effectiveRegion, name); boolean realMode = !config.services().rds().mock(); if (realMode) { try { @@ -6320,6 +6336,10 @@ public class RdsService implements Resettable, ResourceProvider { } } try { + // A proxy's endpoints go with it. + for (DbProxyEndpoint endpoint : endpoints) { + proxyEndpoints.delete(proxyEndpointKey(effectiveRegion, endpoint.getDbProxyEndpointName())); + } deleteTargetGroupKey(accountId, proxyKey); if (legacyTargetGroup.isPresent()) { deleteTargetGroupKey(accountId, name); @@ -6329,6 +6349,10 @@ public class RdsService implements Resettable, ResourceProvider { } deleteProxyKey(accountId, proxyKey); } catch (RuntimeException deleteFailure) { + for (DbProxyEndpoint endpoint : endpoints) { + attemptRollback(deleteFailure, () -> proxyEndpoints.put( + proxyEndpointKey(effectiveRegion, endpoint.getDbProxyEndpointName()), endpoint)); + } attemptRollback(deleteFailure, () -> putProxyForAccount(accountId, proxyKey, proxy)); canonicalTargetGroup.ifPresent(targetGroup -> attemptRollback(deleteFailure, @@ -6344,6 +6368,216 @@ public class RdsService implements Resettable, ResourceProvider { LOG.infov("DB proxy {0} deleted", name); } + // ── DB Proxy endpoints ──────────────────────────────────────────────────── + + /** AWS's limit on the endpoints a caller adds to one proxy, besides its default endpoint. */ + private static final int MAX_ENDPOINTS_PER_PROXY = 20; + private static final String DEFAULT_PROXY_ENDPOINT_NAME = "default"; + private static final Set PROXY_ENDPOINT_TARGET_ROLES = Set.of("READ_WRITE", "READ_ONLY"); + private static final Set PROXY_ENDPOINT_NETWORK_TYPES = Set.of("IPV4", "IPV6", "DUAL"); + + public record ProxyEndpointPage(List endpoints, String marker) {} + + /** + * Adds an endpoint to a proxy. It reports the proxy's own host, so a client reaches the proxy's + * listener through it, and an IAM token signed for that host verifies there. + */ + public synchronized DbProxyEndpoint createDbProxyEndpoint(String region, String dbProxyName, String endpointName, + List vpcSubnetIds, + List vpcSecurityGroupIds, String targetRole, + String endpointNetworkType, Map tags) { + String effectiveRegion = effectiveRegion(region); + requireParameter(dbProxyName, "DBProxyName"); + String name = requireProxyEndpointName(endpointName, "DBProxyEndpointName"); + if (vpcSubnetIds == null || vpcSubnetIds.isEmpty()) { + throw new AwsException("MissingParameter", "The request must contain the parameter VpcSubnetIds.", 400); + } + DbProxy proxy = getDbProxy(dbProxyName, effectiveRegion); + String role = isBlank(targetRole) ? "READ_WRITE" : targetRole; + if (!PROXY_ENDPOINT_TARGET_ROLES.contains(role)) { + throw new AwsException("InvalidParameterValue", "TargetRole must be READ_WRITE or READ_ONLY.", 400); + } + if ("READ_ONLY".equals(role) && "SQLSERVER".equalsIgnoreCase(proxy.getEngineFamily())) { + throw new AwsException("InvalidParameterCombination", + "A DB proxy for RDS for SQL Server supports only the READ_WRITE target role.", 400); + } + String networkType = isBlank(endpointNetworkType) ? "IPV4" : endpointNetworkType; + if (!PROXY_ENDPOINT_NETWORK_TYPES.contains(networkType)) { + throw new AwsException("InvalidParameterValue", "EndpointNetworkType must be IPV4, IPV6, or DUAL.", 400); + } + if (!"available".equals(proxy.getStatus())) { + throw new AwsException("InvalidDBProxyStateFault", + "DB proxy " + proxy.getDbProxyName() + " is not available.", 400); + } + String key = proxyEndpointKey(effectiveRegion, name); + if (DEFAULT_PROXY_ENDPOINT_NAME.equals(name) || proxyEndpoints.get(key).isPresent()) { + throw new AwsException("DBProxyEndpointAlreadyExistsFault", + "DB proxy endpoint " + name + " already exists.", 400); + } + if (proxyEndpointsOf(effectiveRegion, proxy.getDbProxyName()).size() >= MAX_ENDPOINTS_PER_PROXY) { + throw new AwsException("DBProxyEndpointQuotaExceededFault", + "DB proxy " + proxy.getDbProxyName() + " already has " + MAX_ENDPOINTS_PER_PROXY + + " endpoints.", 400); + } + String vpcId = resolveDbProxyVpc(vpcSubnetIds, effectiveRegion); + if (!"IPV4".equals(networkType)) { + validateVpcHasIpv6CidrBlock(vpcId, effectiveRegion); + validateSubnetsHaveIpv6CidrBlock(vpcSubnetIds, effectiveRegion); + } + + DbProxyEndpoint endpoint = new DbProxyEndpoint(); + endpoint.setDbProxyEndpointName(name); + endpoint.setDbProxyEndpointArn(regionResolver.buildArn("rds", effectiveRegion, + "db-proxy-endpoint:prx-endpoint-" + randomResourceSuffix())); + endpoint.setDbProxyName(proxy.getDbProxyName()); + endpoint.setStatus("available"); + endpoint.setVpcId(vpcId); + endpoint.setVpcSubnetIds(vpcSubnetIds); + endpoint.setVpcSecurityGroupIds(vpcSecurityGroupIds == null || vpcSecurityGroupIds.isEmpty() + ? defaultSecurityGroupOf(vpcId, effectiveRegion) : vpcSecurityGroupIds); + endpoint.setCreatedDate(Instant.now()); + endpoint.setTargetRole(role); + endpoint.setEndpointNetworkType(networkType); + endpoint.setTags(tags); + proxyEndpoints.put(key, endpoint); + return withProxyHost(endpoint, proxy); + } + + /** + * Each proxy in scope's default endpoint, then the endpoints added to it by name, narrowed by + * the request's proxy and endpoint names. + */ + public synchronized ProxyEndpointPage describeDbProxyEndpoints(String region, String dbProxyName, + String endpointName, Integer maxRecords, + String marker) { + String effectiveRegion = effectiveRegion(region); + requireValidMaxRecords(maxRecords); + List scope = !isBlank(dbProxyName) + ? List.of(getDbProxy(dbProxyName, effectiveRegion)) + : listDbProxies(null, effectiveRegion).stream() + .sorted(Comparator.comparing(DbProxy::getDbProxyName)) + .toList(); + List all = new ArrayList<>(); + for (DbProxy proxy : scope) { + all.add(defaultProxyEndpoint(proxy)); + proxyEndpointsOf(effectiveRegion, proxy.getDbProxyName()).stream() + .sorted(Comparator.comparing(DbProxyEndpoint::getDbProxyEndpointName)) + .map(endpoint -> withProxyHost(endpoint, proxy)) + .forEach(all::add); + } + List matching = all.stream() + .filter(e -> isBlank(endpointName) || endpointName.equals(e.getDbProxyEndpointName())) + .toList(); + if (!isBlank(endpointName) && matching.isEmpty()) { + throw proxyEndpointNotFound(endpointName); + } + OffsetPage page = offsetPage(matching, maxRecords, marker); + return new ProxyEndpointPage(page.items(), page.marker()); + } + + /** Renames an endpoint or replaces its security groups; a proxy's default endpoint cannot change. */ + public synchronized DbProxyEndpoint modifyDbProxyEndpoint(String region, String endpointName, String newName, + List vpcSecurityGroupIds) { + String effectiveRegion = effectiveRegion(region); + DbProxyEndpoint endpoint = requireProxyEndpoint(effectiveRegion, endpointName); + DbProxy proxy = getDbProxy(endpoint.getDbProxyName(), effectiveRegion); + if (!"available".equals(proxy.getStatus())) { + throw new AwsException("InvalidDBProxyStateFault", + "DB proxy " + proxy.getDbProxyName() + " is not available.", 400); + } + String name = isBlank(newName) ? endpoint.getDbProxyEndpointName() + : requireProxyEndpointName(newName, "NewDBProxyEndpointName"); + boolean renamed = !name.equals(endpoint.getDbProxyEndpointName()); + if (renamed && (DEFAULT_PROXY_ENDPOINT_NAME.equals(name) + || proxyEndpoints.get(proxyEndpointKey(effectiveRegion, name)).isPresent())) { + throw new AwsException("DBProxyEndpointAlreadyExistsFault", + "DB proxy endpoint " + name + " already exists.", 400); + } + String oldKey = proxyEndpointKey(effectiveRegion, endpoint.getDbProxyEndpointName()); + endpoint.setDbProxyEndpointName(name); + if (vpcSecurityGroupIds != null) { + endpoint.setVpcSecurityGroupIds(vpcSecurityGroupIds); + } + proxyEndpoints.put(proxyEndpointKey(effectiveRegion, name), endpoint); + if (renamed) { + proxyEndpoints.delete(oldKey); + } + return withProxyHost(endpoint, proxy); + } + + /** Deletes an endpoint; the response reports it as {@code deleting}. */ + public synchronized DbProxyEndpoint deleteDbProxyEndpoint(String region, String endpointName) { + String effectiveRegion = effectiveRegion(region); + DbProxyEndpoint endpoint = requireProxyEndpoint(effectiveRegion, endpointName); + proxyEndpoints.delete(proxyEndpointKey(effectiveRegion, endpoint.getDbProxyEndpointName())); + endpoint.setStatus("deleting"); + return withProxyHost(endpoint, getDbProxy(endpoint.getDbProxyName(), effectiveRegion)); + } + + /** A stored endpoint by name; the default endpoint is in a state no change can be made in. */ + private DbProxyEndpoint requireProxyEndpoint(String region, String endpointName) { + String name = requireProxyEndpointName(endpointName, "DBProxyEndpointName"); + if (DEFAULT_PROXY_ENDPOINT_NAME.equals(name)) { + throw new AwsException("InvalidDBProxyEndpointStateFault", + "The default endpoint of a DB proxy cannot be modified or deleted.", 400); + } + return proxyEndpoints.get(proxyEndpointKey(region, name)).orElseThrow(() -> proxyEndpointNotFound(name)); + } + + private static String requireProxyEndpointName(String name, String parameter) { + requireParameter(name, parameter); + if (name.length() > 63 || !DB_PROXY_NAME_PATTERN.matcher(name).matches()) { + throw new AwsException("InvalidParameterValue", parameter + " must be 1-63 characters, begin with a " + + "letter, and contain only letters, digits, and single hyphens.", 400); + } + return name; + } + + /** Reports the proxy's current host, which a restore can change after the endpoint was created. */ + private static DbProxyEndpoint withProxyHost(DbProxyEndpoint endpoint, DbProxy proxy) { + endpoint.setEndpoint(proxy.getEndpoint()); + return endpoint; + } + + private static AwsException proxyEndpointNotFound(String name) { + return new AwsException("DBProxyEndpointNotFoundFault", "DB proxy endpoint " + name + " not found.", 404); + } + + /** The endpoint RDS gives every proxy: read/write, in the proxy's VPC, at the proxy's host. */ + private static DbProxyEndpoint defaultProxyEndpoint(DbProxy proxy) { + DbProxyEndpoint endpoint = new DbProxyEndpoint(); + endpoint.setDbProxyEndpointName(DEFAULT_PROXY_ENDPOINT_NAME); + endpoint.setDbProxyName(proxy.getDbProxyName()); + endpoint.setStatus(proxy.getStatus()); + endpoint.setVpcId(proxy.getVpcId()); + endpoint.setVpcSubnetIds(proxy.getVpcSubnetIds()); + endpoint.setVpcSecurityGroupIds(proxy.getVpcSecurityGroupIds()); + endpoint.setEndpoint(proxy.getEndpoint()); + endpoint.setCreatedDate(proxy.getCreatedAt()); + endpoint.setTargetRole("READ_WRITE"); + endpoint.setDefault(true); + endpoint.setEndpointNetworkType(proxy.getEndpointNetworkType()); + return endpoint; + } + + private List defaultSecurityGroupOf(String vpcId, String region) { + return ec2Service.getSecurityGroupsForVpc(region, vpcId, Map.of()).stream() + .filter(group -> "default".equals(group.getGroupName())) + .map(group -> group.getGroupId()) + .toList(); + } + + private List proxyEndpointsOf(String region, String dbProxyName) { + String prefix = effectiveRegion(region) + "::"; + return proxyEndpoints.scan(key -> key.startsWith(prefix)).stream() + .filter(endpoint -> dbProxyName.equals(endpoint.getDbProxyName())) + .toList(); + } + + private String proxyEndpointKey(String region, String endpointName) { + return effectiveRegion(region) + "::" + endpointName; + } + // ── DB Subnet Groups ────────────────────────────────────────────────────── public DbSubnetGroup createDbSubnetGroup(String name, String description, List subnetIds) { diff --git a/src/main/java/io/github/hectorvent/floci/services/rds/model/DbProxyEndpoint.java b/src/main/java/io/github/hectorvent/floci/services/rds/model/DbProxyEndpoint.java new file mode 100644 index 0000000000..7effa6fe03 --- /dev/null +++ b/src/main/java/io/github/hectorvent/floci/services/rds/model/DbProxyEndpoint.java @@ -0,0 +1,85 @@ +package io.github.hectorvent.floci.services.rds.model; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import io.quarkus.runtime.annotations.RegisterForReflection; + +import java.time.Instant; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +/** + * A DB proxy endpoint as DescribeDBProxyEndpoints reports it. Endpoints a caller creates are + * stored; a proxy's default endpoint is built from the proxy when described and carries no ARN. + * Every endpoint reports the proxy's own host, so a connection through it reaches the proxy's + * listener and the proxy's one target, whatever its target role. The host is not stored: a restored + * proxy can come back on a new one, so each response reads it from the proxy. + */ +@RegisterForReflection +public class DbProxyEndpoint { + + private String dbProxyEndpointName; + private String dbProxyEndpointArn; + private String dbProxyName; + private String status; + private String vpcId; + private List vpcSubnetIds = new ArrayList<>(); + private List vpcSecurityGroupIds = new ArrayList<>(); + /** The owning proxy's host, filled in for each response. */ + @JsonIgnore + private String endpoint; + private Instant createdDate; + /** READ_WRITE or READ_ONLY. */ + private String targetRole; + private boolean isDefault; + private String endpointNetworkType; + private Map tags = new LinkedHashMap<>(); + + public DbProxyEndpoint() {} + + public String getDbProxyEndpointName() { return dbProxyEndpointName; } + public void setDbProxyEndpointName(String dbProxyEndpointName) { this.dbProxyEndpointName = dbProxyEndpointName; } + + public String getDbProxyEndpointArn() { return dbProxyEndpointArn; } + public void setDbProxyEndpointArn(String dbProxyEndpointArn) { this.dbProxyEndpointArn = dbProxyEndpointArn; } + + public String getDbProxyName() { return dbProxyName; } + public void setDbProxyName(String dbProxyName) { this.dbProxyName = dbProxyName; } + + public String getStatus() { return status; } + public void setStatus(String status) { this.status = status; } + + public String getVpcId() { return vpcId; } + public void setVpcId(String vpcId) { this.vpcId = vpcId; } + + public List getVpcSubnetIds() { return vpcSubnetIds; } + public void setVpcSubnetIds(List vpcSubnetIds) { + this.vpcSubnetIds = vpcSubnetIds != null ? new ArrayList<>(vpcSubnetIds) : new ArrayList<>(); + } + + public List getVpcSecurityGroupIds() { return vpcSecurityGroupIds; } + public void setVpcSecurityGroupIds(List vpcSecurityGroupIds) { + this.vpcSecurityGroupIds = vpcSecurityGroupIds != null ? new ArrayList<>(vpcSecurityGroupIds) : new ArrayList<>(); + } + + public String getEndpoint() { return endpoint; } + public void setEndpoint(String endpoint) { this.endpoint = endpoint; } + + public Instant getCreatedDate() { return createdDate; } + public void setCreatedDate(Instant createdDate) { this.createdDate = createdDate; } + + public String getTargetRole() { return targetRole; } + public void setTargetRole(String targetRole) { this.targetRole = targetRole; } + + public boolean isDefault() { return isDefault; } + public void setDefault(boolean isDefault) { this.isDefault = isDefault; } + + public String getEndpointNetworkType() { return endpointNetworkType; } + public void setEndpointNetworkType(String endpointNetworkType) { this.endpointNetworkType = endpointNetworkType; } + + public Map getTags() { return tags; } + public void setTags(Map tags) { + this.tags = tags != null ? new LinkedHashMap<>(tags) : new LinkedHashMap<>(); + } +} diff --git a/src/test/java/io/github/hectorvent/floci/services/rds/RdsProxyEndpointIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/rds/RdsProxyEndpointIntegrationTest.java new file mode 100644 index 0000000000..b3df3017cd --- /dev/null +++ b/src/test/java/io/github/hectorvent/floci/services/rds/RdsProxyEndpointIntegrationTest.java @@ -0,0 +1,217 @@ +package io.github.hectorvent.floci.services.rds; + +import io.github.hectorvent.floci.services.ec2.Ec2Service; +import io.quarkus.test.junit.QuarkusTest; +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; +import static org.hamcrest.Matchers.not; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * DB proxy endpoints over the Query protocol: create, describe after the proxy's default endpoint, + * tag, rename, delete, and removal with their proxy. Runs in its own Region so the endpoint names + * it uses are its own. + */ +@QuarkusTest +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +class RdsProxyEndpointIntegrationTest { + + private static final String REGION = "eu-west-3"; + private static final String PROXY = "pep-proxy"; + private static final String MEMBERS = + "DescribeDBProxyEndpointsResponse.DescribeDBProxyEndpointsResult.DBProxyEndpoints.member"; + private static final String AUTH = + "AWS4-HMAC-SHA256 Credential=test/20261019/" + REGION + "/rds/aws4_request, " + + "SignedHeaders=content-type;host, Signature=test"; + + private static String endpointArn; + + private static RequestSpecification query(String action) { + return given().header("Authorization", AUTH) + .contentType(URLENC) + .formParam("Action", action) + .formParam("Version", "2014-10-31"); + } + + private static RequestSpecification withSubnets(RequestSpecification request) { + return request.formParam("VpcSubnetIds.member.1", Ec2Service.defaultSubnetId(REGION, "a")) + .formParam("VpcSubnetIds.member.2", Ec2Service.defaultSubnetId(REGION, "b")); + } + + private static RequestSpecification describe() { + return query("DescribeDBProxyEndpoints").formParam("DBProxyName", PROXY); + } + + @Test + @Order(1) + void anEndpointIsAddedToAProxy() { + withSubnets(query("CreateDBProxy")) + .formParam("DBProxyName", PROXY) + .formParam("EngineFamily", "POSTGRESQL") + .formParam("RoleArn", "arn:aws:iam::000000000000:role/proxy") + .formParam("VpcSecurityGroupIds.member.1", "sg-proxy") + .formParam("Auth.member.1.AuthScheme", "SECRETS") + .formParam("Auth.member.1.SecretArn", + "arn:aws:secretsmanager:" + REGION + ":000000000000:secret:db-AbCdEf") + .when().post("/").then().statusCode(200); + + endpointArn = withSubnets(query("CreateDBProxyEndpoint")) + .formParam("DBProxyName", PROXY) + .formParam("DBProxyEndpointName", "reader") + .formParam("TargetRole", "READ_ONLY") + .formParam("VpcSecurityGroupIds.member.1", "sg-endpoint") + .formParam("Tags.Tag.1.Key", "team") + .formParam("Tags.Tag.1.Value", "data") + .when().post("/").then() + .statusCode(200) + .body(containsString("")) + .body("CreateDBProxyEndpointResponse.CreateDBProxyEndpointResult.DBProxyEndpoint.DBProxyEndpointName", + equalTo("reader")) + .body(containsString("" + PROXY + "")) + .body(containsString("available")) + .body(containsString("READ_ONLY")) + .body(containsString("false")) + .body(containsString("IPV4")) + .body(containsString("sg-endpoint")) + .body(containsString("")) + .extract().path("CreateDBProxyEndpointResponse.CreateDBProxyEndpointResult.DBProxyEndpoint" + + ".DBProxyEndpointArn"); + assertTrue( + endpointArn.startsWith("arn:aws:rds:" + REGION + ":000000000000:db-proxy-endpoint:prx-endpoint-"), + endpointArn); + } + + @Test + @Order(2) + void theProxysDefaultEndpointIsListedFirst() { + String proxyHost = query("DescribeDBProxies").formParam("DBProxyName", PROXY) + .when().post("/").then().statusCode(200) + .extract().path("DescribeDBProxiesResponse.DescribeDBProxiesResult.DBProxies.member.Endpoint"); + + describe().when().post("/").then() + .statusCode(200) + .body(MEMBERS + ".size()", equalTo(2)) + .body(MEMBERS + "[0].DBProxyEndpointName", equalTo("default")) + .body(MEMBERS + "[0].IsDefault", equalTo("true")) + .body(MEMBERS + "[0].TargetRole", equalTo("READ_WRITE")) + // Only the added endpoint has an ARN. + .body(MEMBERS + ".DBProxyEndpointArn.size()", equalTo(1)) + .body(MEMBERS + "[1].DBProxyEndpointArn", equalTo(endpointArn)) + .body(MEMBERS + "[0].Endpoint", equalTo(proxyHost)) + .body(MEMBERS + "[1].DBProxyEndpointName", equalTo("reader")) + .body(MEMBERS + "[1].Endpoint", equalTo(proxyHost)) + .body(not(containsString(""))); + + query("DescribeDBProxyEndpoints").formParam("DBProxyEndpointName", "absent") + .when().post("/").then().statusCode(404) + .body(containsString("DBProxyEndpointNotFoundFault")); + query("DescribeDBProxyEndpoints").formParam("DBProxyName", "absent-proxy") + .when().post("/").then().statusCode(404) + .body(containsString("DBProxyNotFoundFault")); + } + + @Test + @Order(3) + void anEndpointIsTaggedByItsArn() { + query("ListTagsForResource").formParam("ResourceName", endpointArn) + .when().post("/").then().statusCode(200) + .body(containsString("teamdata")); + } + + @Test + @Order(4) + void requestsOutsideTheModelAreRefused() { + withSubnets(query("CreateDBProxyEndpoint")) + .formParam("DBProxyName", PROXY).formParam("DBProxyEndpointName", "reader") + .when().post("/").then().statusCode(400) + .body(containsString("DBProxyEndpointAlreadyExistsFault")); + withSubnets(query("CreateDBProxyEndpoint")) + .formParam("DBProxyName", PROXY).formParam("DBProxyEndpointName", "bad--name") + .when().post("/").then().statusCode(400) + .body(containsString("InvalidParameterValue")); + withSubnets(query("CreateDBProxyEndpoint")) + .formParam("DBProxyName", PROXY).formParam("DBProxyEndpointName", "writer") + .formParam("TargetRole", "WRITER") + .when().post("/").then().statusCode(400) + .body(containsString("InvalidParameterValue")); + query("CreateDBProxyEndpoint") + .formParam("DBProxyName", PROXY).formParam("DBProxyEndpointName", "lonely") + .formParam("VpcSubnetIds.member.1", Ec2Service.defaultSubnetId(REGION, "a")) + .when().post("/").then().statusCode(400) + .body(containsString("InvalidSubnet")); + withSubnets(query("CreateDBProxyEndpoint")).formParam("DBProxyEndpointName", "orphan") + .when().post("/").then().statusCode(400) + .body(containsString("MissingParameter")) + .body(containsString("The request must contain the parameter DBProxyName.")); + withSubnets(query("CreateDBProxyEndpoint")).formParam("DBProxyName", PROXY) + .when().post("/").then().statusCode(400) + .body(containsString("The request must contain the parameter DBProxyEndpointName.")); + query("CreateDBProxyEndpoint") + .formParam("DBProxyName", PROXY).formParam("DBProxyEndpointName", "nowhere") + .when().post("/").then().statusCode(400) + .body(containsString("The request must contain the parameter VpcSubnetIds.")); + query("DeleteDBProxyEndpoint") + .when().post("/").then().statusCode(400) + .body(containsString("MissingParameter")); + query("ModifyDBProxyEndpoint").formParam("DBProxyEndpointName", "default") + .formParam("NewDBProxyEndpointName", "renamed") + .when().post("/").then().statusCode(400) + .body(containsString("InvalidDBProxyEndpointStateFault")); + query("DeleteDBProxyEndpoint").formParam("DBProxyEndpointName", "default") + .when().post("/").then().statusCode(400) + .body(containsString("InvalidDBProxyEndpointStateFault")); + describe().formParam("MaxRecords", "19") + .when().post("/").then().statusCode(400) + .body(containsString("InvalidParameterValue")); + } + + @Test + @Order(5) + void anEndpointIsRenamedAndDeleted() { + query("ModifyDBProxyEndpoint") + .formParam("DBProxyEndpointName", "reader") + .formParam("NewDBProxyEndpointName", "analytics") + .formParam("VpcSecurityGroupIds.member.1", "sg-other") + .when().post("/").then() + .statusCode(200) + .body(containsString("")) + .body(containsString("analytics")) + .body(containsString("" + endpointArn + "")) + .body(containsString("sg-other")); + + query("DeleteDBProxyEndpoint").formParam("DBProxyEndpointName", "analytics") + .when().post("/").then() + .statusCode(200) + .body(containsString("")) + .body(containsString("deleting")); + query("DeleteDBProxyEndpoint").formParam("DBProxyEndpointName", "analytics") + .when().post("/").then().statusCode(404) + .body(containsString("DBProxyEndpointNotFoundFault")); + describe().when().post("/").then().statusCode(200) + .body(MEMBERS + ".DBProxyEndpointName", equalTo("default")); + } + + @Test + @Order(6) + void deletingTheProxyDeletesItsEndpoints() { + withSubnets(query("CreateDBProxyEndpoint")) + .formParam("DBProxyName", PROXY).formParam("DBProxyEndpointName", "leftover") + .when().post("/").then().statusCode(200); + + query("DeleteDBProxy").formParam("DBProxyName", PROXY).when().post("/").then().statusCode(200); + + query("DeleteDBProxyEndpoint").formParam("DBProxyEndpointName", "leftover") + .when().post("/").then().statusCode(404) + .body(containsString("DBProxyEndpointNotFoundFault")); + query("DescribeDBProxyEndpoints").when().post("/").then().statusCode(200) + .body(not(containsString(""))); + } +} diff --git a/src/test/java/io/github/hectorvent/floci/services/rds/RdsServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/rds/RdsServiceTest.java index 053a8a9205..0049a5de8d 100644 --- a/src/test/java/io/github/hectorvent/floci/services/rds/RdsServiceTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/rds/RdsServiceTest.java @@ -12,6 +12,7 @@ import io.github.hectorvent.floci.core.storage.InMemoryStorage; import io.github.hectorvent.floci.core.storage.StorageBackend; import io.github.hectorvent.floci.core.storage.StorageFactory; import io.github.hectorvent.floci.services.ec2.Ec2Service; +import io.github.hectorvent.floci.services.ec2.model.SecurityGroup; import io.github.hectorvent.floci.services.ec2.model.Subnet; import io.github.hectorvent.floci.services.ec2.model.Vpc; import io.github.hectorvent.floci.services.ec2.model.VpcIpv6CidrBlockAssociation; @@ -35,6 +36,7 @@ import io.github.hectorvent.floci.services.rds.model.DbInstanceStatus; import io.github.hectorvent.floci.services.rds.model.DbParameterGroup; import io.github.hectorvent.floci.services.rds.model.DbProxy; import io.github.hectorvent.floci.services.rds.model.DbProxyAuth; +import io.github.hectorvent.floci.services.rds.model.DbProxyEndpoint; import io.github.hectorvent.floci.services.rds.model.DbProxyTarget; import io.github.hectorvent.floci.services.rds.model.DbProxyTargetGroup; import io.github.hectorvent.floci.services.rds.model.DbSnapshot; @@ -56,6 +58,7 @@ import io.github.hectorvent.floci.services.secretsmanager.model.Secret; import io.github.hectorvent.floci.testutil.LogCapture; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.function.Executable; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; import org.junit.jupiter.params.provider.ValueSource; @@ -67,6 +70,7 @@ import java.time.Duration; import java.time.Instant; import java.util.Collection; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Optional; @@ -10343,4 +10347,291 @@ class RdsServiceTest { rdsService.deleteDbInstance("writer"); assertEquals("reader", rdsService.getDbCluster("aurora").resolveWriterIdentifier()); } + + // ── DB proxy endpoints ──────────────────────────────────────────────────── + + private DbProxy proxyForEndpoints(String name, String engineFamily) { + return rdsService.createDbProxy(name, engineFamily, true, false, PROXY_ROLE_ARN, + PROXY_SUBNET_IDS, List.of("sg-proxy"), PROXY_AUTH, Map.of()); + } + + private DbProxyEndpoint addProxyEndpoint(String proxyName, String endpointName, String targetRole) { + return rdsService.createDbProxyEndpoint("us-east-1", proxyName, endpointName, PROXY_SUBNET_IDS, + List.of("sg-endpoint"), targetRole, null, Map.of()); + } + + private static List endpointNames(RdsService.ProxyEndpointPage page) { + return page.endpoints().stream().map(DbProxyEndpoint::getDbProxyEndpointName).toList(); + } + + @Test + void proxyEndpointIsCreatedDescribedRenamedAndDeleted() { + DbProxy proxy = proxyForEndpoints("app-proxy", "POSTGRESQL"); + + DbProxyEndpoint reader = rdsService.createDbProxyEndpoint("us-east-1", "app-proxy", "reader", + PROXY_SUBNET_IDS, List.of("sg-endpoint"), "READ_ONLY", null, Map.of("team", "data")); + assertEquals("READ_ONLY", reader.getTargetRole()); + assertEquals("available", reader.getStatus()); + assertEquals("IPV4", reader.getEndpointNetworkType()); + assertEquals(proxy.getEndpoint(), reader.getEndpoint()); + assertEquals(proxy.getVpcId(), reader.getVpcId()); + assertFalse(reader.isDefault()); + assertTrue(reader.getDbProxyEndpointArn() + .startsWith("arn:aws:rds:us-east-1:123456789012:db-proxy-endpoint:prx-endpoint-")); + + RdsService.ProxyEndpointPage page = rdsService.describeDbProxyEndpoints("us-east-1", "app-proxy", null, + null, null); + assertEquals(List.of("default", "reader"), endpointNames(page)); + DbProxyEndpoint byDefault = page.endpoints().get(0); + assertTrue(byDefault.isDefault()); + assertEquals("READ_WRITE", byDefault.getTargetRole()); + assertNull(byDefault.getDbProxyEndpointArn()); + assertEquals(proxy.getEndpoint(), byDefault.getEndpoint()); + assertEquals(List.of("sg-proxy"), byDefault.getVpcSecurityGroupIds()); + assertNull(page.marker()); + + DbProxyEndpoint renamed = rdsService.modifyDbProxyEndpoint("us-east-1", "reader", "analytics", + List.of("sg-other")); + assertEquals("analytics", renamed.getDbProxyEndpointName()); + assertEquals(List.of("sg-other"), renamed.getVpcSecurityGroupIds()); + assertEquals(reader.getDbProxyEndpointArn(), renamed.getDbProxyEndpointArn()); + AwsException oldName = assertThrows(AwsException.class, + () -> rdsService.describeDbProxyEndpoints("us-east-1", null, "reader", null, null)); + assertEquals("DBProxyEndpointNotFoundFault", oldName.getErrorCode()); + + // Leaving the security groups out keeps them. + assertEquals(List.of("sg-other"), rdsService.modifyDbProxyEndpoint("us-east-1", "analytics", null, null) + .getVpcSecurityGroupIds()); + + assertEquals("deleting", rdsService.deleteDbProxyEndpoint("us-east-1", "analytics").getStatus()); + assertEquals(List.of("default"), endpointNames( + rdsService.describeDbProxyEndpoints("us-east-1", "app-proxy", null, null, null))); + AwsException gone = assertThrows(AwsException.class, + () -> rdsService.deleteDbProxyEndpoint("us-east-1", "analytics")); + assertEquals("DBProxyEndpointNotFoundFault", gone.getErrorCode()); + } + + /** + * A restore can bring a proxy back on a new host. Every endpoint follows it, not only the + * default one built from the proxy. + */ + @Test + void proxyEndpointsReportTheProxysHostAfterARestoreMovesIt() { + InMemoryStorage proxies = new InMemoryStorage<>(); + RdsService service = proxyStoreService(regionResolver, config, proxies, new InMemoryStorage<>(), + new InMemoryStorage<>(), new InMemoryStorage<>()); + service.createDbProxy("app-proxy", "POSTGRESQL", true, false, PROXY_ROLE_ARN, PROXY_SUBNET_IDS, + List.of(), PROXY_AUTH, Map.of()); + service.createDbProxyEndpoint("us-east-1", "app-proxy", "reader", PROXY_SUBNET_IDS, List.of(), + "READ_ONLY", null, Map.of()); + + // Each step moves the proxy to a new host first, so no answer can carry an earlier one. + moveProxyHost(proxies, "us-east-1::app-proxy", "proxy-restored-1.internal"); + RdsService.ProxyEndpointPage page = service.describeDbProxyEndpoints("us-east-1", "app-proxy", null, + null, null); + assertEquals(List.of("proxy-restored-1.internal", "proxy-restored-1.internal"), + page.endpoints().stream().map(DbProxyEndpoint::getEndpoint).toList()); + moveProxyHost(proxies, "us-east-1::app-proxy", "proxy-restored-2.internal"); + assertEquals("proxy-restored-2.internal", service.modifyDbProxyEndpoint("us-east-1", "reader", null, null) + .getEndpoint()); + moveProxyHost(proxies, "us-east-1::app-proxy", "proxy-restored-3.internal"); + assertEquals("proxy-restored-3.internal", service.deleteDbProxyEndpoint("us-east-1", "reader").getEndpoint()); + } + + private static void moveProxyHost(InMemoryStorage proxies, String key, String host) { + DbProxy restored = proxies.get(key).orElseThrow(); + restored.setEndpointHost(host); + proxies.put(key, restored); + } + + /** A missing required member is MissingParameter, checked before any lookup, and changes nothing. */ + @Test + void proxyEndpointRequiredMembersAreMissingParameter() { + proxyForEndpoints("app-proxy", "POSTGRESQL"); + addProxyEndpoint("app-proxy", "kept", null); + + List> missing = List.of( + Map.entry("DBProxyName", () -> rdsService.createDbProxyEndpoint("us-east-1", null, "ep", + PROXY_SUBNET_IDS, List.of(), null, null, Map.of())), + Map.entry("DBProxyEndpointName", () -> rdsService.createDbProxyEndpoint("us-east-1", "app-proxy", + "", PROXY_SUBNET_IDS, List.of(), null, null, Map.of())), + Map.entry("VpcSubnetIds", () -> rdsService.createDbProxyEndpoint("us-east-1", "app-proxy", "ep", + List.of(), List.of(), null, null, Map.of())), + // Reported as missing before the unknown proxy is looked up. + Map.entry("VpcSubnetIds", () -> rdsService.createDbProxyEndpoint("us-east-1", "absent", "ep", + null, List.of(), null, null, Map.of())), + Map.entry("DBProxyEndpointName", () -> rdsService.modifyDbProxyEndpoint("us-east-1", null, + "renamed", List.of("sg-x"))), + Map.entry("DBProxyEndpointName", () -> rdsService.deleteDbProxyEndpoint("us-east-1", " "))); + for (Map.Entry c : missing) { + AwsException e = assertThrows(AwsException.class, c.getValue(), c.getKey()); + assertEquals("MissingParameter", e.getErrorCode(), c.getKey()); + assertEquals("The request must contain the parameter " + c.getKey() + ".", e.getMessage()); + assertEquals(400, e.getHttpStatus()); + } + assertEquals(List.of("default", "kept"), endpointNames( + rdsService.describeDbProxyEndpoints("us-east-1", "app-proxy", null, null, null))); + } + + @Test + void proxyEndpointRequestsAreCheckedAgainstTheModel() { + proxyForEndpoints("app-proxy", "POSTGRESQL"); + proxyForEndpoints("mssql-proxy", "SQLSERVER"); + addProxyEndpoint("app-proxy", "taken", null); + + Map refused = new LinkedHashMap<>(); + refused.put("DBProxyNotFoundFault", () -> addProxyEndpoint("absent", "ep", null)); + refused.put("InvalidParameterValue", () -> addProxyEndpoint("app-proxy", "1st", null)); + refused.put("DBProxyEndpointAlreadyExistsFault", () -> addProxyEndpoint("app-proxy", "taken", null)); + refused.put("InvalidParameterCombination", () -> addProxyEndpoint("mssql-proxy", "ro", "READ_ONLY")); + refused.put("InvalidSubnet", () -> rdsService.createDbProxyEndpoint("us-east-1", "app-proxy", "ep", + List.of("subnet-missing"), List.of(), null, null, Map.of())); + for (Map.Entry c : refused.entrySet()) { + assertEquals(c.getKey(), assertThrows(AwsException.class, c.getValue()).getErrorCode(), c.getKey()); + } + for (Executable invalid : List.of( + () -> addProxyEndpoint("app-proxy", "a--b", null), + () -> addProxyEndpoint("app-proxy", "ends-", null), + () -> addProxyEndpoint("app-proxy", "e".repeat(64), null), + () -> addProxyEndpoint("app-proxy", "ep", "WRITER"), + // The default VPC carries no IPv6 block, so an IPv6 endpoint cannot be placed in it. + () -> rdsService.createDbProxyEndpoint("us-east-1", "app-proxy", "ep", PROXY_SUBNET_IDS, + List.of(), null, "IPV6", Map.of()))) { + assertEquals("InvalidParameterValue", assertThrows(AwsException.class, invalid).getErrorCode()); + } + // An unknown network type is refused for what it is, before any VPC check. + AwsException networkType = assertThrows(AwsException.class, () -> rdsService.createDbProxyEndpoint( + "us-east-1", "app-proxy", "ep", PROXY_SUBNET_IDS, List.of(), null, "IPV5", Map.of())); + assertEquals("InvalidParameterValue", networkType.getErrorCode()); + assertTrue(networkType.getMessage().contains("EndpointNetworkType must be IPV4, IPV6, or DUAL"), + networkType.getMessage()); + // The name is the default endpoint's, which every proxy already has. + assertEquals("DBProxyEndpointAlreadyExistsFault", assertThrows(AwsException.class, + () -> addProxyEndpoint("app-proxy", "default", null)).getErrorCode()); + // Names are unique across the account's proxies, not per proxy. + assertEquals("DBProxyEndpointAlreadyExistsFault", assertThrows(AwsException.class, + () -> addProxyEndpoint("mssql-proxy", "taken", null)).getErrorCode()); + assertEquals("READ_WRITE", addProxyEndpoint("mssql-proxy", "rw", null).getTargetRole()); + } + + @Test + void aProxyHoldsAtMostTwentyEndpoints() { + proxyForEndpoints("app-proxy", "POSTGRESQL"); + for (int i = 1; i < 20; i++) { + addProxyEndpoint("app-proxy", "ep" + i, null); + } + addProxyEndpoint("app-proxy", "ep20", null); + AwsException full = assertThrows(AwsException.class, () -> addProxyEndpoint("app-proxy", "ep21", null)); + assertEquals("DBProxyEndpointQuotaExceededFault", full.getErrorCode()); + } + + @Test + void theDefaultProxyEndpointCannotBeChangedAndARenameCannotTakeAName() { + proxyForEndpoints("app-proxy", "POSTGRESQL"); + addProxyEndpoint("app-proxy", "first", null); + addProxyEndpoint("app-proxy", "second", null); + + assertEquals("InvalidDBProxyEndpointStateFault", assertThrows(AwsException.class, + () -> rdsService.modifyDbProxyEndpoint("us-east-1", "default", "renamed", null)).getErrorCode()); + assertEquals("InvalidDBProxyEndpointStateFault", assertThrows(AwsException.class, + () -> rdsService.deleteDbProxyEndpoint("us-east-1", "default")).getErrorCode()); + assertEquals("DBProxyEndpointAlreadyExistsFault", assertThrows(AwsException.class, + () -> rdsService.modifyDbProxyEndpoint("us-east-1", "first", "second", null)).getErrorCode()); + assertEquals("DBProxyEndpointAlreadyExistsFault", assertThrows(AwsException.class, + () -> rdsService.modifyDbProxyEndpoint("us-east-1", "first", "default", null)).getErrorCode()); + assertEquals("DBProxyEndpointNotFoundFault", assertThrows(AwsException.class, + () -> rdsService.modifyDbProxyEndpoint("us-east-1", "absent", null, null)).getErrorCode()); + assertEquals(List.of("default", "first", "second"), endpointNames( + rdsService.describeDbProxyEndpoints("us-east-1", "app-proxy", null, null, null))); + } + + @Test + void anEndpointOnAProxyThatIsNotAvailableIsRefused() { + InMemoryStorage proxies = new InMemoryStorage<>(); + rdsService = proxyStoreService(regionResolver, config, proxies, new InMemoryStorage<>(), + new InMemoryStorage<>(), new InMemoryStorage<>()); + proxyForEndpoints("app-proxy", "POSTGRESQL"); + addProxyEndpoint("app-proxy", "before", null); + String key = proxies.keys().iterator().next(); + DbProxy stored = proxies.get(key).orElseThrow(); + stored.setStatus("modifying"); + proxies.put(key, stored); + + assertEquals("InvalidDBProxyStateFault", assertThrows(AwsException.class, + () -> addProxyEndpoint("app-proxy", "ep", null)).getErrorCode()); + assertEquals("InvalidDBProxyStateFault", assertThrows(AwsException.class, + () -> rdsService.modifyDbProxyEndpoint("us-east-1", "before", "after", null)).getErrorCode()); + } + + @Test + void deletingAProxyDeletesItsEndpoints() { + proxyForEndpoints("proxy-a", "POSTGRESQL"); + proxyForEndpoints("proxy-b", "POSTGRESQL"); + addProxyEndpoint("proxy-a", "shared-name", null); + addProxyEndpoint("proxy-b", "b-endpoint", null); + + rdsService.deleteDbProxy("proxy-a", "us-east-1"); + + assertEquals(List.of("default", "b-endpoint"), endpointNames( + rdsService.describeDbProxyEndpoints("us-east-1", null, null, null, null))); + assertEquals("DBProxyEndpointNotFoundFault", assertThrows(AwsException.class, + () -> rdsService.deleteDbProxyEndpoint("us-east-1", "shared-name")).getErrorCode()); + // The deleted proxy's endpoint name is free again. + assertEquals("proxy-b", addProxyEndpoint("proxy-b", "shared-name", null).getDbProxyName()); + } + + @Test + void proxyEndpointsPageAndFilterByName() { + proxyForEndpoints("proxy-a", "POSTGRESQL"); + proxyForEndpoints("proxy-b", "POSTGRESQL"); + for (int i = 10; i < 30; i++) { + addProxyEndpoint("proxy-a", "a" + i, null); + } + for (int i = 10; i < 15; i++) { + addProxyEndpoint("proxy-b", "b" + i, null); + } + + RdsService.ProxyEndpointPage first = rdsService.describeDbProxyEndpoints("us-east-1", null, null, 20, null); + assertEquals(20, first.endpoints().size()); + assertEquals("default", first.endpoints().get(0).getDbProxyEndpointName()); + assertEquals("proxy-a", first.endpoints().get(0).getDbProxyName()); + assertNotNull(first.marker()); + RdsService.ProxyEndpointPage second = rdsService.describeDbProxyEndpoints("us-east-1", null, null, 20, + first.marker()); + assertEquals(List.of("a29", "default", "b10", "b11", "b12", "b13", "b14"), endpointNames(second)); + assertNull(second.marker()); + + assertEquals(List.of("b12"), endpointNames( + rdsService.describeDbProxyEndpoints("us-east-1", null, "b12", null, null))); + assertEquals("DBProxyEndpointNotFoundFault", assertThrows(AwsException.class, + () -> rdsService.describeDbProxyEndpoints("us-east-1", "proxy-a", "b12", null, null)) + .getErrorCode()); + assertEquals("DBProxyNotFoundFault", assertThrows(AwsException.class, + () -> rdsService.describeDbProxyEndpoints("us-east-1", "absent", null, null, null)).getErrorCode()); + assertEquals("InvalidParameterValue", assertThrows(AwsException.class, + () -> rdsService.describeDbProxyEndpoints("us-east-1", null, null, 19, null)).getErrorCode()); + } + + @Test + void proxyEndpointTagsRoundTripAndItDefaultsToTheVpcsDefaultSecurityGroup() { + DbProxy proxy = proxyForEndpoints("app-proxy", "POSTGRESQL"); + SecurityGroup defaultGroup = new SecurityGroup(); + defaultGroup.setGroupId("sg-vpc-default"); + defaultGroup.setGroupName("default"); + SecurityGroup otherGroup = new SecurityGroup(); + otherGroup.setGroupId("sg-vpc-other"); + otherGroup.setGroupName("other"); + when(ec2Service.getSecurityGroupsForVpc("us-east-1", proxy.getVpcId(), Map.of())) + .thenReturn(List.of(otherGroup, defaultGroup)); + + DbProxyEndpoint endpoint = rdsService.createDbProxyEndpoint("us-east-1", "app-proxy", "ep", + PROXY_SUBNET_IDS, List.of(), null, null, Map.of("env", "dev")); + assertEquals(List.of("sg-vpc-default"), endpoint.getVpcSecurityGroupIds()); + + String arn = endpoint.getDbProxyEndpointArn(); + assertEquals(Map.of("env", "dev"), rdsService.listTagsForResource(arn)); + rdsService.addTagsToResource(arn, Map.of("team", "data")); + rdsService.removeTagsFromResource(arn, List.of("env")); + assertEquals(Map.of("team", "data"), rdsService.listTagsForResource(arn)); + } }