feat(route53resolver): list resolver DNSSEC configs (#9040)

ListResolverDnssecConfigs answered UnknownOperationException, which broke
the Terraform DNSSEC resource right after UpdateResolverDnssecConfig
succeeded: the provider waits for the resource by listing the
configurations. The service now returns the region's DNSSEC configs under
the documented ResolverDnssecConfigs member, leaving out disabled ones as
the model says.

The list matches its Filters the way ListResolverRules does and pages by
MaxResults (1 to 100, defaulting to 100) and NextToken, refusing an
invalid token with the modeled InvalidNextTokenException. The filter and
paging checks are one helper each, shared with ListResolverRules and
ListTagsForResource.

Closes #9012

Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com>
This commit is contained in:
Matheus Oliveira authored and GitHub committed 2026-11-23 07:37:50 -04:00
1 parent c15e1e26ce
commit 8a9fa27575
6 files changed
+290 -64

No files matched your search

+1 -1
View File
@@ -151,7 +151,7 @@ Operation counts are exact. For dispatch-table services (Query and JSON 1.1) eac
| [CloudFront](cloudfront.md) | `/2020-05-31/distribution/*`, `/2020-05-31/cache-policy/*`, `/2020-05-31/function/*`, `/2020-05-31/key-value-store/*` | REST XML | 97 |
| [CloudFront KeyValueStore](cloudfront.md#key-value-stores) | `/key-value-stores/*` | REST JSON | 6 |
| [Route53](route53.md) | `/2013-04-01/hostedzone/*`, `/2013-04-01/healthcheck/*`, `/2013-04-01/change/*`, `/2013-04-01/delegationset/*` | REST XML | 31 |
| [Route 53 Resolver](route53resolver.md) | `POST /` + `X-Amz-Target: Route53Resolver.*` | JSON 1.1 | 24 |
| [Route 53 Resolver](route53resolver.md) | `POST /` + `X-Amz-Target: Route53Resolver.*` | JSON 1.1 | 25 |
| [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
@@ -26,6 +26,7 @@
| `ListResolverRuleAssociations` | Lists all resolver rule associations. |
| `UpdateResolverDnssecConfig` | Creates or updates a VPC's DNSSEC validation configuration and returns its terminal validation status. |
| `GetResolverDnssecConfig` | Returns a stable DNSSEC validation configuration for an existing VPC, defaulting to `DISABLED` before its first update. |
| `ListResolverDnssecConfigs` | Lists the region's DNSSEC validation configurations, leaving out disabled ones, filtered by `Filters` and paginated by `MaxResults` (default and maximum 100) and `NextToken`. |
| `TagResource` | Adds or overwrites tags on a resolver endpoint, resolver rule or custom firewall domain list, by ARN. |
| `UntagResource` | Removes tag keys from a resolver endpoint, resolver rule or custom firewall domain list; absent keys are ignored. |
| `ListTagsForResource` | Lists a resource's tags, paginated by `MaxResults` (default and maximum 100) and `NextToken`. |
@@ -78,6 +78,9 @@ public class Route53ResolverJsonHandler {
request, region, accountId));
case "GetResolverDnssecConfig" -> dnssecConfigResponse(service.getResolverDnssecConfig(
text(request, "ResourceId"), region));
case "ListResolverDnssecConfigs" -> Response.ok(service.listResolverDnssecConfigs(
request.get("Filters"), request.get("MaxResults"), text(request, "NextToken"),
region)).build();
case "TagResource" -> {
service.tagResource(text(request, "ResourceArn"), request.get("Tags"), region, accountId);
@@ -32,6 +32,8 @@ import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.function.Predicate;
/**
@@ -79,6 +81,13 @@ public class Route53ResolverService {
"status", "Status",
"type", "RuleType");
/** The config fields the DNSSEC listing filters on, keyed as the normalized filter name. */
private static final Map<String, String> DNSSEC_FILTER_FIELDS = Map.of(
"id", "Id",
"ownerid", "OwnerId",
"resourceid", "ResourceId",
"validationstatus", "ValidationStatus");
/** The AWS-managed domain lists available in commercial regions. */
static final List<String> AWS_MANAGED_DOMAIN_LIST_NAMES = List.of(
"AWSManagedDomainsAggregateThreatList",
@@ -564,48 +573,7 @@ public class Route53ResolverService {
* ({@code CREATOR_REQUEST_ID}); a name the operation does not list filters nothing.
*/
public List<ObjectNode> listResolverRules(JsonNode filters, String region) {
List<ObjectNode> rules = recordsIn(ruleStore, region);
if (filters == null || filters.isNull()) {
return rules;
}
if (!filters.isArray()) {
throw new AwsException(INVALID_PARAMETER, "Filters must be a list of filters.", 400);
}
for (JsonNode filter : filters) {
if (!filter.isObject()) {
throw new AwsException(INVALID_PARAMETER, "Filters must be a list of filters.", 400);
}
String name = filter.path("Name").asText("");
if (name.isEmpty() || name.length() > 64) {
throw new AwsException(INVALID_PARAMETER, "Filter Name must be 1 to 64 characters long.", 400);
}
JsonNode filterValues = filter.path("Values");
if (!filterValues.isMissingNode() && !filterValues.isNull() && !filterValues.isArray()) {
throw new AwsException(INVALID_PARAMETER, "Filter Values must be a list of strings.", 400);
}
List<String> values = new ArrayList<>();
for (JsonNode value : filterValues) {
if (!value.isTextual()) {
throw new AwsException(INVALID_PARAMETER, "Filter Values must be a list of strings.", 400);
}
if (value.asText().isEmpty() || value.asText().length() > 600) {
throw new AwsException(INVALID_PARAMETER, "Filter Values must be 1 to 600 characters long.", 400);
}
values.add(value.asText());
}
String field = RULE_FILTER_FIELDS.get(name.replace("_", "").toLowerCase(Locale.ROOT));
if (field == null) {
continue;
}
boolean domain = "DomainName".equals(field);
rules = rules.stream()
.filter(rule -> values.stream().anyMatch(value -> domain
? DnsLookupHelper.normalizeTarget(value)
.equalsIgnoreCase(DnsLookupHelper.normalizeTarget(text(rule, field)))
: value.equals(text(rule, field))))
.toList();
}
return rules;
return filtered(recordsIn(ruleStore, region), filters, RULE_FILTER_FIELDS, "DomainName"::equals);
}
public ObjectNode updateResolverRule(String id, JsonNode config, String region) {
@@ -696,6 +664,22 @@ public class Route53ResolverService {
}).deepCopy();
}
/**
* One page of the region's DNSSEC validation configurations, filtered as {@link #listResolverRules}
* filters rules. A disabled configuration is left out, as the model says the response "doesn't contain
* disabled DNSSEC configurations": that covers a VPC only ever read through
* {@link #getResolverDnssecConfig} and one updated to {@code DISABLE}. The page cursor is the config id.
*/
public synchronized ObjectNode listResolverDnssecConfigs(JsonNode filters, JsonNode maxResults,
String nextToken, String region) {
List<ObjectNode> configs = dnssecConfigStore.scan(key -> key.startsWith(region + "::")).stream()
.filter(config -> !"DISABLED".equals(text(config, "ValidationStatus")))
.map(ObjectNode::deepCopy).toList();
List<ObjectNode> matching = filtered(configs, filters, DNSSEC_FILTER_FIELDS, field -> false);
return page(matching, config -> text(config, "Id"), pageSize(maxResults), nextToken, "dnssec-configs",
"ResolverDnssecConfigs", ArrayNode::add);
}
private Vpc requireDnssecVpc(String resourceId, String region) {
if (ec2Service == null) {
return null;
@@ -813,10 +797,8 @@ public class Route53ResolverService {
}
/**
* One page of a resource's tags as modeled {@code Tag} entries, paged by
* {@link Pagination#paginate} on the tag key; {@code MaxResults} defaults to the modeled 100.
* {@code MaxResults} arrives as a JSON value, so it is type-checked here rather than parsed
* from a string: {@code 1.5}, {@code true} and {@code "1"} are not the modeled integer.
* One page of a resource's tags as modeled {@code Tag} entries, paged on the tag key, with
* {@code MaxResults} read by {@link #pageSize}.
*
* <p>The stored tag node is copied under the monitor {@link #tagResource} and
* {@link #untagResource} mutate it under, so a concurrent tag change can neither break the
@@ -824,11 +806,7 @@ public class Route53ResolverService {
*/
public ObjectNode listTagsForResource(String arn, JsonNode maxResults, String nextToken,
String region, String accountId) {
boolean absent = maxResults == null || maxResults.isNull();
if (!absent && (!maxResults.isIntegralNumber() || !maxResults.canConvertToInt()
|| maxResults.intValue() < 1 || maxResults.intValue() > 100)) {
throw new AwsException(INVALID_PARAMETER, "MaxResults must be an integer between 1 and 100", 400);
}
int pageSize = pageSize(maxResults);
ObjectNode snapshot;
synchronized (this) {
requireTaggable(arn, region, accountId);
@@ -838,18 +816,8 @@ public class Route53ResolverService {
if (snapshot != null) {
snapshot.fields().forEachRemaining(all::add);
}
PaginatedResult<Map.Entry<String, JsonNode>> paged = Pagination.paginate(all, Map.Entry::getKey,
absent ? 100 : maxResults.intValue(), nextToken, "tags",
token -> new AwsException("InvalidNextTokenException", "Invalid NextToken: " + token, 400));
ObjectNode result = objectMapper.createObjectNode();
ArrayNode page = result.putArray("Tags");
for (Map.Entry<String, JsonNode> tag : paged.items()) {
page.addObject().put("Key", tag.getKey()).set("Value", tag.getValue());
}
if (paged.nextToken() != null) {
result.put("NextToken", paged.nextToken());
}
return result;
return page(all, Map.Entry::getKey, pageSize, nextToken, "tags", "Tags",
(tags, tag) -> tags.addObject().put("Key", tag.getKey()).set("Value", tag.getValue()));
}
/**
@@ -1133,6 +1101,94 @@ public class Route53ResolverService {
.map(ObjectNode::deepCopy).toList();
}
/**
* The records matching every filter of {@code filters}, a record matching a filter when its field equals any of
* the filter's values. A filter name is read case-insensitively and without underscores, so the legacy
* upper-case form ({@code CREATOR_REQUEST_ID}) works too, and a name {@code fields} does not list filters
* nothing. A field {@code domainField} accepts compares as a domain name.
*/
private List<ObjectNode> filtered(List<ObjectNode> records, JsonNode filters, Map<String, String> fields,
Predicate<String> domainField) {
if (filters == null || filters.isNull()) {
return records;
}
if (!filters.isArray()) {
throw new AwsException(INVALID_PARAMETER, "Filters must be a list of filters.", 400);
}
List<ObjectNode> matching = records;
for (JsonNode filter : filters) {
if (!filter.isObject()) {
throw new AwsException(INVALID_PARAMETER, "Filters must be a list of filters.", 400);
}
String name = filter.path("Name").asText("");
if (name.isEmpty() || name.length() > 64) {
throw new AwsException(INVALID_PARAMETER, "Filter Name must be 1 to 64 characters long.", 400);
}
JsonNode filterValues = filter.path("Values");
if (!filterValues.isMissingNode() && !filterValues.isNull() && !filterValues.isArray()) {
throw new AwsException(INVALID_PARAMETER, "Filter Values must be a list of strings.", 400);
}
List<String> values = new ArrayList<>();
for (JsonNode value : filterValues) {
if (!value.isTextual()) {
throw new AwsException(INVALID_PARAMETER, "Filter Values must be a list of strings.", 400);
}
if (value.asText().isEmpty() || value.asText().length() > 600) {
throw new AwsException(INVALID_PARAMETER, "Filter Values must be 1 to 600 characters long.", 400);
}
values.add(value.asText());
}
String field = fields.get(name.replace("_", "").toLowerCase(Locale.ROOT));
if (field == null) {
continue;
}
boolean domain = domainField.test(field);
matching = matching.stream()
.filter(record -> values.stream().anyMatch(value -> domain
? DnsLookupHelper.normalizeTarget(value)
.equalsIgnoreCase(DnsLookupHelper.normalizeTarget(text(record, field)))
: value.equals(text(record, field))))
.toList();
}
return matching;
}
/**
* {@code MaxResults} as a page size: the modeled 100 when absent. It arrives as a JSON value, so it is
* type-checked rather than parsed from a string: {@code 1.5}, {@code true} and {@code "1"} are not the modeled
* integer.
*/
private static int pageSize(JsonNode maxResults) {
if (maxResults == null || maxResults.isNull()) {
return 100;
}
if (!maxResults.isIntegralNumber() || !maxResults.canConvertToInt()
|| maxResults.intValue() < 1 || maxResults.intValue() > 100) {
throw new AwsException(INVALID_PARAMETER, "MaxResults must be an integer between 1 and 100", 400);
}
return maxResults.intValue();
}
/**
* One page of {@code items} under {@code member}, cursored by {@code cursor} through {@link Pagination#paginate},
* with a {@code NextToken} only when another page remains. An invalid token is the modeled
* {@code InvalidNextTokenException}.
*/
private <T> ObjectNode page(List<T> items, Function<T, String> cursor, int pageSize, String nextToken,
String namespace, String member, BiConsumer<ArrayNode, T> write) {
PaginatedResult<T> paged = Pagination.paginate(items, cursor, pageSize, nextToken, namespace,
token -> new AwsException("InvalidNextTokenException", "Invalid NextToken: " + token, 400));
ObjectNode result = objectMapper.createObjectNode();
ArrayNode page = result.putArray(member);
for (T item : paged.items()) {
write.accept(page, item);
}
if (paged.nextToken() != null) {
result.put("NextToken", paged.nextToken());
}
return result;
}
/**
* Whether a stored record belongs to {@code region}. The stores carry no Region in their keys, so it comes from the
* ARN this service minted for the record, read as {@link #resolverRuleIn} reads a rule's on the DNS path, and for a
@@ -1,15 +1,25 @@
package io.floci.aws.services.route53resolver;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.floci.aws.core.common.AwsException;
import io.floci.aws.core.storage.InMemoryStorage;
import org.junit.jupiter.api.Test;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
class Route53ResolverDnssecStorageTest {
private static final ObjectMapper MAPPER = new ObjectMapper();
private static final String ACCOUNT_ID = "000000000000";
@Test
void failedUpdatePreservesStoredValidationStatus() {
ObjectMapper objectMapper = new ObjectMapper();
@@ -42,4 +52,94 @@ class Route53ResolverDnssecStorageTest {
assertEquals("ENABLED", service.getResolverDnssecConfig(vpcId, region)
.path("ValidationStatus").asText());
}
@Test
void listResolverDnssecConfigs_returnsOnlyTheRegionsConfigs() {
Route53ResolverService service = service();
validate(service, "vpc-east", "ENABLE", "us-east-1");
validate(service, "vpc-west", "ENABLE", "us-west-2");
ObjectNode result = service.listResolverDnssecConfigs(null, null, null, "us-east-1");
JsonNode east = result.path("ResolverDnssecConfigs");
assertEquals(1, east.size());
assertEquals("vpc-east", east.get(0).path("ResourceId").asText());
assertEquals(ACCOUNT_ID, east.get(0).path("OwnerId").asText());
assertEquals("ENABLED", east.get(0).path("ValidationStatus").asText());
assertTrue(east.get(0).path("Id").asText().startsWith("rdsc-"));
assertTrue(service.listResolverDnssecConfigs(null, null, null, "eu-west-1")
.path("ResolverDnssecConfigs").isEmpty());
}
@Test
void listResolverDnssecConfigs_filtersByResourceId() {
Route53ResolverService service = service();
validate(service, "vpc-a", "ENABLE", "us-east-1");
validate(service, "vpc-b", "ENABLE", "us-east-1");
ObjectNode filter = MAPPER.createObjectNode();
filter.put("Name", "ResourceId");
filter.set("Values", MAPPER.createArrayNode().add("vpc-b"));
ObjectNode result = service.listResolverDnssecConfigs(
MAPPER.createArrayNode().add(filter), null, null, "us-east-1");
JsonNode matched = result.path("ResolverDnssecConfigs");
assertEquals(1, matched.size());
assertEquals("vpc-b", matched.get(0).path("ResourceId").asText());
assertTrue(result.path("NextToken").isMissingNode());
}
@Test
void listResolverDnssecConfigs_pagesByMaxResultsWithNextToken() {
Route53ResolverService service = service();
for (String vpc : List.of("vpc-a", "vpc-b", "vpc-c")) {
validate(service, vpc, "ENABLE", "us-east-1");
}
ObjectNode firstPage = service.listResolverDnssecConfigs(null,
MAPPER.getNodeFactory().numberNode(2), null, "us-east-1");
assertEquals(2, firstPage.path("ResolverDnssecConfigs").size());
String token = firstPage.path("NextToken").asText(null);
assertTrue(token != null && !token.isBlank());
ObjectNode secondPage = service.listResolverDnssecConfigs(null, null, token, "us-east-1");
assertEquals(1, secondPage.path("ResolverDnssecConfigs").size());
assertTrue(secondPage.path("NextToken").isMissingNode());
assertThrows(AwsException.class, () -> service.listResolverDnssecConfigs(null,
MAPPER.getNodeFactory().numberNode(101), null, "us-east-1"));
}
// The model: the response "doesn't contain disabled DNSSEC configurations". A disabled config still answers Get.
@Test
void listResolverDnssecConfigs_leavesOutDisabledConfigs() {
Route53ResolverService service = service();
validate(service, "vpc-on", "ENABLE", "us-east-1");
validate(service, "vpc-local", "USE_LOCAL_RESOURCE_SETTING", "us-east-1");
validate(service, "vpc-off", "ENABLE", "us-east-1");
validate(service, "vpc-off", "DISABLE", "us-east-1");
validate(service, "vpc-never", "DISABLE", "us-east-1");
ObjectNode result = service.listResolverDnssecConfigs(null,
MAPPER.getNodeFactory().numberNode(2), null, "us-east-1");
assertEquals(Set.of("vpc-on", "vpc-local"), resourceIds(result.path("ResolverDnssecConfigs")));
assertTrue(result.path("NextToken").isMissingNode(), "a disabled config takes no place on a page");
assertEquals("DISABLED", service.getResolverDnssecConfig("vpc-off", "us-east-1")
.path("ValidationStatus").asText());
}
private static Route53ResolverService service() {
return new Route53ResolverService(new InMemoryStorage<>(), new InMemoryStorage<>(), new InMemoryStorage<>(),
new InMemoryStorage<>(), new InMemoryStorage<>(), new InMemoryStorage<>(), new InMemoryStorage<>(),
MAPPER);
}
private static void validate(Route53ResolverService service, String vpc, String validation, String region) {
service.updateResolverDnssecConfig(MAPPER.createObjectNode().put("ResourceId", vpc)
.put("Validation", validation), region, ACCOUNT_ID);
}
private static Set<String> resourceIds(JsonNode configs) {
Set<String> ids = new HashSet<>();
configs.forEach(config -> ids.add(config.path("ResourceId").asText()));
return ids;
}
}
@@ -20,6 +20,7 @@ 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.lessThanOrEqualTo;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.startsWith;
@@ -140,6 +141,71 @@ class Route53ResolverIntegrationTest {
.statusCode(400).body("__type", equalTo("AccessDeniedException"));
}
@Test
void listResolverDnssecConfigs_listsTheUpdatedConfiguration() {
String vpc = ec2Ok("CreateVpc", "CidrBlock", "10.82.0.0/16")
.extract().path("CreateVpcResponse.vpc.vpcId");
try {
dnssec("UpdateResolverDnssecConfig", "{\"ResourceId\":\"" + vpc
+ "\",\"Validation\":\"ENABLE\"}").statusCode(200);
String id = dnssec("GetResolverDnssecConfig", "{\"ResourceId\":\"" + vpc + "\"}")
.statusCode(200).extract().path("ResolverDNSSECConfig.Id");
dnssec("ListResolverDnssecConfigs", "{}")
.statusCode(200)
.body("ResolverDnssecConfigs.ResourceId", hasItems(vpc))
.body("ResolverDnssecConfigs.findAll { it.ResourceId == '%s' }"
.formatted(vpc) + "[0].Id", equalTo(id))
.body("ResolverDnssecConfigs.findAll { it.ResourceId == '%s' }"
.formatted(vpc) + "[0].OwnerId", notNullValue())
.body("ResolverDnssecConfigs.findAll { it.ResourceId == '%s' }"
.formatted(vpc) + "[0].ValidationStatus", equalTo("ENABLED"));
dnssecConfigsOf(vpc)
.body("ResolverDnssecConfigs.size()", equalTo(1))
.body("ResolverDnssecConfigs[0].ResourceId", equalTo(vpc));
String nextToken = dnssec("ListResolverDnssecConfigs", "{\"MaxResults\":1}")
.statusCode(200)
.body("ResolverDnssecConfigs.size()", lessThanOrEqualTo(1))
.extract().path("NextToken");
if (nextToken != null) {
dnssec("ListResolverDnssecConfigs", "{\"NextToken\":\"" + nextToken + "\"}")
.statusCode(200);
}
dnssec("ListResolverDnssecConfigs", "{\"NextToken\":\"no-such-token\"}")
.statusCode(400).body("__type", equalTo("InvalidNextTokenException"));
} finally {
ec2Ok("DeleteVpc", "VpcId", vpc);
}
}
@Test
void listResolverDnssecConfigs_leavesOutDisabledConfigs() {
String vpc = ec2Ok("CreateVpc", "CidrBlock", "10.83.0.0/16")
.extract().path("CreateVpcResponse.vpc.vpcId");
try {
dnssec("GetResolverDnssecConfig", "{\"ResourceId\":\"" + vpc + "\"}")
.statusCode(200).body("ResolverDNSSECConfig.ValidationStatus", equalTo("DISABLED"));
dnssecConfigsOf(vpc).body("ResolverDnssecConfigs.size()", equalTo(0));
dnssec("UpdateResolverDnssecConfig", "{\"ResourceId\":\"" + vpc
+ "\",\"Validation\":\"ENABLE\"}").statusCode(200);
dnssecConfigsOf(vpc).body("ResolverDnssecConfigs.size()", equalTo(1));
dnssec("UpdateResolverDnssecConfig", "{\"ResourceId\":\"" + vpc
+ "\",\"Validation\":\"DISABLE\"}").statusCode(200);
dnssecConfigsOf(vpc).body("ResolverDnssecConfigs.size()", equalTo(0));
} finally {
ec2Ok("DeleteVpc", "VpcId", vpc);
}
}
private static ValidatableResponse dnssecConfigsOf(String vpc) {
return dnssec("ListResolverDnssecConfigs", "{\"Filters\":[{\"Name\":\"ResourceId\","
+ "\"Values\":[\"" + vpc + "\"]}]}").statusCode(200);
}
private static ValidatableResponse dnssec(String action, String body) {
return dnssec(action, body, AUTH_HEADER);
}