fix(fis): give resource-tag conditions the tags of the template, experiment or action a request names (#8838)

The generated request resources give AWS FIS's experiment-template,
experiment and action types the aws:ResourceTag/ key, but no service
answered the fis namespace's stored tags, so a condition on their tags
saw none. FisService now answers it: storedTags reads the template,
experiment or action tags stored under the Region the ARN names and its
id, in the request's account, where the tag handlers read, in place; a
template or an experiment is matched on the whole ARN it records, an
action on the ARN built for it. Tag calls already run one at a time and
store a new record.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-18 03:15:22 -04:00
1 parent 07996b0ede
commit 29d4555896
5 files changed
+174 -13

No files matched your search

+3 -2
View File
@@ -3355,8 +3355,9 @@ floci populates:
instances, ACM for its certificates, Firehose for its delivery streams, Cognito for its user pools and identity
pools, OpenSearch for its domains, Signer for its signing profiles, Access Analyzer for its analyzers, Managed Service
for Apache Flink for its applications, S3 Vectors for its vector buckets and indexes, Timestream for InfluxDB for its
DB instances, DB clusters, parameter groups and backups, CloudTrail for its trails, and Budgets for its budgets and
budget actions. Tag keys differing only in case are one condition key holding every value.
DB instances, DB clusters, parameter groups and backups, CloudTrail for its trails, Budgets for its budgets and budget
actions, and AWS FIS for its experiment templates, experiments and actions. Tag keys differing only in case are one
condition key holding every value.
- EC2 resource keys such as a network interface's `ec2:Vpc`, `ec2:Subnet`, `ec2:AvailabilityZone` and
`ec2:NetworkInterfaceID`: for every action on a resource EC2 holds, the members of the resource the
key names, an ARN for a key the Service Reference types as one. `resourceKeys` in
@@ -49,9 +49,10 @@ import java.util.Optional;
* the tags of a signing profile; Access Analyzer, for the tags of an analyzer; Managed Service for Apache Flink, for
* the tags of an application; S3 Vectors, for the tags of a vector bucket or an index; Timestream for InfluxDB, for the
* tags of a DB instance, a DB cluster, a parameter group or a backup; CloudTrail, for the tags of a trail; Budgets, for
* the tags of a budget or a budget action); looked up lazily by {@code ResourceArnBuilder} and
* {@code IamConditionContextResolver} through {@code Instance<StoredResourceArns>} for the namespace a request or an
* ARN is of, so IAM never depends on that service directly.</p>
* the tags of a budget or a budget action; AWS FIS, for the tags of an experiment template, an experiment or an
* action); looked up lazily by {@code ResourceArnBuilder} and {@code IamConditionContextResolver} through
* {@code Instance<StoredResourceArns>} for the namespace a request or an ARN is of, so IAM never depends on that
* service directly.</p>
*
* <p>Each answer is a lookup of what the service holds, asked for by an entry of the generated table ({@code find},
* {@code through}, a default, {@code forwarded}, a type's {@code resourceTagKeys}): never a fact about what an operation acts on, which the table alone
@@ -10,6 +10,7 @@ import io.floci.aws.core.common.AwsException;
import io.floci.aws.core.common.Base64Url;
import io.floci.aws.core.common.EpochSeconds;
import io.floci.aws.core.common.RegionResolver;
import io.floci.aws.core.common.StoredResourceArns;
import io.floci.aws.core.common.TagHandler;
import io.floci.aws.core.storage.AccountAwareStorageBackend;
import io.floci.aws.core.storage.StorageBackend;
@@ -38,6 +39,7 @@ import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.OptionalDouble;
import java.util.Random;
import java.util.Set;
@@ -58,7 +60,7 @@ import java.util.regex.Pattern;
* impairs, and each completes once its duration runs out.</p>
*/
@ApplicationScoped
public class FisService implements TagHandler {
public class FisService implements TagHandler, StoredResourceArns {
private static final String SERVICE = "fis";
private static final int MAX_PAGE_SIZE = 100;
@@ -631,6 +633,53 @@ public class FisService implements TagHandler {
saveResourceTags(region, resource, current);
}
@Override
public String namespace() {
return SERVICE;
}
/** A request names a template, an experiment or an action by the id its ARN ends in: nothing to find. */
@Override
public Optional<String> find(String type, List<String> names, String region) {
return Optional.empty();
}
/**
* The tags of the experiment template, the experiment or the action whose ARN is {@code arn}, in the request's
* account, where the tag handlers read: an ARN of another account names none. Read in place under the Region the
* ARN names and the id it ends in, a record stored before storage was account-aware included; a template or an
* experiment is matched on the whole ARN it records, an action, whose ARN is built rather than stored, on the ARN
* built for it. A tag call stores a new record, one at a time, so the read is of one whole set.
*/
@Override
public Map<String, String> storedTags(String arn) {
if (!AwsArnUtils.isArnFor(arn, SERVICE)) {
return Map.of();
}
AwsArnUtils.Arn parsed = AwsArnUtils.parse(arn);
String account = regionResolver.getAccountId();
int separator = parsed.resource().indexOf('/');
if (!parsed.accountId().equals(account) || separator <= 0) {
return Map.of();
}
String region = parsed.region();
String id = parsed.resource().substring(separator + 1);
Map<String, String> tags = switch (parsed.resource().substring(0, separator)) {
case "experiment-template" -> AccountAwareStorageBackend.readInAccount(stores.templates, account,
templateKey(region, id))
.filter(template -> arn.equals(template.getArn())).map(ExperimentTemplate::getTags).orElse(null);
case "experiment" -> AccountAwareStorageBackend.readInAccount(stores.experiments, account,
experimentKey(region, id))
.filter(experiment -> arn.equals(experiment.getArn())).map(Experiment::getTags).orElse(null);
case "action" -> arn.equals(regionResolver.buildArn(SERVICE, region, "action/" + id))
? AccountAwareStorageBackend.readInAccount(stores.actionTags, account, actionTagsKey(region, id))
.orElse(null)
: null;
default -> null;
};
return tags == null ? Map.of() : new LinkedHashMap<>(tags);
}
private void validateCreateTemplate(ObjectNode input) {
requireToken(input, "clientToken");
validateOptionalDescription(input, "description", false);
@@ -0,0 +1,81 @@
package io.floci.aws.services.fis;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.floci.aws.core.common.RegionResolver;
import io.floci.aws.core.storage.InMemoryStorage;
import io.floci.aws.services.fis.model.ExperimentTemplate;
import io.floci.aws.testing.InMemoryStorageFactory;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.Map;
import java.util.Set;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
/** IAM's lookup of the tags AWS FIS holds on an experiment template, an experiment or an action. */
class FisStoredTagsTest {
private static final String REGION = "us-east-1";
private static final String ACCOUNT = "000000000000";
private final ObjectMapper mapper = new ObjectMapper();
/**
* The lookup reads the tags of the template, the experiment or the action the ARN names, as the tag calls leave
* them, and nothing for another account's, another Region's, an unknown resource's or another service's ARN.
*/
@Test
void storedTagsAreTheTagsOfTheResourceTheArnNames() throws Exception {
FisService service = service(new InMemoryStorageFactory(ACCOUNT));
String templateId = service.createExperimentTemplate(REGION, mapper.readTree("""
{"clientToken":"stored-tags-template","description":"d",
"roleArn":"arn:aws:iam::000000000000:role/fis-role","stopConditions":[{"source":"none"}],
"targets":{},"actions":{"wait":{"actionId":"aws:fis:wait","parameters":{"duration":"PT1M"}}},
"tags":{"team":"web","env":"dev"}}
""")).path("experimentTemplate").path("id").asText();
String templateArn = service.getExperimentTemplate(REGION, templateId).path("experimentTemplate").path("arn")
.asText();
service.tagResource(REGION, templateArn, Map.of("team", "data"));
service.untagResource(REGION, templateArn, List.of("env"));
String experimentArn = service.startExperiment(REGION, mapper.readTree("""
{"clientToken":"stored-tags-experiment","experimentTemplateId":"%s",
"experimentOptions":{"actionsMode":"skip-all"},"tags":{"team":"ops"}}
""".formatted(templateId))).path("experiment").path("arn").asText();
String actionArn = service.getAction(REGION, "aws:fis:wait").path("action").path("arn").asText();
service.tagResource(REGION, actionArn, Map.of("team", "sre"));
assertEquals("fis", service.namespace());
assertEquals(Map.of("team", "data"), service.storedTags(templateArn));
assertEquals(Map.of("team", "ops"), service.storedTags(experimentArn));
assertEquals(Map.of("team", "sre"), service.storedTags(actionArn));
assertTrue(service.storedTags(templateArn.replace(ACCOUNT, "111122223333")).isEmpty());
assertTrue(service.storedTags(templateArn.replace(REGION, "us-west-2")).isEmpty());
assertTrue(service.storedTags(templateArn.replace(templateId, "EXTmissing")).isEmpty());
assertTrue(service.storedTags(actionArn.replace("aws:fis:wait", "aws:fis:inject-api-throttle-error"))
.isEmpty());
assertTrue(service.storedTags("arn:aws:ec2:us-east-1:000000000000:instance/i-0123456789abcdef0").isEmpty());
}
/** A template stored before storage was account-aware is read in place: the lookup migrates nothing. */
@Test
void storedTagsReadAPreAccountAwareTemplateInPlace() {
InMemoryStorage<String, ExperimentTemplate> raw = new InMemoryStorage<>();
FisService service =
service(new InMemoryStorageFactory(ACCOUNT).withStore("fis-experiment-templates.json", raw));
ExperimentTemplate legacy = new ExperimentTemplate();
legacy.setId("EXTlegacy");
legacy.setArn("arn:aws:fis:us-east-1:000000000000:experiment-template/EXTlegacy");
legacy.setTags(Map.of("team", "data"));
raw.put(REGION + "::template::EXTlegacy", legacy);
assertEquals(Map.of("team", "data"), service.storedTags(legacy.getArn()));
assertEquals(Set.of(REGION + "::template::EXTlegacy"), raw.keys());
}
private FisService service(InMemoryStorageFactory storage) {
RegionResolver regionResolver = new RegionResolver(REGION, ACCOUNT);
return new FisService(new FisStores(storage), mapper, regionResolver, new FisCatalog(mapper, regionResolver));
}
}
@@ -1141,13 +1141,8 @@ class IamRestRouteEnforcementIntegrationTest {
@Test
void fisIsCheckedOnTheTemplateItsPathNames() {
String template = "{\"clientToken\":\"" + suffix() + "\",\"description\":\"d\",\"roleArn\":\"arn:aws:iam::"
+ ACCOUNT + ":role/fis\",\"stopConditions\":[{\"source\":\"none\"}],\"targets\":{},\"actions\":"
+ "{\"wait\":{\"actionId\":\"aws:fis:wait\",\"parameters\":{\"duration\":\"PT1M\"}}}}";
String id = adminOf("fis").body(template).post("/experimentTemplates")
.then().statusCode(200).extract().path("experimentTemplate.id");
cleanup.register(() -> adminOf("fis").delete("/experimentTemplates/" + id));
String arn = "arn:aws:fis:us-east-1:" + ACCOUNT + ":experiment-template/" + id;
String id = fisTemplate(null);
String arn = fisTemplateArn(id);
String user = user("route-fis");
policy(user, allow("fis:GetExperimentTemplate", arn));
@@ -1156,6 +1151,40 @@ class IamRestRouteEnforcementIntegrationTest {
refused(request(user, "fis", "GET", "/experimentTemplates/EXTother", null), "fis:GetExperimentTemplate");
}
/**
* An {@code aws:ResourceTag} condition reads the tags AWS FIS holds on the experiment template a request names,
* as TagResource leaves them, so an allow on one team's tag lets the caller read that team's template and not
* another's.
*/
@Test
void aFisResourceTagConditionReadsTheTagsOfTheTemplate() {
String tagged = fisTemplate("{\"team\":\"web\"}");
String other = fisTemplate("{\"team\":\"web\"}");
adminOf("fis").body("{\"tags\":{\"team\":\"data\"}}").post("/tags/" + fisTemplateArn(tagged))
.then().statusCode(200);
String user = user("route-fis-tags");
policy(user, onTeam("Allow", "fis:GetExperimentTemplate", "data"));
request(user, "fis", "GET", "/experimentTemplates/" + tagged, null).statusCode(200);
refused(request(user, "fis", "GET", "/experimentTemplates/" + other, null), "fis:GetExperimentTemplate");
}
/** The id of an experiment template an administrator creates, with the {@code tags} JSON object if any. */
private String fisTemplate(String tags) {
String template = "{\"clientToken\":\"" + suffix() + "\",\"description\":\"d\",\"roleArn\":\"arn:aws:iam::"
+ ACCOUNT + ":role/fis\",\"stopConditions\":[{\"source\":\"none\"}],\"targets\":{},\"actions\":"
+ "{\"wait\":{\"actionId\":\"aws:fis:wait\",\"parameters\":{\"duration\":\"PT1M\"}}}"
+ (tags == null ? "" : ",\"tags\":" + tags) + "}";
String id = adminOf("fis").body(template).post("/experimentTemplates")
.then().statusCode(200).extract().path("experimentTemplate.id");
cleanup.register(() -> adminOf("fis").delete("/experimentTemplates/" + id));
return id;
}
private static String fisTemplateArn(String id) {
return "arn:aws:fis:us-east-1:" + ACCOUNT + ":experiment-template/" + id;
}
@Test
void fisSafetyLeverUpdateIsCheckedOnTheLever() {
String user = user("route-lever");