Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions docs/services/iam.md
Original file line number Diff line number Diff line change
Expand Up @@ -2332,7 +2332,7 @@ requests retain HTTP 403 XML `AccessDenied` responses, except SNS's, which retur
action is denied. The routed protocol determines the status, not just the request's content type.

A request is checked against the resources it names. Floci builds their ARNs itself for S3,
DynamoDB, SSM, KMS, IAM, Resource Groups, API Gateway
DynamoDB, SSM, KMS, IAM, API Gateway
and CloudWatch Logs. For Secrets Manager, Elastic Load Balancing, ECR,
Step Functions, EventBridge, EventBridge Scheduler, Amazon Cognito user pools and identity pools, Amazon Data Firehose, Cloud
Map, ACM, CodePipeline, CodeBuild, Amazon Managed Service for Apache Flink (Kinesis Data Analytics v2),
Expand All @@ -2341,7 +2341,7 @@ AWS Data Exports, AWS Pricing Calculator, Cost Explorer, CloudTrail, Global Acce
Timestream for InfluxDB, Amazon Redshift, the Amazon Redshift Data API, AWS Payment Cryptography, AWS DataSync, Amazon EMR,
Amazon Rekognition, IAM Identity Center, Amazon Inspector, Amazon Macie, AWS Fault Injection Service, AWS Resource
Access Manager, CloudWatch Observability Access Manager, AWS Resource Explorer, AWS Account Management, AWS Control
Catalog, Amazon OpenSearch Service, IAM Access Analyzer, AWS Security Hub, Amazon GuardDuty, Lambda, AWS Glue, Amazon SQS, Amazon SNS, Amazon Kinesis Data Streams, Amazon EventBridge Pipes, Aurora DSQL, STS and Amazon EKS they come from a table generated from AWS's Service Reference and botocore, `src/main/resources/aws/iam-request-resources.json`, which gives each
Catalog, Amazon OpenSearch Service, IAM Access Analyzer, AWS Security Hub, Amazon GuardDuty, Lambda, AWS Glue, Amazon SQS, Amazon SNS, Amazon Kinesis Data Streams, Amazon EventBridge Pipes, Aurora DSQL, STS, Amazon EKS and AWS Resource Groups they come from a table generated from AWS's Service Reference and botocore, `src/main/resources/aws/iam-request-resources.json`, which gives each
operation's action, the resource types that action acts on with their ARN formats, and the request
members that name them: a member holding a resource's ARN, which counts when it matches the format
of a type the action acts on, or members filling the variables of a type's format. Nothing in it is
Expand Down Expand Up @@ -3537,8 +3537,9 @@ floci populates:
controls, GuardDuty for its detectors and Malware Protection plans, Cloud Map for its namespaces and services, Elastic
Load Balancing for its load balancers, target groups, listeners and rules and its Classic Load Balancers, SQS for its
queues, SNS for its topics, Kinesis Data Streams for its streams and consumers, EventBridge Pipes for its pipes,
Aurora DSQL for its clusters and EKS for its clusters, node groups, Fargate profiles, add-ons, Pod Identity
associations and access entries. Tag keys differing only in case are one condition key holding every value.
Aurora DSQL for its clusters, EKS for its clusters, node groups, Fargate profiles, add-ons, Pod Identity
associations and access entries and Resource Groups for its groups. 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@
* 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
Expand Down
17 changes: 0 additions & 17 deletions src/main/java/io/floci/aws/services/iam/ResourceArnBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ public List<String> buildResources(String credentialScope, String operation, Con
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);
Expand Down Expand Up @@ -219,22 +218,6 @@ private StoredResourceArns storedResourceArns(String namespace) {
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,22 @@ private static String key(String region, String name) {
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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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));
}
}
Loading
Loading