diff --git a/docs/services/iam.md b/docs/services/iam.md
index dc16af3c15..90ac23052f 100644
--- a/docs/services/iam.md
+++ b/docs/services/iam.md
@@ -3071,8 +3071,9 @@ floci populates:
its type (`aws:ResourceTag/`, `secretsmanager:ResourceTag/`), which `regen_iam_request_resources.py`
reads from the Service Reference for every namespace it reads, valued from the tags the type's service
holds on that resource (`StoredResourceArns.storedTags`); a service that holds none leaves them absent.
- Secrets Manager answers for its secrets, S3 Tables for its table buckets and tables, and EventBridge
- Scheduler for its schedule groups. Tag keys differing only in case are one condition key holding every value.
+ Secrets Manager answers for its secrets, S3 Tables for its table buckets and tables, EventBridge Scheduler for
+ its schedule groups, and CloudFormation for its stacks, stack sets and change sets. 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
diff --git a/src/main/java/io/floci/aws/core/common/StoredResourceArns.java b/src/main/java/io/floci/aws/core/common/StoredResourceArns.java
index 4aec68e485..68892179bb 100644
--- a/src/main/java/io/floci/aws/core/common/StoredResourceArns.java
+++ b/src/main/java/io/floci/aws/core/common/StoredResourceArns.java
@@ -26,10 +26,11 @@ import java.util.Optional;
* permission sets are provisioned to; Resource Explorer, for its default view; OAM and RAM, for the sinks,
* invitations and shares of other accounts they act on; Secrets Manager, for the secret a name or an ARN names,
* random suffix included, and its tags; EventBridge Scheduler, for its default schedule group and its groups' tags;
- * CloudFormation, for the stack or the stack set a name names, whose id it minted; S3 Tables, for the table a request
- * names by its table bucket, namespace and name, and the tags of a table bucket or a table); looked up lazily by
- * {@code ResourceArnBuilder} and {@code IamConditionContextResolver} through {@code Instance} for
- * the namespace a request or an ARN is of, so IAM never depends on that service directly.
+ * CloudFormation, for the stack or the stack set a name names, whose id it minted, and the tags of a stack, a stack set
+ * or a change set; S3 Tables, for the table a request names by its table bucket, namespace and name, and the tags of a
+ * table bucket or a table); looked up lazily by {@code ResourceArnBuilder} and {@code IamConditionContextResolver}
+ * through {@code Instance} for the namespace a request or an ARN is of, so IAM never depends on
+ * that service directly.
*
* 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
diff --git a/src/main/java/io/floci/aws/services/cloudformation/CloudFormationService.java b/src/main/java/io/floci/aws/services/cloudformation/CloudFormationService.java
index e77391f90d..a2f829190f 100644
--- a/src/main/java/io/floci/aws/services/cloudformation/CloudFormationService.java
+++ b/src/main/java/io/floci/aws/services/cloudformation/CloudFormationService.java
@@ -425,6 +425,34 @@ public class CloudFormationService implements ResourceProvider {
return Optional.ofNullable(resolveStack(stackNameOrArn, region, currentAccount())).map(Stack::getStackId);
}
+ /**
+ * The tags of the live stack, or of the change set, stored under {@code arn} in the account and Region the ARN
+ * names, by key, which IAM gives a resource-tag condition; empty when there is none. Reads only, matching the
+ * stack's id or the change set's on the whole ARN.
+ */
+ public Map storedTags(String arn) {
+ if (!AwsArnUtils.isArnFor(arn, "cloudformation")) {
+ return Map.of();
+ }
+ AwsArnUtils.Arn parsed = AwsArnUtils.parse(arn);
+ String resource = parsed.resource();
+ if (resource.startsWith("stack/")) {
+ Stack stack = resolveStack(arn, parsed.region(), parsed.accountId());
+ return stack != null && arn.equals(stack.getStackId()) ? stack.tagsSnapshot() : Map.of();
+ }
+ if (!resource.startsWith("changeSet/")) {
+ return Map.of();
+ }
+ try {
+ Stack stack = findStackForChangeSetArn(arn, parsed.region(), parsed.accountId());
+ ChangeSet changeSet = stack == null ? null
+ : stack.getChangeSets().get(resolveChangeSetName(arn, parsed.region(), parsed.accountId()));
+ return changeSet == null || changeSet.getTags() == null ? Map.of() : Map.copyOf(changeSet.getTags());
+ } catch (AwsException expected) {
+ return Map.of();
+ }
+ }
+
/**
* The stack's current parameter values, or an empty map if it does not exist (yet). Used to
* resolve {@code UsePreviousValue} on an update before the stack lookup that
diff --git a/src/main/java/io/floci/aws/services/cloudformation/CloudFormationStoredResourceArns.java b/src/main/java/io/floci/aws/services/cloudformation/CloudFormationStoredResourceArns.java
index 95a5f5a98b..23b34ae838 100644
--- a/src/main/java/io/floci/aws/services/cloudformation/CloudFormationStoredResourceArns.java
+++ b/src/main/java/io/floci/aws/services/cloudformation/CloudFormationStoredResourceArns.java
@@ -5,11 +5,13 @@ import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import java.util.List;
+import java.util.Map;
import java.util.Optional;
/**
* What IAM asks CloudFormation of the resources a request names: the ARN of the stack or the stack set a name names,
- * whose id CloudFormation minted, so a request naming one by its name is checked on the ARN AWS checks.
+ * whose id CloudFormation minted, so a request naming one by its name is checked on the ARN AWS checks; and the tags
+ * of a stack, a stack set or a change set, which a resource-tag condition reads.
*/
@ApplicationScoped
public class CloudFormationStoredResourceArns implements StoredResourceArns {
@@ -39,4 +41,10 @@ public class CloudFormationStoredResourceArns implements StoredResourceArns {
default -> Optional.empty();
};
}
+
+ /** The tags of the stack, stack set or change set {@code arn} names, which a resource-tag condition reads. */
+ @Override
+ public Map storedTags(String arn) {
+ return arn.contains(":stackset/") ? stackSets.storedTags(arn) : stacks.storedTags(arn);
+ }
}
diff --git a/src/main/java/io/floci/aws/services/cloudformation/StackSetService.java b/src/main/java/io/floci/aws/services/cloudformation/StackSetService.java
index 608af77dd1..42a9ab0c70 100644
--- a/src/main/java/io/floci/aws/services/cloudformation/StackSetService.java
+++ b/src/main/java/io/floci/aws/services/cloudformation/StackSetService.java
@@ -7,6 +7,7 @@ import io.floci.aws.core.common.RegionResolver;
import io.floci.aws.core.common.RequestScopes;
import io.floci.aws.core.common.ServicePrincipals;
import io.floci.aws.core.common.SmithyValidationErrors;
+import io.floci.aws.core.storage.AccountAwareStorageBackend;
import io.floci.aws.core.storage.StorageBackend;
import io.floci.aws.core.storage.StorageFactory;
import io.floci.aws.services.cloudformation.model.ChangeSet;
@@ -66,6 +67,7 @@ public class StackSetService implements PassedRoleLookup, AccountPlacementListen
private static final String INSTANCE_CHANGE_SET = "stackset-instance";
private static final String UPDATE_CHANGE_SET = "stackset-update";
private static final String ORGANIZATIONS_ACCESS_KEY = "organizations-access";
+ private static final String STACK_SET_RESOURCE = "stackset/";
private static final int STACK_SET_LIMIT = 1000;
private static final Pattern STACK_SET_NAME = Pattern.compile("[A-Za-z][A-Za-z0-9-]{0,127}");
private static final Pattern OPERATION_ID = Pattern.compile("[A-Za-z0-9][-A-Za-z0-9]{0,127}");
@@ -211,7 +213,7 @@ public class StackSetService implements PassedRoleLookup, AccountPlacementListen
/** The stack set's ARN, {@code stackset/:} in the request's Region, as AWS gives its StackSetARN. */
/** The stack set's ARN in the Region given, the one the request naming it is in, whatever context runs it. */
public String stackSetArn(StackSet stackSet, String region) {
- return regionResolver.buildArn("cloudformation", region, "stackset/" + stackSet.getStackSetId());
+ return regionResolver.buildArn("cloudformation", region, STACK_SET_RESOURCE + stackSet.getStackSetId());
}
/**
@@ -222,6 +224,31 @@ public class StackSetService implements PassedRoleLookup, AccountPlacementListen
return name == null ? Optional.empty() : stackSets.get(name).map(stackSet -> stackSetArn(stackSet, region));
}
+ /**
+ * The tags of the stack set stored under {@code arn} in the account the ARN names, a pre-multi-account one of the
+ * default account read in place, by key, which IAM gives a resource-tag condition; empty when there is none. Reads
+ * only, matching the stack set's id, {@code :}, on the ARN.
+ */
+ public Map storedTags(String arn) {
+ if (!AwsArnUtils.isArnFor(arn, "cloudformation")) {
+ return Map.of();
+ }
+ AwsArnUtils.Arn parsed = AwsArnUtils.parse(arn);
+ String id = parsed.resource().startsWith(STACK_SET_RESOURCE)
+ ? parsed.resource().substring(STACK_SET_RESOURCE.length()) : "";
+ if (id.indexOf(':') < 1) {
+ return Map.of();
+ }
+ String name = id.substring(0, id.indexOf(':'));
+ String account = parsed.accountId();
+ Optional stored = stackSets instanceof AccountAwareStorageBackend aware
+ ? aware.getForAccount(account, name).or(() -> aware.getLegacyForAccount(account, name))
+ : stackSets.get(name);
+ return stored.filter(stackSet -> id.equals(stackSet.getStackSetId()))
+ .