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
49 changes: 26 additions & 23 deletions docs/services/iam.md
Original file line number Diff line number Diff line change
Expand Up @@ -2332,16 +2332,15 @@ 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, API Gateway
and CloudWatch Logs. For Secrets Manager, Elastic Load Balancing, ECR,
DynamoDB, SSM, KMS, IAM and API Gateway. 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),
Application Auto Scaling, AWS Budgets, Cost and Usage Reports, Service Quotas, Amazon Textract, Amazon Translate, Amazon Athena,
AWS Data Exports, AWS Pricing Calculator, Cost Explorer, CloudTrail, Global Accelerator, Amazon
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, 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
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, AWS Resource Groups and Amazon CloudWatch Logs 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 @@ -3088,42 +3087,47 @@ These identities always bypass enforcement (backward-compatible defaults):
| No `Authorization` header | **Rejected** for a JSON, CBOR or Query management call, unless AWS serves the operation without credentials. Allowed for a REST request such as a health check (see [Unsigned requests](#unsigned-requests)) |
| Unresolvable IAM action for the request | Allowed — unknown mappings are permissive |

**CloudWatch Logs streams.** `logs:CreateLogStream` and `logs:DeleteLogStream` evaluate the
specific log-stream ARN, so policies can allow or deny one stream within a group. Their
`aws:ResourceTag/<key>` conditions read the owning log group's current tags in the request's
account and region. Both stream operations check the documented group and stream name constraints
**CloudWatch Logs streams.** `logs:CreateLogStream`, `logs:DeleteLogStream`, `logs:PutLogEvents` and
`logs:GetLogEvents` are checked on the log-stream ARN their group and stream names give, from the generated
table, so policies can allow or deny one stream within a group. A stream ARN carries no
`aws:ResourceTag/<key>`: Floci holds no tags on a stream, and nothing AWS publishes gives a stream its group's.
`CreateLogStream` and `DeleteLogStream` check the documented group and stream name constraints
before changing storage, preventing delimiter aliases from targeting another stream.
These checks also apply to deletion: legacy streams with names containing `:` or `*` cannot be
deleted through `DeleteLogStream`. Existing stored names are not automatically migrated.

**CloudWatch Logs groups.** `CreateLogGroup`, `DeleteLogGroup`, `PutRetentionPolicy` and
`DeleteRetentionPolicy` accept policy resources naming the selected group with a bare ARN
or its legacy `:*` form. Both forms participate in each statement, including explicit denies
and `NotResource`, without bypassing session, boundary or SCP ceilings. The three operations on
existing groups read that group's resource tags; creation uses the request's `tags` for
**CloudWatch Logs groups.** An operation on a log group, `FilterLogEvents`, `DescribeLogStreams`, metric and
subscription filters and `StartQuery` among them, is checked on the group's bare ARN, as the Service Reference
formats a log group, from the generated table. `CreateLogGroup`, `DeleteLogGroup`, `PutRetentionPolicy`,
`DeleteRetentionPolicy` and `TagLogGroup` also accept policy resources naming the selected group with its legacy
`:*` form. Both forms participate in each statement, including explicit denies
and `NotResource`, without bypassing session, boundary or SCP ceilings. An operation on an
existing group reads that group's resource tags; creation uses the request's `tags` for
`aws:RequestTag/<key>` and `aws:TagKeys`. Tagged creation additionally requires either
`logs:TagResource` on the bare group ARN or `logs:TagLogGroup` on either group ARN form.
The group name constraints apply before mutation, and deletion preserves streams and filters
whose stored group identity belongs to another historical group. These four operations reject `:`
or `*` in a group name. Historical names remain taggable through the ARN tagging APIs below;
they cannot be newly created or deleted through the group lifecycle APIs. Stored names are not migrated.

**CloudWatch Logs ARN tagging.** For log groups, `logs:TagResource`, `logs:UntagResource`
and `logs:ListTagsForResource` evaluate the group's ARN without a trailing `:*`. The ARN must
**CloudWatch Logs ARN tagging.** `logs:TagResource`, `logs:UntagResource` and
`logs:ListTagsForResource` are checked on the ARN their `resourceArn` carries, from the generated table, for each
type the Service Reference gives them: a log group, a destination, a delivery source, a delivery destination or a
delivery. For a log group the ARN must
identify a group in the request's account, region and partition; a different owner or resource
kind returns `ResourceNotFoundException` without reading or changing a local group's tags.
All three actions use the group's existing `aws:ResourceTag/<key>` conditions. `TagResource`
All three actions use the resource's existing `aws:ResourceTag/<key>` conditions. `TagResource`
also provides `aws:RequestTag/<key>` and `aws:TagKeys`; `UntagResource` provides `aws:TagKeys`.
An unauthorized request cannot partially add or remove tags. These ownership checks also apply
when IAM enforcement is disabled. Shared tag mutations reject storage aliases whose stored group
name differs from the requested name, without migrating historical records.

This support covers log groups. Tagging destinations and other CloudWatch Logs resource types
remains unsupported. Plain-name inputs are used literally, including incomplete prefixes such as
The tag handlers also take a plain group name, used literally, including incomplete prefixes such as
`arn:archive`; arbitrary `:log-group:` substrings never select a different group. Structurally complete
ARNs take precedence over plain-name interpretation and must identify a local group. A trailing `:*`
is accepted on a canonical local group ARN. These compatibility forms are not a claim that AWS accepts
them for these APIs. Other Logs actions retain their existing wildcard resource evaluation.
them for these APIs, and authorization reads `resourceArn` as AWS does: a plain name names nothing the
table reads, so the call is checked on `*`, and a group ARN with a trailing `:*` is checked as written.

**CloudWatch Logs account policies.** `PutAccountPolicy` also needs the action for the type of
policy it creates, checked against `*` like `logs:PutAccountPolicy` itself: `logs:PutDataProtectionPolicy`
Expand Down Expand Up @@ -3503,9 +3507,7 @@ floci populates:
`ResourceId.N` or `InstanceId.N`), and for `s3:GetBucketTagging`, `s3:DeleteBucket` and the
`s3:PutBucketTagging` that `DeleteBucketTagging` is checked as (the bucket). A request naming several EC2 resources is evaluated
once per resource and denied when any of them fails the condition, as on AWS.
`logs:CreateLogStream`, `logs:DeleteLogStream`, `logs:TagResource`, `logs:UntagResource`,
`logs:ListTagsForResource`, `logs:DeleteLogGroup`, `logs:PutRetentionPolicy` and
`logs:DeleteRetentionPolicy` use the owning log group's tags. Any other ARN a request is checked on
Any other ARN a request is checked on
takes the resource-tag keys the generated `resourceTagKeys` table in `iam-request-resources.json` gives
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
Expand Down Expand Up @@ -3538,8 +3540,9 @@ floci populates:
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, 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.
associations and access entries, Resource Groups for its groups and CloudWatch Logs for its log groups,
destinations, delivery sources, delivery destinations and deliveries. 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 @@ -5,10 +5,6 @@
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.floci.aws.config.EmulatorConfig;
import io.floci.aws.services.cloudwatch.logs.CloudWatchLogsCrossAccountService;
import io.floci.aws.services.cloudwatch.logs.CloudWatchLogsDeliveryService;
import io.floci.aws.services.cloudwatch.logs.CloudWatchLogsService;
import io.floci.aws.services.cloudwatch.logs.LogGroupTagTarget;
import io.floci.aws.services.dynamodb.DynamoDbConditionKeys;
import io.floci.aws.services.dynamodb.DynamoDbFacade;
import io.floci.aws.services.dynamodb.DynamoDbPartiQLParser;
Expand Down Expand Up @@ -111,8 +107,6 @@ public class IamConditionContextResolver {
private final Instance<DynamoDbFacade> dynamoDbFacade;
private final Instance<Ec2Service> ec2Service;
private final Instance<S3Service> s3Service;
private final Instance<CloudWatchLogsService> logsService;
private final Instance<CloudWatchLogsCrossAccountService> crossAccountService;
private final Instance<IamService> iamService;
private final Instance<LambdaWebService> lambdaWebService;
private final Instance<RequestConditionSpelling> requestConditionSpellings;
Expand All @@ -132,8 +126,6 @@ public class IamConditionContextResolver {
public IamConditionContextResolver(Instance<DynamoDbFacade> dynamoDbFacade,
Instance<Ec2Service> ec2Service,
Instance<S3Service> s3Service,
Instance<CloudWatchLogsService> logsService,
Instance<CloudWatchLogsCrossAccountService> crossAccountService,
Instance<IamService> iamService,
Instance<LambdaWebService> lambdaWebService,
Instance<RequestConditionSpelling> requestConditionSpellings,
Expand All @@ -143,16 +135,14 @@ public IamConditionContextResolver(Instance<DynamoDbFacade> dynamoDbFacade,
EmulatorConfig config,
CurrentVertxRequest currentVertxRequest,
ResolvedServiceCatalog serviceCatalog) {
this(dynamoDbFacade, ec2Service, s3Service, logsService, crossAccountService, iamService,
this(dynamoDbFacade, ec2Service, s3Service, iamService,
lambdaWebService, requestConditionSpellings, storedResourceArns, requestContext, regionResolver,
config, currentVertxRequest, serviceCatalog, Clock.systemUTC());
}

IamConditionContextResolver(Instance<DynamoDbFacade> dynamoDbFacade,
Instance<Ec2Service> ec2Service,
Instance<S3Service> s3Service,
Instance<CloudWatchLogsService> logsService,
Instance<CloudWatchLogsCrossAccountService> crossAccountService,
Instance<IamService> iamService,
Instance<LambdaWebService> lambdaWebService,
Instance<RequestConditionSpelling> requestConditionSpellings,
Expand All @@ -165,8 +155,6 @@ public IamConditionContextResolver(Instance<DynamoDbFacade> dynamoDbFacade,
this.dynamoDbFacade = dynamoDbFacade;
this.ec2Service = ec2Service;
this.s3Service = s3Service;
this.logsService = logsService;
this.crossAccountService = crossAccountService;
this.iamService = iamService;
this.lambdaWebService = lambdaWebService;
this.requestConditionSpellings = requestConditionSpellings;
Expand Down Expand Up @@ -298,81 +286,35 @@ public Map<String, List<String>> resolve(String credentialScope, String action,
};
}

/** Logs tag operations and group mutations use the handler's resource and request scope. */
/**
* The tags a CloudWatch Logs call asks to attach or remove, read as its handler reads them: a tagged
* {@code CreateLogGroup}'s and a {@code TagResource}'s {@code tags} as {@code aws:RequestTag/<key>} and
* {@code aws:TagKeys}, an {@code UntagResource}'s {@code tagKeys} as {@code aws:TagKeys}. The tags of what the
* request names come from Logs' {@link StoredResourceArns}, as for every namespace the table reads.
*/
private Map<String, List<String>> logsConditionContext(String action, ContainerRequestContext ctx) {
if (!("logs:CreateLogStream".equals(action) || "logs:DeleteLogStream".equals(action)
|| LogGroupTagTarget.supports(action) || "logs:CreateLogGroup".equals(action) || "logs:DeleteLogGroup".equals(action)
|| "logs:PutRetentionPolicy".equals(action) || "logs:DeleteRetentionPolicy".equals(action))) {
if (!("logs:CreateLogGroup".equals(action) || "logs:TagResource".equals(action)
|| "logs:UntagResource".equals(action))) {
return null;
}
JsonNode body = bufferedJsonBody(ctx);
if (body == null) {
return null;
}
if ("logs:CreateLogGroup".equals(action)) {
JsonNode tags = body.path("tags");
if (!tags.isObject() || tags.isEmpty()) {
return null;
}
Map<String, List<String>> conditions = new LinkedHashMap<>();
List<String> keys = new ArrayList<>();
tags.properties().forEach(entry -> {
keys.add(entry.getKey());
conditions.put("aws:RequestTag/" + entry.getKey(), List.of(entry.getValue().asText()));
});
conditions.put("aws:TagKeys", keys);
return conditions;
}
boolean direct = LogGroupTagTarget.supports(action);
boolean destination = direct && CloudWatchLogsCrossAccountService.isCrossAccountDestinationArn(
body.path("resourceArn").asText());
if (destination ? !crossAccountService.isResolvable() : !logsService.isResolvable()) {
return null;
}
String region = requestContext.getRegion() == null ? config.defaultRegion() : requestContext.getRegion();
Map<String, List<String>> conditions = new LinkedHashMap<>();
if ("logs:TagResource".equals(action) && body.path("tags").isObject()) {
List<String> keys = new ArrayList<>();
body.path("tags").fields().forEachRemaining(entry -> {
List<String> keys = new ArrayList<>();
if ("logs:UntagResource".equals(action)) {
body.path("tagKeys").forEach(key -> keys.add(key.asText()));
} else if (body.path("tags").isObject()) {
body.path("tags").properties().forEach(entry -> {
keys.add(entry.getKey());
conditions.put(REQUEST_TAG_PREFIX + entry.getKey(), List.of(entry.getValue().asText()));
});
if (!keys.isEmpty()) {
conditions.put("aws:TagKeys", keys);
}
} else if ("logs:UntagResource".equals(action)) {
List<String> keys = new ArrayList<>();
body.path("tagKeys").forEach(key -> keys.add(key.asText()));
if (!keys.isEmpty()) {
conditions.put("aws:TagKeys", keys);
}
}
if (direct && CloudWatchLogsDeliveryService.isDeliveryResourceArn(body.path("resourceArn").asText())) {
// A delivery source, destination or delivery: its request tags apply, its own tags are not read.
return conditions.isEmpty() ? null : conditions;
}
Map<String, String> tags;
try {
if (destination) {
tags = crossAccountService.get().listDestinationTags(body.path("resourceArn").asText(), region);
} else {
String group = direct ? logsService.get().resolveTagTarget(body.path("resourceArn").asText(), region).name()
: body.path("logGroupName").asText();
tags = logsService.get().listTagsLogGroup(group, region);
}
} catch (AwsException e) {
if (!"ResourceNotFoundException".equals(e.getErrorCode())) {
throw e;
}
// Leave the handler to report a missing resource; unexpected lookup errors must not hide a deny.
return conditions.isEmpty() ? null : conditions;
}
if (tags == null || tags.isEmpty()) {
return conditions.isEmpty() ? null : conditions;
if (!keys.isEmpty()) {
conditions.put("aws:TagKeys", keys);
}
tags.forEach((key, value) -> conditions.put(RESOURCE_TAG_PREFIX + key,
List.of(value == null ? "" : value)));
return conditions;
return conditions.isEmpty() ? null : conditions;
}

/** The condition key whose value a delegation can decide rather than the request. */
Expand Down
Loading
Loading