fix(ssm): honor path parameter type filters (#6183)

* fix(ssm): honor path parameter type filters

Forward GetParametersByPath Type filters through the existing parameter-filter validation and matching rules. Retain path, recursion, region and public AMI selection, and document the remaining filter and pagination limitations.

* fix(ssm): validate path filter keys and apply key ids

Reject missing and action-invalid filter keys before selecting path results. Reuse the existing Type and KeyId matcher, and validate Label options while keeping label matching a documented gap.

Verify 264 focused SSM tests, Checkstyle, 95 docs tests, docs checks, and the partition gate. Regression tests fail before the fix and detect an inverted key allowlist.

* fix(ssm): reuse canonical invalid filter option errors

Share the existing AWS InvalidFilterOption message between DescribeParameters and Label path filters. Assert the complete HTTP message for invalid KeyId and Label options.

Verify 264 focused SSM tests, three CI-failing Lambda/SQS tests, Checkstyle, docs checks, 95 docs tests, and the partition gate. The two Label message assertions fail before the fix.
This commit is contained in:
Aniket Shukla authored and GitHub committed 2026-10-22 17:06:23 -04:00
1 parent af3dc4866e
commit a9ceee1de6
6 files changed
+280 -11

No files matched your search

@@ -232,7 +232,7 @@ public class SsmJsonHandler {
String path = request.path("Path").asText();
boolean recursive = request.path("Recursive").asBoolean(false);
List<Parameter> params = ssmService.getParametersByPath(path, recursive, region);
List<Parameter> params = ssmService.getParametersByPath(path, recursive, parameterFilters(request), region);
ObjectNode response = objectMapper.createObjectNode();
ArrayNode parametersArray = objectMapper.createArrayNode();
@@ -302,11 +302,7 @@ public class SsmJsonHandler {
private static final int DESCRIBE_PARAMETERS_MAX_RESULTS = 50;
private Response handleDescribeParameters(JsonNode request, String region) {
List<ParameterStringFilter> filters = new ArrayList<>();
for (JsonNode f : request.path("ParameterFilters")) {
filters.add(new ParameterStringFilter(f.path("Key").asText(null),
f.path("Option").asText(null), textValues(f.path("Values"))));
}
List<ParameterStringFilter> filters = parameterFilters(request);
// The deprecated Filters shape has no option; each of its keys matches exactly.
for (JsonNode f : request.path("Filters")) {
String key = f.path("Key").asText(null);
@@ -371,6 +367,15 @@ public class SsmJsonHandler {
return text.isEmpty() ? null : text;
}
private static List<ParameterStringFilter> parameterFilters(JsonNode request) {
List<ParameterStringFilter> filters = new ArrayList<>();
for (JsonNode filter : request.path("ParameterFilters")) {
filters.add(new ParameterStringFilter(filter.path("Key").asText(null),
filter.path("Option").asText(null), textValues(filter.path("Values"))));
}
return filters;
}
private static List<String> textValues(JsonNode values) {
List<String> result = new ArrayList<>();
values.forEach(v -> result.add(v.asText()));
@@ -56,6 +56,7 @@ public class SsmService implements ResourceProvider {
// Label is a ParameterStringFilter key too, but only GetParametersByPath accepts it.
private static final Set<String> DESCRIBE_PARAMETERS_FILTER_KEYS =
Set.of("Name", "Type", "KeyId", "Path", "Tier", "DataType");
private static final Set<String> GET_PARAMETERS_BY_PATH_FILTER_KEYS = Set.of("Type", "KeyId", "Label");
private static final String DEFAULT_SSM_KEY_ID = "alias/aws/ssm";
private static final int STANDARD_TIER_MAX_VALUE_BYTES = 4096;
private static final Set<String> PARAMETER_TIERS = Set.of("Standard", "Advanced", "Intelligent-Tiering");
@@ -561,6 +562,15 @@ public class SsmService implements ResourceProvider {
});
}
public List<Parameter> getParametersByPath(String path, boolean recursive,
List<ParameterStringFilter> filters, String region) {
filters.forEach(SsmService::validateGetParametersByPathFilter);
List<ParameterStringFilter> matchingFilters = filters.stream().filter(filter -> !"Label".equals(filter.key())).toList();
return getParametersByPath(path, recursive, region).stream()
.filter(parameter -> matchingFilters.stream().allMatch(filter -> matchesParameterFilter(parameter, filter)))
.toList();
}
public List<Parameter> getParametersByPath(String path, boolean recursive, String region) {
String normalizedPath = path.endsWith("/") ? path : path + "/";
String prefix = region + "::";
@@ -663,9 +673,7 @@ public class SsmService implements ResourceProvider {
: "Name".equals(key) ? Set.of("Equals", "BeginsWith", "Contains")
: Set.of("Equals", "BeginsWith");
if (!options.contains(filter.option())) {
throw new AwsException("InvalidFilterOption",
"The specified filter option isn't valid. Valid options are Equals and BeginsWith. "
+ "For Path filter, valid options are Recursive and OneLevel.", 400);
throw invalidFilterOption();
}
}
// Every key but a tag needs at least one value, and a path value must be absolute.
@@ -677,6 +685,30 @@ public class SsmService implements ResourceProvider {
}
}
private static void validateGetParametersByPathFilter(ParameterStringFilter filter) {
String key = filter.key();
if (key == null || !GET_PARAMETERS_BY_PATH_FILTER_KEYS.contains(key)) {
throw new AwsException("InvalidFilterKey", "The specified key isn't valid.", 400);
}
if (!"Label".equals(key)) {
validateDescribeParametersFilter(filter);
return;
}
if (filter.option() != null && !"Equals".equals(filter.option())) {
throw invalidFilterOption();
}
if (filter.values().isEmpty()) {
throw new AwsException("InvalidFilterValue",
"The filter value isn't valid. Verify the value and try again.", 400);
}
}
private static AwsException invalidFilterOption() {
return new AwsException("InvalidFilterOption",
"The specified filter option isn't valid. Valid options are Equals and BeginsWith. "
+ "For Path filter, valid options are Recursive and OneLevel.", 400);
}
private static boolean matchesParameterFilter(Parameter parameter, ParameterStringFilter filter) {
String key = filter.key();
if (key.startsWith("tag:")) {
@@ -3,8 +3,8 @@ package io.github.hectorvent.floci.services.ssm.model;
import java.util.List;
/**
* One entry of {@code DescribeParameters}' {@code ParameterFilters} (or a translated legacy
* {@code Filters} entry). A null {@code option} means the caller omitted it.
* One {@code ParameterFilters} entry for a parameter listing (or a translated legacy
* {@code DescribeParameters.Filters} entry). A null {@code option} means the caller omitted it.
*/
public record ParameterStringFilter(String key, String option, List<String> values) {
}