mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(iam): check Resource Groups requests on the groups the generated table gives them (#9074)
Resource Groups was built by hand: ResourceArnBuilder read a group from the body's Group or GroupName, or CreateGroup's Name, the request resources table held no Resource Groups operation, and nothing gave a policy condition a group's tags. resource-groups moves from HAND_BUILT to NAMESPACES, so the table gives each operation the group its Group names, by its name or its ARN, and the ARN a tagging route carries; CreateGroup, for which the Service Reference lists no resource type, is checked on *, as AWS checks it. ResourceArnBuilder's Resource Groups branch goes. ResourceGroupsStoredResourceArns answers a group's stored tags, read in place from the group record the service stores whole. Only Resource Groups' operations change in the table.
This commit is contained in:
1 parent
ab7fc6f81f
commit
dc97ce5cb1
9 files changed
+196
-54
No files matched your search
@@ -61,9 +61,9 @@ import java.util.Optional;
|
||||
* group, a listener, a rule or a Classic Load Balancer; SQS, for the tags of a queue; SNS, for the tags of a topic;
|
||||
* Kinesis Data Streams, for the tags of a stream or a consumer; EventBridge Pipes, for the tags of a pipe; Aurora DSQL,
|
||||
* for the tags of a cluster; EKS, for the tags of a cluster, a node group, a Fargate profile, an add-on, a Pod Identity
|
||||
* association or an access entry); 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>
|
||||
* association or an access entry; Resource Groups, for the tags of a group); 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
|
||||
|
||||
@@ -172,7 +172,6 @@ public class ResourceArnBuilder {
|
||||
case "s3" -> buildS3Resources(operation, path, ctx, region);
|
||||
case "dynamodb" -> buildDynamoDbArns(ctx, region, accountId);
|
||||
case "iam" -> buildIamArns(ctx, region, accountId);
|
||||
case "resource-groups" -> List.of(buildResourceGroupArn(ctx, region, accountId));
|
||||
case "apigateway" -> List.of(buildApiGatewayArn(ctx, region, partition));
|
||||
case "bedrock" -> List.of(buildBedrockArn(path, ctx));
|
||||
default -> namedResources(credentialScope, operation, ctx, region, accountId, partition);
|
||||
@@ -219,22 +218,6 @@ public class ResourceArnBuilder {
|
||||
return null;
|
||||
}
|
||||
|
||||
private String buildResourceGroupArn(ContainerRequestContext ctx, String region, String accountId) {
|
||||
JsonNode body = readJsonBody(ctx);
|
||||
if (body == null) {
|
||||
return "*";
|
||||
}
|
||||
String path = IamActionRegistry.decodedPath(ctx);
|
||||
boolean create = path.endsWith("/groups") || path.endsWith("/groups/");
|
||||
String group = create ? body.path("Name").asText()
|
||||
: body.path("Group").asText(body.path("GroupName").asText());
|
||||
if (group.isEmpty()) {
|
||||
return "*";
|
||||
}
|
||||
return AwsArnUtils.looksLikeArn(group) ? group
|
||||
: AwsArnUtils.Arn.of("resource-groups", region, accountId, "group/" + group).toString();
|
||||
}
|
||||
|
||||
/** Uses the serving operation and the same raw names as the handler. */
|
||||
public List<String> buildLogResources(String action, ContainerRequestContext ctx,
|
||||
String region, String accountId, String partition) {
|
||||
|
||||
@@ -326,6 +326,22 @@ public class ResourceGroupsService implements Resettable {
|
||||
return region + "::" + name;
|
||||
}
|
||||
|
||||
/**
|
||||
* The tags of the group whose ARN is {@code arn} in {@code account}, read in place under the key the handlers read,
|
||||
* its name in the ARN's Region, and matched on the whole ARN it records; none when there is no such group. A group
|
||||
* is stored whole, so the read is of one whole set.
|
||||
*/
|
||||
Map<String, String> groupTagsInAccount(String account, String arn) {
|
||||
AwsArnUtils.Arn parsed = AwsArnUtils.parse(arn);
|
||||
if (!parsed.resource().startsWith("group/")) {
|
||||
return Map.of();
|
||||
}
|
||||
return AccountAwareStorageBackend.readInAccount(groups, account,
|
||||
key(parsed.region(), parsed.resource().substring("group/".length())))
|
||||
.filter(group -> arn.equals(group.arn()))
|
||||
.map(ResourceGroup::tags).orElse(Map.of());
|
||||
}
|
||||
|
||||
private static String text(JsonNode object, String field, boolean required) {
|
||||
JsonNode value = object.get(field);
|
||||
if ((value == null || value.isNull()) && !required) {
|
||||
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
package io.floci.aws.services.resourcegroups;
|
||||
|
||||
import io.floci.aws.core.common.AwsArnUtils;
|
||||
import io.floci.aws.core.common.RegionResolver;
|
||||
import io.floci.aws.core.common.StoredResourceArns;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/** IAM's lookup of the tags Resource Groups holds on a group, for the {@code resource-groups} namespace. */
|
||||
@ApplicationScoped
|
||||
public class ResourceGroupsStoredResourceArns implements StoredResourceArns {
|
||||
|
||||
private static final String NAMESPACE = "resource-groups";
|
||||
|
||||
private final ResourceGroupsService groups;
|
||||
private final RegionResolver regionResolver;
|
||||
|
||||
@Inject
|
||||
public ResourceGroupsStoredResourceArns(ResourceGroupsService groups, RegionResolver regionResolver) {
|
||||
this.groups = groups;
|
||||
this.regionResolver = regionResolver;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String namespace() {
|
||||
return NAMESPACE;
|
||||
}
|
||||
|
||||
/** A request names a group by its name or its ARN: nothing to find. */
|
||||
@Override
|
||||
public Optional<String> find(String type, List<String> names, String region) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* The tags of the group whose ARN is {@code arn}, in the request's account, where the handlers read: an ARN of
|
||||
* another account names none. The group is read in place by the name its ARN gives, in the ARN's Region, and
|
||||
* matched on the whole ARN it records. A tag without a value reads as an empty one.
|
||||
*/
|
||||
@Override
|
||||
public Map<String, String> storedTags(String arn) {
|
||||
if (!AwsArnUtils.isArnFor(arn, NAMESPACE)) {
|
||||
return Map.of();
|
||||
}
|
||||
AwsArnUtils.Arn parsed = AwsArnUtils.parse(arn);
|
||||
String account = regionResolver.getAccountId();
|
||||
if (!parsed.accountId().equals(account) || parsed.region().isBlank()) {
|
||||
return Map.of();
|
||||
}
|
||||
return StoredResourceArns.withEmptyValues(groups.groupTagsInAccount(account, arn));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user