fix(ssm): normalize retained legacy parameter ARNs (#7698) (#7702)

Retained flat-name parameters still exposed the pre-fix ARN stored on disk. Normalize only the exact legacy SSM resource suffix when reading the ARN, retaining its stored partition, region and account. All metadata consumers and serialized responses then use the canonical resource without overwriting the parameter or incrementing its version.

Cover retained persistent JSON, version and label reads, metadata and history preservation, all eight partitions, canonical flush/reload, unrelated ARN preservation, and AWS SDK exact-resource IAM policy consumption. Malformed policy ARNs remain denied.

Validation: 298 focused SSM and partition tests passed; Checkstyle reports zero violations; docs-check and partition-check passed.

Fixes #7698
This commit is contained in:
jwoa95 authored and GitHub committed 2026-11-09 22:16:10 -04:00
1 parent 068c96eb2e
commit 99f9a49ebe
4 files changed
+218 -1

No files matched your search

+6
View File
@@ -31,6 +31,12 @@
`DescribeParameters` includes the stored parameter's `ARN` in each metadata entry, matching
`GetParameter`. This applies to filtered and paginated results as well.
Retained flat-name parameters from older Floci versions expose canonical
`parameter/<name>` ARNs on reads without a `PutParameter` overwrite. Normalization
preserves the ARN's partition, region and account, along with the parameter's value,
version, tags and history. Refresh cached Terraform outputs or policies that consumed
the old malformed ARN; malformed policy resources do not grant access to the canonical ARN.
`GetParametersByPath` supports `Type` and `KeyId` entries in `ParameterFilters`, with `Equals`
(the default) or `BeginsWith`. Values within one filter combine with OR; multiple
filters combine with AND. Filtering also applies to public AMI parameters and
@@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.JsonNode;
import io.floci.aws.core.common.AwsArnUtils;
import io.quarkus.runtime.annotations.RegisterForReflection;
import java.time.Instant;
@@ -103,7 +104,17 @@ public class Parameter {
public String getDescription() { return description; }
public void setDescription(String description) { this.description = description; }
public String getArn() { return arn; }
public String getArn() {
// Retained flat-name records written before the ARN fix lack the resource separator.
if (name != null && !name.startsWith("/") && AwsArnUtils.isArnFor(arn, "ssm")) {
AwsArnUtils.Arn stored = AwsArnUtils.parse(arn);
if (stored.resource().equals("parameter" + name)) {
return new AwsArnUtils.Arn(stored.partition(), stored.service(), stored.region(),
stored.accountId(), "parameter/" + name).toString();
}
}
return arn;
}
public void setArn(String arn) { this.arn = arn; }
public String getDataType() { return dataType; }
@@ -1,5 +1,8 @@
package io.floci.aws.services.ssm;
import com.fasterxml.jackson.core.type.TypeReference;
import io.floci.aws.core.storage.StorageFactory;
import io.floci.aws.services.ssm.model.Parameter;
import io.floci.aws.testing.AwsTestClients;
import io.floci.aws.testing.EnforcementFixtures;
import io.floci.aws.testing.IamEnforcementProfile;
@@ -7,12 +10,14 @@ import io.floci.aws.testing.PartitionCleanup;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
import io.restassured.RestAssured;
import jakarta.inject.Inject;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.ssm.SsmClient;
import software.amazon.awssdk.services.ssm.model.SsmException;
import java.util.Map;
import java.util.UUID;
import static io.floci.aws.testing.EnforcementFixtures.auth;
@@ -24,9 +29,52 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
@TestProfile(IamEnforcementProfile.class)
class SsmGetParameterArnIamEnforcementIntegrationTest {
@Inject
StorageFactory storageFactory;
@RegisterExtension
final PartitionCleanup cleanup = new PartitionCleanup();
@Test
void retainedParameterArnCanPopulateAnExactResourcePolicy() {
String account = "000000000000";
String name = "retained-arn-" + UUID.randomUUID();
String legacyArn = "arn:aws:ssm:us-east-1:" + account + ":parameter" + name;
Parameter legacy = new Parameter(name, "retained-value", "String");
legacy.setArn(legacyArn);
storageFactory.create("ssm", "ssm-parameters.json", new TypeReference<Map<String, Parameter>>() {})
.putForAccount(account, "us-east-1::" + name, legacy);
try (SsmClient root = AwsTestClients.create(SsmClient.builder(), account, Region.US_EAST_1)) {
try {
String returnedArn = root.getParameter(request -> request.name(name)).parameter().arn();
String userName = "ssm-retained-" + UUID.randomUUID();
EnforcementFixtures.UserCredentials credentials = EnforcementFixtures.createUser(
cleanup, RestAssured.port, auth(account, "iam"), userName);
String policy = """
{"Version":"2012-10-17","Statement":[{"Effect":"Allow",
"Action":"ssm:GetParameter","Resource":"%s"}]}""";
EnforcementFixtures.putUserPolicy(RestAssured.port, auth(account, "iam"), userName,
"read-retained", policy.formatted(returnedArn));
try (SsmClient user = AwsTestClients.create(SsmClient.builder(), credentials.accessKeyId(),
credentials.secretAccessKey(), Region.US_EAST_1)) {
assertEquals("retained-value", user.getParameter(request -> request.name(name)).parameter().value());
assertEquals("retained-value", user.getParameter(request -> request.name(returnedArn)).parameter().value());
assertEquals("arn:aws:ssm:us-east-1:" + account + ":parameter/" + name, returnedArn);
assertEquals(1, root.getParameter(request -> request.name(name)).parameter().version());
EnforcementFixtures.putUserPolicy(RestAssured.port, auth(account, "iam"), userName,
"read-retained", policy.formatted(legacyArn));
SsmException error = assertThrows(SsmException.class,
() -> user.getParameter(request -> request.name(name)));
assertEquals("AccessDeniedException", error.awsErrorDetails().errorCode());
}
} finally {
root.deleteParameter(request -> request.name(name));
}
}
}
@Test
void arnReadsStillRequirePermissionForTheRequestedParameter() {
String account = "000000000000";
@@ -0,0 +1,152 @@
package io.floci.aws.services.ssm;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.floci.aws.core.storage.InMemoryStorage;
import io.floci.aws.core.storage.PersistentStorage;
import io.floci.aws.services.ssm.model.Parameter;
import io.floci.aws.services.ssm.model.ParameterHistory;
import io.floci.aws.testing.PartitionMatrix.PartitionCase;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.ValueSource;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Instant;
import java.util.List;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
class SsmRetainedParameterArnTest {
@TempDir
Path directory;
@Test
void readingLegacyFlatNameReturnsCanonicalArn() {
InMemoryStorage<String, Parameter> parameters = new InMemoryStorage<>();
Parameter legacy = new Parameter("example-endpoint", "retained-value", "String");
legacy.setArn("arn:aws:ssm:eu-west-2:000000000000:parameterexample-endpoint");
parameters.put("eu-west-2::example-endpoint", legacy);
SsmService service = new SsmService(parameters, new InMemoryStorage<>(), 5);
assertEquals("arn:aws:ssm:eu-west-2:000000000000:parameter/example-endpoint",
service.getParameter("example-endpoint", "eu-west-2").getArn());
}
@ParameterizedTest
@MethodSource("io.floci.aws.testing.PartitionMatrix#cases")
void normalizationPreservesStoredPartitionRegionAndAccount(PartitionCase partitionCase) {
String prefix = "arn:" + partitionCase.partition() + ":ssm:" + partitionCase.region() + ":123456789012:";
InMemoryStorage<String, Parameter> parameters = new InMemoryStorage<>();
Parameter legacy = new Parameter("endpoint", "value", "String");
legacy.setArn(prefix + "parameterendpoint");
parameters.put(partitionCase.region() + "::endpoint", legacy);
SsmService service = new SsmService(parameters, new InMemoryStorage<>(), 5);
assertEquals(prefix + "parameter/endpoint", service.getParameter("endpoint", partitionCase.region()).getArn());
}
@ParameterizedTest
@ValueSource(strings = {"endpoint", "/endpoint", "/app/endpoint"})
void retainedStoreReadsPreserveMetadataHistoryAndFiles(String name) throws IOException {
String region = "eu-west-2";
String key = region + "::" + name;
String prefix = "arn:aws:ssm:eu-west-2:000000000000:";
String canonicalArn = prefix + SsmService.parameterResource(name);
Path parameterFile = directory.resolve("ssm-parameters.json");
String original = """
{"%s":{
"Name":"%s","Value":"retained-value","Type":"SecureString","Version":2,
"LastModifiedDate":"2026-10-01T12:00:00Z","Description":"retained-description",
"ARN":"%sparameter%s","KeyId":"alias/retained","EncryptedValue":"retained-ciphertext",
"AllowedPattern":".*","Tier":"Advanced","DataType":"text","Tags":{"env":"test"},
"Policies":[{"Type":"Expiration","Version":"1.0","Attributes":{"Timestamp":"2030-01-01T00:00:00Z"}}]
}}
""".formatted(key, name, prefix, name);
Files.writeString(parameterFile, original);
PersistentStorage<String, Parameter> parameters = new PersistentStorage<>(parameterFile, new TypeReference<>() {});
parameters.load();
Parameter retained = parameters.get(key).orElseThrow();
ParameterHistory previous = new ParameterHistory(retained);
previous.setValue("previous-value");
previous.setVersion(1);
previous.setLabels(List.of("release"));
Path historyFile = directory.resolve("ssm-history.json");
PersistentStorage<String, List<ParameterHistory>> history = new PersistentStorage<>(historyFile,
new TypeReference<>() {});
history.put(key, List.of(previous, new ParameterHistory(retained)));
String originalHistory = Files.readString(historyFile);
SsmService service = new SsmService(parameters, history, 5);
Parameter current = service.getParameter(name, region);
assertEquals(canonicalArn, current.getArn());
assertEquals("retained-value", current.getValue());
assertEquals("SecureString", current.getType());
assertEquals(2, current.getVersion());
assertEquals(Instant.parse("2026-10-01T12:00:00Z"), current.getLastModifiedDate());
assertEquals("retained-description", current.getDescription());
assertEquals("alias/retained", current.getKeyId());
assertEquals("retained-ciphertext", current.getEncryptedValue());
assertEquals(".*", current.getAllowedPattern());
assertEquals("Advanced", current.getTier());
assertEquals("text", current.getDataType());
assertEquals(Map.of("env", "test"), service.listTagsForResource(name, region));
assertEquals("Expiration", current.getPolicies().getFirst().get("Type").asText());
assertEquals(canonicalArn, service.getParameter(canonicalArn, region).getArn());
assertEquals(canonicalArn, service.getParameters(List.of(name), true, region).getFirst().getArn());
assertEquals(canonicalArn, service.describeParameters(region).getFirst().getArn());
for (String selector : List.of("1", "release")) {
Parameter selected = service.getParameter(name + ":" + selector, region);
assertEquals(canonicalArn, selected.getArn());
assertEquals("previous-value", selected.getValue());
assertEquals(1, selected.getVersion());
assertEquals(":" + selector, selected.getSelector());
}
if (name.startsWith("/")) {
assertEquals(canonicalArn, service.getParametersByPath("/", true, region).getFirst().getArn());
}
assertEquals(List.of(1L, 2L), service.getParameterHistory(name, region).stream()
.map(ParameterHistory::getVersion).toList());
assertEquals(List.of("release"), service.getParameterHistory(name, region).getFirst().getLabels());
assertEquals(original, Files.readString(parameterFile));
assertEquals(originalHistory, Files.readString(historyFile));
parameters.flush();
ObjectMapper mapper = new ObjectMapper();
assertEquals(canonicalArn, mapper.readTree(parameterFile.toFile()).get(key).get("ARN").asText());
parameters.load();
assertEquals(canonicalArn, service.getParameter(name, region).getArn());
assertEquals(2, service.getParameter(name, region).getVersion());
assertEquals(originalHistory, Files.readString(historyFile));
}
@ParameterizedTest
@CsvSource({
"endpoint, arn:aws:ssm:eu-west-2:000000000000:parameter/endpoint",
"endpoint, arn:aws:ssm:eu-west-2:000000000000:parameterdifferent-name",
"endpoint, arn:aws:secretsmanager:eu-west-2:000000000000:parameterendpoint",
"/aws/reference/secretsmanager/endpoint, arn:aws:secretsmanager:eu-west-2:000000000000:secret:endpoint-AbCdEf",
"endpoint, malformed-arn"
})
void unrelatedOrCanonicalArnsAreUnchanged(String name, String arn) {
Parameter parameter = new Parameter(name, "value", "String");
parameter.setArn(arn);
assertEquals(arn, parameter.getArn());
}
@Test
void absentArnOrNameRemainsReadable() {
Parameter parameter = new Parameter();
assertNull(parameter.getArn());
parameter.setArn("arn:aws:ssm:eu-west-2:000000000000:parameterendpoint");
assertEquals("arn:aws:ssm:eu-west-2:000000000000:parameterendpoint", parameter.getArn());
}
}