feat(route53resolver): implement ListResolverEndpointIpAddresses (#5731)

* feat(route53resolver): implement ListResolverEndpointIpAddresses

The Terraform provider lists an endpoint's IP addresses right after
CreateResolverEndpoint, so the missing operation (UnknownOperationException)
failed every aws_route53_resolver_endpoint create.

Built from the IpAddresses recorded at create time: one ATTACHED entry per
request with a deterministic rni- IpId. Unknown endpoint ids raise
ResourceNotFoundException. Not paginated, like the sibling List operations.

* docs(route53resolver): update service matrix operation count

* refactor(route53resolver): add endpoint IP addresses with a single addAll

* fix(route53resolver): distinct IpIds for repeated entries; fail on missing IP record

ListResolverEndpointIpAddresses hashed only the endpoint id and the entry,
so two identical entries (two addresses in one subnet, both left for AWS to
pick, which IpAddressesRequest allows) shared an IpId. Include the entry's
position in the recorded list, which is normalised once at create and so
stable across reads.

An endpoint whose recorded IP requests are missing returned an empty list
beside a nonzero IpAddressCount. Throw the modeled
InternalServiceErrorException instead.

* test(route53resolver): import List/HashSet instead of fully qualifying (checkstyle NoFqcn)

* fix(route53resolver): return InternalServiceErrorException as HTTP 400

The Route 53 Resolver model gives InternalServiceErrorException no
httpStatusCode, so clients expect the awsJson default of 400, as with
every other Resolver error.
This commit is contained in:
Allen Sanborn authored and GitHub committed 2026-10-15 16:44:58 -04:00
1 parent 5544a119d3
commit a37c27516a
6 files changed
+161 -2

No files matched your search

+1 -1
View File
@@ -125,7 +125,7 @@ Operation counts are exact. For dispatch-table services (Query and JSON 1.1) eac
| [CodeArtifact](codeartifact.md) | `/v1/domain*`, `/v1/repository*`, `/v1/package`, `/v1/package/version*`, `/v1/tag*`, `/v1/authorization-token`, `/codeartifact/maven/*`, `/codeartifact/npm/*`, `/codeartifact/pypi/*` | REST JSON | 30 |
| [CloudFront](cloudfront.md) | `/2020-05-31/distribution/*`, `/2020-05-31/cache-policy/*`, `/2020-05-31/function/*` | REST XML | 50 |
| [Route53](route53.md) | `/2013-04-01/hostedzone/*`, `/2013-04-01/healthcheck/*`, `/2013-04-01/change/*` | REST XML | 27 |
| [Route 53 Resolver](route53resolver.md) | `POST /` + `X-Amz-Target: Route53Resolver.*` | JSON 1.1 | 18 |
| [Route 53 Resolver](route53resolver.md) | `POST /` + `X-Amz-Target: Route53Resolver.*` | JSON 1.1 | 19 |
| [Amazon SageMaker](sagemaker.md) | `POST /` + `X-Amz-Target: SageMaker.*` | JSON 1.1 | 20 |
| [SageMaker Runtime](sagemaker.md#endpoint-hosting) | `/endpoints/{EndpointName}/invocations` | REST (binary payload) | 1 |
| [Cloud Map](cloudmap.md) | `POST /` + `X-Amz-Target: Route53AutoNaming_v20170314.*` | JSON 1.1 | 22 |
+1
View File
@@ -13,6 +13,7 @@
| `DeleteResolverEndpoint` | Deletes a resolver endpoint and returns its final description. |
| `GetResolverEndpoint` | Returns a resolver endpoint by id. |
| `ListResolverEndpoints` | Lists all resolver endpoints. |
| `ListResolverEndpointIpAddresses` | Lists a resolver endpoint's IP addresses from those it was created with, each `ATTACHED`; an address left for AWS to choose has no `Ip`. Not paginated. |
| `UpdateResolverEndpoint` | Updates a resolver endpoint's `Name` and `ResolverEndpointType`; `IpAddresses` changes are not modelled. |
| `CreateResolverRule` | Creates a resolver rule, returned immediately as `COMPLETE`; `ResolverEndpointId` is not validated against an existing endpoint. |
| `DeleteResolverRule` | Deletes a resolver rule and returns its final description. |
@@ -50,6 +50,8 @@ public class Route53ResolverJsonHandler {
case "GetResolverEndpoint" -> resolverEndpointResponse(
service.getResolverEndpoint(text(request, "ResolverEndpointId")));
case "ListResolverEndpoints" -> handleListResolverEndpoints();
case "ListResolverEndpointIpAddresses" -> handleListResolverEndpointIpAddresses(
text(request, "ResolverEndpointId"));
case "UpdateResolverEndpoint" -> resolverEndpointResponse(
service.updateResolverEndpoint(text(request, "ResolverEndpointId"), request));
@@ -144,6 +146,12 @@ public class Route53ResolverJsonHandler {
return Response.ok(result).build();
}
private Response handleListResolverEndpointIpAddresses(String endpointId) {
ObjectNode result = objectMapper.createObjectNode();
result.putArray("IpAddresses").addAll(service.listResolverEndpointIpAddresses(endpointId));
return Response.ok(result).build();
}
// ---------- Resolver rules ----------
private Response resolverRuleResponse(ObjectNode rule) {
@@ -83,7 +83,7 @@ public class Route53ResolverService {
* Kept beside the endpoint rather than on it: the modeled {@code ResolverEndpoint} shape
* carries {@code IpAddressCount} and no IP list, and the handlers return the stored node
* verbatim, so holding the addresses on the resource would put an unmodeled member on the
* wire. Only the CreatorRequestId conflict check reads this.
* wire. Read by the CreatorRequestId conflict check and ListResolverEndpointIpAddresses.
*/
private final StorageBackend<String, ObjectNode> endpointIpRequestStore;
private final ObjectMapper objectMapper;
@@ -239,6 +239,39 @@ public class Route53ResolverService {
return endpointStore.scan(key -> true).stream().map(ObjectNode::deepCopy).toList();
}
/**
* The endpoint's addresses as AWS {@code IpAddressResponse} entries, built from the
* {@code IpAddresses} recorded at create time. {@code IpId} is derived from the endpoint,
* the entry and its position in the recorded list, so it is stable across calls. An
* address the request left for AWS to pick has no {@code Ip}: Floci does not allocate
* from the subnet.
*/
public List<ObjectNode> listResolverEndpointIpAddresses(String id) {
ObjectNode endpoint = require(endpointStore, id, "resolver endpoint");
// A missing record would otherwise read as an empty list beside a nonzero
// IpAddressCount; fail loudly with the modeled InternalServiceErrorException instead.
JsonNode recorded = endpointIpRequestStore.get(id)
.map(node -> node.get("IpAddressRequests"))
.filter(JsonNode::isArray)
.orElseThrow(() -> new AwsException("InternalServiceErrorException",
"No IP addresses recorded for resolver endpoint: " + id, 400));
List<ObjectNode> addresses = new ArrayList<>();
for (int i = 0; i < recorded.size(); i++) {
JsonNode request = recorded.get(i);
ObjectNode address = objectMapper.createObjectNode();
// The index keeps repeated entries (two addresses in one subnet, both left for AWS
// to pick) distinct; the stored list is normalised once at create, so it is stable.
address.put("IpId", "rni-" + deterministicHex(id + "|" + i + "|" + canonicalKey(request), 17));
copyIfPresent(request, address, "SubnetId", "Ip", "Ipv6");
address.put("Status", "ATTACHED");
address.put("StatusMessage", "This IP address is operational.");
address.set("CreationTime", endpoint.get("CreationTime"));
address.set("ModificationTime", endpoint.get("CreationTime"));
addresses.add(address);
}
return addresses;
}
public ObjectNode updateResolverEndpoint(String id, JsonNode request) {
ObjectNode endpoint = require(endpointStore, id, "resolver endpoint");
String endpointType = text(request, "ResolverEndpointType");
@@ -5,10 +5,18 @@ import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.util.HashSet;
import java.util.List;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.everyItem;
import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Integration tests for Route 53 Resolver DNS Firewall operations
@@ -166,6 +174,100 @@ class Route53ResolverIntegrationTest {
.body("message", equalTo("IpAddresses is required"));
}
// ── ListResolverEndpointIpAddresses ─────────────────────────────────────────
//
// The Terraform provider calls this right after CreateResolverEndpoint to read the
// endpoint's ip_address set, so an unimplemented operation fails every endpoint create.
private static String listIpAddresses(String endpointId) {
return given()
.contentType(CONTENT_TYPE)
.header("X-Amz-Target", "Route53Resolver.ListResolverEndpointIpAddresses")
.header("Authorization", AUTH_HEADER)
.body("{\"ResolverEndpointId\":\"" + endpointId + "\"}")
.when()
.post("/")
.then()
.statusCode(200)
.extract().asString();
}
@Test
void listResolverEndpointIpAddresses_returnsTheAddressesTheEndpointWasCreatedWith() {
String endpointId = given()
.contentType(CONTENT_TYPE)
.header("X-Amz-Target", "Route53Resolver.CreateResolverEndpoint")
.header("Authorization", AUTH_HEADER)
.body("{\"Name\":\"ep-ips\",\"Direction\":\"OUTBOUND\",\"CreatorRequestId\":\"list-ips-1\","
+ "\"SecurityGroupIds\":[\"sg-abc123\"],"
+ "\"IpAddresses\":[{\"SubnetId\":\"subnet-aaa\",\"Ip\":\"10.0.1.10\"},"
+ "{\"SubnetId\":\"subnet-bbb\"}]}")
.when()
.post("/")
.then()
.statusCode(200)
.extract().path("ResolverEndpoint.Id");
given()
.contentType(CONTENT_TYPE)
.header("X-Amz-Target", "Route53Resolver.ListResolverEndpointIpAddresses")
.header("Authorization", AUTH_HEADER)
.body("{\"ResolverEndpointId\":\"" + endpointId + "\"}")
.when()
.post("/")
.then()
.statusCode(200)
.body("IpAddresses.size()", equalTo(2))
.body("IpAddresses.SubnetId", containsInAnyOrder("subnet-aaa", "subnet-bbb"))
.body("IpAddresses.find { it.SubnetId == 'subnet-aaa' }.Ip", equalTo("10.0.1.10"))
.body("IpAddresses.find { it.SubnetId == 'subnet-bbb' }.Ip", nullValue())
.body("IpAddresses.Status", everyItem(equalTo("ATTACHED")))
.body("IpAddresses.IpId", everyItem(startsWith("rni-")))
.body("IpAddresses.CreationTime", everyItem(notNullValue()));
// IpId is the provider's handle on each address, so it must not change between reads.
assertEquals(listIpAddresses(endpointId), listIpAddresses(endpointId));
}
@Test
void listResolverEndpointIpAddresses_repeatedEntriesGetDistinctStableIds() {
// Two addresses in one subnet, both left for AWS to pick, is a valid request: the
// model's IpAddressesRequest is a plain list with no uniqueness constraint. Each is a
// separate address, so each needs its own IpId.
String endpointId = given()
.contentType(CONTENT_TYPE)
.header("X-Amz-Target", "Route53Resolver.CreateResolverEndpoint")
.header("Authorization", AUTH_HEADER)
.body("{\"Name\":\"ep-dup-ips\",\"Direction\":\"INBOUND\",\"CreatorRequestId\":\"list-ips-dup\","
+ "\"SecurityGroupIds\":[\"sg-abc123\"],"
+ "\"IpAddresses\":[{\"SubnetId\":\"subnet-aaa\"},{\"SubnetId\":\"subnet-aaa\"}]}")
.when()
.post("/")
.then()
.statusCode(200)
.extract().path("ResolverEndpoint.Id");
String first = listIpAddresses(endpointId);
List<String> ids = io.restassured.path.json.JsonPath.from(first).getList("IpAddresses.IpId");
assertEquals(2, ids.size());
assertEquals(2, new HashSet<>(ids).size(), "repeated entries share an IpId: " + ids);
assertEquals(first, listIpAddresses(endpointId));
}
@Test
void listResolverEndpointIpAddresses_unknownEndpoint_returnsResourceNotFound() {
given()
.contentType(CONTENT_TYPE)
.header("X-Amz-Target", "Route53Resolver.ListResolverEndpointIpAddresses")
.header("Authorization", AUTH_HEADER)
.body("{\"ResolverEndpointId\":\"rslvr-in-doesnotexist\"}")
.when()
.post("/")
.then()
.statusCode(400)
.body("__type", equalTo("ResourceNotFoundException"));
}
// ── CreateResolverEndpoint: IpAddresses is min 2 / max 20 ──────────────────
//
// The request shape models IpAddresses as min 2 / max 20, so a resolver endpoint
@@ -86,6 +86,21 @@ class Route53ResolverReplayFallbackTest {
assertEquals("ResourceExistsException", conflict.jsonType());
}
@Test
void listingIpAddressesWithoutARecordFailsInsteadOfReturningEmpty() {
// An empty list beside IpAddressCount=2 would be a silent wrong answer; the modeled
// InternalServiceErrorException says the state is broken.
ObjectNode created = service.createResolverEndpoint(createRequest("tok-list", "10.0.0.5"), REGION, ACCOUNT);
String id = created.get("Id").asText();
assertEquals(2, service.listResolverEndpointIpAddresses(id).size());
endpointIpRequests.delete(id);
AwsException broken = assertThrows(AwsException.class,
() -> service.listResolverEndpointIpAddresses(id));
assertEquals("InternalServiceErrorException", broken.jsonType());
assertEquals(400, broken.getHttpStatus());
}
@Test
void anIntactRecordStillReplaysAnIdenticalRequest() {
// Guard against over-correcting: the ordinary path must stay idempotent.