mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(cloudformation): check CloudFormation requests on the resources they name, from the generated request resources (#8426)
CloudFormation was not read by the request-resources generator, so under IAM enforcement every CloudFormation request was checked on *: a grant scoped to a stack or a stack set was refused, and a deny scoped to one never applied. cloudformation now moves into NAMESPACES (100 operations). One rule is fixed: an account member named after another record's shape names that record's account, not the type's (StackInstanceAccount is a StackInstance's), so a stack instance call is checked on its stack set in the caller's account. A stack or a stack set named by its name is checked on the ARN CloudFormation minted for it, which CloudFormationStoredResourceArns finds, reading only, or with its id open when it does not exist yet. A request naming its stack by no StackName (a change set by its ARN alone, DescribeStackResources by PhysicalResourceId alone) stays on *, as the generated data gives it. DescribeStackSet now returns StackSetARN, which botocore gives and Floci left out, in the Region of the request naming it.
This commit is contained in:
1 parent
9c1e5c1163
commit
0f223224ce
11 files changed
+371
-13
No files matched your search
@@ -25,7 +25,8 @@ import java.util.Optional;
|
||||
* the key an alias names; EMR, for the clusters of its instance groups; IAM Identity Center, for the accounts its
|
||||
* 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); looked up lazily by {@code ResourceArnBuilder} and
|
||||
* random suffix included, and its tags; EventBridge Scheduler, for its default schedule group; CloudFormation, for
|
||||
* the stack or the stack set a name names, whose id it minted); 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>
|
||||
*
|
||||
|
||||
@@ -92,7 +92,7 @@ public class CloudFormationQueryHandler {
|
||||
case "DescribeOrganizationsAccess" -> describeOrganizationsAccess();
|
||||
case "ActivateOrganizationsAccess" -> activateOrganizationsAccess();
|
||||
case "CreateStackSet" -> createStackSet(params);
|
||||
case "DescribeStackSet" -> describeStackSet(params);
|
||||
case "DescribeStackSet" -> describeStackSet(params, region);
|
||||
case "ListStackSets" -> listStackSets();
|
||||
case "UpdateStackSet" -> updateStackSet(params);
|
||||
case "DeleteStackSet" -> deleteStackSet(params);
|
||||
@@ -922,7 +922,7 @@ public class CloudFormationQueryHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private Response describeStackSet(MultivaluedMap<String, String> params) {
|
||||
private Response describeStackSet(MultivaluedMap<String, String> params, String region) {
|
||||
try {
|
||||
StackSet ss = stackSetService.describeStackSet(params.getFirst("StackSetName"));
|
||||
XmlBuilder xml = new XmlBuilder()
|
||||
@@ -931,6 +931,7 @@ public class CloudFormationQueryHandler {
|
||||
.start("StackSet")
|
||||
.elem("StackSetName", ss.getStackSetName())
|
||||
.elem("StackSetId", ss.getStackSetId())
|
||||
.elem("StackSetARN", stackSetService.stackSetArn(ss, region))
|
||||
.elem("Status", ss.getStatus())
|
||||
.elem("Description", ss.getDescription())
|
||||
.elem("TemplateBody", ss.getTemplateBody())
|
||||
|
||||
@@ -443,6 +443,14 @@ public class CloudFormationService implements ResourceProvider {
|
||||
.toList();
|
||||
}
|
||||
|
||||
/**
|
||||
* The id of the live stack a name or a stack id names in the caller's account and the Region, its ARN with the id
|
||||
* CloudFormation minted, which IAM checks a request naming the stack on; empty when there is none. Reads only.
|
||||
*/
|
||||
public Optional<String> stackArn(String stackNameOrArn, String region) {
|
||||
return Optional.ofNullable(resolveStack(stackNameOrArn, region, currentAccount())).map(Stack::getStackId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package io.floci.aws.services.cloudformation;
|
||||
|
||||
import io.floci.aws.core.common.StoredResourceArns;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
|
||||
import java.util.List;
|
||||
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.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class CloudFormationStoredResourceArns implements StoredResourceArns {
|
||||
|
||||
private final CloudFormationService stacks;
|
||||
private final StackSetService stackSets;
|
||||
|
||||
@Inject
|
||||
public CloudFormationStoredResourceArns(CloudFormationService stacks, StackSetService stackSets) {
|
||||
this.stacks = stacks;
|
||||
this.stackSets = stackSets;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String namespace() {
|
||||
return "cloudformation";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> find(String type, List<String> names, String region) {
|
||||
if (names.size() != 1) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return switch (type) {
|
||||
case "stack" -> stacks.stackArn(names.getFirst(), region);
|
||||
case "stackset" -> stackSets.stackSetArn(names.getFirst(), region);
|
||||
default -> Optional.empty();
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -213,6 +213,20 @@ public class StackSetService implements PassedRoleLookup, AccountPlacementListen
|
||||
return getStackSetOrThrow(name);
|
||||
}
|
||||
|
||||
/** The stack set's ARN, {@code stackset/<name>:<id>} 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());
|
||||
}
|
||||
|
||||
/**
|
||||
* The ARN of the caller's stack set of that name in the Region given, which IAM checks a request naming it on;
|
||||
* empty for none.
|
||||
*/
|
||||
public Optional<String> stackSetArn(String name, String region) {
|
||||
return name == null ? Optional.empty() : stackSets.get(name).map(stackSet -> stackSetArn(stackSet, region));
|
||||
}
|
||||
|
||||
/** The StackSet's permission model, which says whether an update naming no administration role passes the default one. */
|
||||
@Override
|
||||
public Optional<String> stackSetPermissionModel(String stackSetName) {
|
||||
|
||||
Reference in new issue
Block a user