Repository navigation
fix(iam): check CloudWatch Logs requests on the resources they name, from the generated table - #9088
Conversation
PR Summary by QodoCheck CloudWatch Logs IAM requests against generated resource ARNs
AI Description
Merge Risk
|
Code Review by Qodo
1.
|
22da33c to
e37ede1
Compare
e37ede1 to
71b4017
Compare
…from the generated table CloudWatch Logs was built by hand: ResourceArnBuilder built a group or stream ARN for six operations and resolved the tag operations' ARN itself, every other Logs operation was checked on *, and only the vended-log delivery operations and PutDestination were read from the request resources table, through READ_IN_HAND_BUILT. logs moves from HAND_BUILT to NAMESPACES, so the table gives each of its 118 operations the log group, stream, destination or delivery resource its request names, from botocore and the Service Reference: PutLogEvents, FilterLogEvents, metric and subscription filters, StartQuery and the other operations on a group or stream are checked on it, no longer on *. READ_IN_HAND_BUILT, whose only entries were Logs', goes with its checks and tests. ResourceArnBuilder's buildLogResources and the filter's Logs case go; the tagged CreateLogGroup check reads the table's bare group ARN, which the evaluator already matches with or without the trailing :* for the group's management actions. CloudWatchLogsStoredResourceArns answers the stored tags of a log group, a destination and the delivery family; IamConditionContextResolver keeps only the request tags of Logs' create and tag calls. Log group tag writes give the group a new map under the lock creating and deleting a group take, so one racing a delete cannot put the group back, and its tags field is volatile. Only Logs' operations change in the table.
71b4017 to
51e04ce
Compare
Summary
CloudWatch Logs was one of the namespaces
ResourceArnBuilderbuilt by hand, and the last one the generator read only in part. The builder made a group ARN (with a trailing:*) forCreateLogGroup,DeleteLogGroup,PutRetentionPolicyandDeleteRetentionPolicy, a stream ARN forCreateLogStreamandDeleteLogStream, and resolved the tag operations'resourceArnitself. Every other Logs operation was checked on*,PutLogEvents,FilterLogEvents, metric and subscription filters and Insights queries among them. Only the vended-log delivery operations andPutDestinationcame fromiam-request-resources.json, throughREAD_IN_HAND_BUILT. Logs now comes from the generated table whole, as every namespace is meant to.logsmoves fromHAND_BUILTtoNAMESPACES, and the generator's existing rules give each of its 118 operations the log group, log stream, destination, lookup table, anomaly detector, scheduled query or delivery resource its request names, from botocore and the Service Reference. Of the 53 operations Floci serves, about 25 that were checked on*are now checked on their group, stream or destination, so a policy scoped to one group or stream now means something for them, as on AWS; a policy on*passes as before. The ARNs take the request's partition.ResourceArnBuilder.buildLogResourcesandIamEnforcementFilter's Logs case are gone.READ_IN_HAND_BUILTis gone. Its only entries were Logs' 14 operations, so the list,reads()'s clause for it, its checks in_check_overridesandverify_against, the docstring paragraph and its two tests go with it. A hand-built namespace now reads only whatMEASUREDgives (DynamoDB'sListTables).log-group:<name>, without the trailing:*the builder added.IamPolicyEvaluatoralready matches a policy naming the group with or without:*forCreateLogGroup,DeleteLogGroup,PutRetentionPolicy,DeleteRetentionPolicyandTagLogGroup, so policies written either way keep working for those. The taggedCreateLogGroupcheck, which takes eitherlogs:TagResourceorlogs:TagLogGroup, now reads the table's bare group ARN for both instead of cutting:*off the builder's.CloudWatchLogsStoredResourceArnsanswersstoredTagsfor a log group (read in place by the name its ARN gives, a trailing:*dropped as the tag handlers drop it, in the ARN's Region), a destination and a delivery source, delivery destination or delivery, all in the request's account. A resource Floci does not hold has none; any other lookup failure is thrown, so it cannot pass for a resource without tags.IamConditionContextResolver's Logs branch keeps only what no generated source gives, the request tags of a taggedCreateLogGroup,TagResourceandUntagResource, and its two Logs service dependencies go.TagLogGroupandUntagLogGroupchanged the group's tag map in place without a lock; they now give the group a new map under the lock creating and deleting a group take, so a tag call racing a delete cannot put the group back, and its tags field is volatile.make iam-request-resources-checkpasses on it.Where the generated reading differs from the builder's, stated plainly:
CreateLogStream,DeleteLogStream) no longer carries its log group's tags asaws:ResourceTag/<key>. Floci holds no tags on a stream, and nothing AWS publishes gives a stream its group's tags, so a stream ARN has none. A condition on the group's tags no longer matches a stream call.*. A group ARN given with a trailing:*is checked as written.log-grouptype,FilterLogEvents,DescribeLogStreams, the metric and subscription filter calls andStartQueryamong them, are checked on the group's ARN as that type's format gives it,log-group:<name>. A policy naming the group aslog-group:<name>:*does not match them, as it did not before, when they were checked on*; one naming the bare group ARN now matches them, an Allow and a Deny alike.IamPolicyEvaluatormatches both forms only for the five group-management actions above. A policy on*matches them as before, and one onlog-group:*now matches them too.GetLogEvents,FilterLogEventsand the other operations that also takelogGroupIdentifierare checked on the group theirlogGroupNamenames. A request naming the group only bylogGroupIdentifieris checked on*, as all of them were before.Type of change
fix:)feat:)feat!:orfix!:)AWS Compatibility
The Service Authorization Reference gives CloudWatch Logs the types
log-group(arn:${Partition}:logs:${Region}:${Account}:log-group:${LogGroupName}),log-stream(...:log-group:${LogGroupName}:log-stream:${LogStreamName}),destination,delivery-source,delivery-destination,delivery,anomaly-detector,lookup-tableandscheduled-query, each withaws:ResourceTag/${TagKey}, and lists the type each action acts on:PutLogEventsandGetLogEventsonlog-stream;FilterLogEvents,DescribeLogStreams,PutMetricFilter,PutSubscriptionFilterandStartQueryonlog-group, among others. The CloudWatch Logs guide's access control overview gives a log group's ARN with and without the trailing:*.Checklist
./mvnw testpasses locally (ran the generator's tests, the request resource reader, builder, filter and condition context tests, every Logs test class that needs no Docker, the CloudFormation and Lambda classes that use Logs, the Logs IAM integration test classes, and the IAM enforcement classes that check resource-tag conditions, not the whole suite)