Repository navigation
fix(ec2,iam): authorize a tagging call against every resource it names (#674) - #682
Merged
Merged
Conversation
#674) CreateTags and DeleteTags accept up to 1000 resource IDs of mixed types, and substrate decided all of them against a single ARN built from InstanceId.1 — a parameter neither operation carries — so every tagging call was decided against the literal string "*". That broke in both directions, because resourceMatches passes the statement's own Resource to globMatch as the pattern: an ARN-scoped Deny never matched, so a guardrail fencing off a shared resource was silently inert, and a least-privilege Allow naming the ARNs could not grant a tagging call at all. Each named resource now resolves to its own ARN paired with its own tags, so aws:ResourceTag conditions and the permission boundary are evaluated per resource. The ARN resource type is stated rather than derived from substrate's state key: five of the nine taggable prefixes differ (sg/security-group, igw/internet-gateway, rtb/route-table, eip/elastic-ip, nat/natgateway), so one function now returns both and they cannot drift. The aws:RequestTag fix is coupled and mandatory. addRequestTags read only TagSpecification.N.Tag.M.*, so the Tag.N.Key/Tag.N.Value form a direct tagging call sends left aws:RequestTag/* empty — resolving the ARNs without it would have turned AWS's own documented CreateTags policies from a false allow into a false deny. Closes #674
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CreateTagsandDeleteTagsaccept up to 1000 resource IDs of mixed types, and substrate decided all of them against a single ARN built fromInstanceId.1— a parameter neither operation carries. Every tagging call was therefore decided against the literal string"*".That broke in both directions, and the reason is
resourceMatches: it passes the statement's ownResourcetoglobMatchas the pattern, so"*"as the request resource matches only a statement whoseResourceitself begins with"*".Denyscoped to one instance, subnet, volume or security group was inert. A guardrail fencing a shared or production resource off from a pipeline that re-tags everything it can see read as a boundary and was not one.Allownaming those ARNs could not grant a tagging call at all.Each named resource now resolves to its own ARN paired with its own tags, so
aws:ResourceTagconditions and the permission boundary are evaluated per resource, and the denial names the first resource the policy does not allow.The ARN resource type is stated, not derived
Five of the nine taggable ID prefixes have a state-key abbreviation that differs from the ARN resource type:
sg→security-group,igw→internet-gateway,rtb→route-table,eip→elastic-ip,nat→natgateway. String-munging the state key would producearn:…:sg/sg-…, which matches nothing a caller writes.ec2TaggableResourcenow returns(stateKey, arnType, ok)andec2TaggableStateKeycalls it, so the two lists cannot drift.An unrecognized ID prefix is skipped, not denied and not widened
AWS answers a tagging ID it cannot parse with
InvalidID— "The specified ID for the resource you are trying to tag is not valid" — notAccessDenied, and it is the handler's answer to owe. Widening to"*"would match a broadAllowand quietly grant more than the caller wrote. So the ID is omitted from the resource list, followingec2AuthzRunInstancesResources' rule for a resource the request does not name; a request naming only such IDs returnsniland is decided exactly as before.The
aws:RequestTagfix is coupled and mandatoryaddRequestTags' ec2 arm read onlyTagSpecification.N.Tag.M.Key/Value. A directCreateTags/DeleteTagssendsTag.N.Key/Tag.N.Value, soaws:RequestTag/*was empty for every direct tagging call. Resolving the ARNs without this would have turned AWS's own documentedCreateTagspolicies from a false allow into a false deny. TheTagSpecificationwalk is untouched, including its #468 comment about deliberately not filtering by resource type.DeleteTags' optional tag value records as"", whichconditionMatchescannot distinguish from an absent key for any operator includingNull— so no new denial arises from it.Atomicity comes free
CheckAccessruns entirely before the handler, so a refused mixed-resource call writes nothing — not even to the resources the policy permits. That is the same all-or-nothing shapecreateTags' own reserved-key and tag-limit checks already have, and the e2e journey asserts it.Fail-before evidence
Unit tier, with the source reverted and the new tests in place: 38 failing cases across the 6 new tests — every scoped-
Denyand least-privilege subtest resolving to"*"instead of the expected ARN, and theaws:RequestTagsubtests denied withnot authorized … on resource: *.SDK tier,
test/e2e/journey_ec2_tag_authz_test.goagainst the unfixed emulator:Honest caveat:
TestEC2_TagAuthz_PermissionBoundaryCoversEveryResourcepasses both before and after. The boundary check is already inside the decision loop, so that criterion is satisfied by construction — the test is a regression guard, not a fail-before proof.Mutation testing
Green baseline; anchor counts asserted over the whole file;
gofmt -w && go vetso a non-compiling mutant is BROKEN rather than a result; full-packagego test -race -count=1 ./emulator/with no-runfilter. All four targets killed, no survivors:ResourceIdis evaluatedsg)aws:RequestTagwalk overTag.Nis droppedLive run
substrate server --address :4678from a scratch directory, real AWS CLI,AWS_MAX_ATTEMPTS=1, a real IAM user with an access key (the built-in key resolves to no principal and is unenforced):create-tags --resources <instance> <volume>underAllow ec2:*+Deny ec2:CreateTagson the volume ARN →AccessDenied, naming the volume ARN — and both resources came back with[]tags.Env=test.Allownaming both ARNs → succeeds, volume carriesEnv=prod.AccessDenied, naming the volume ARN.Condition: StringEquals aws:RequestTag/Env=test→Env=testsucceeds;Env=stagingdenied.delete-tagsunder aDenyon the volume ARN →AccessDenied, andEnv=prodsurvives.create-tags --resources tgw-…under a broadAllow→ 200, noAccessDenied.Provenance
Neither action has a required resource type — the Service Authorization Reference marks zero of the 105 resource types it lists for either one. Authorizing against every named resource instead rests on AWS's general rule for an action naming several resources, which the Organizations counterpart (#660) and
RunInstances(#662) already follow here, and on AWS's own scoped tagging examples, which writeinstance/*as theResourceof anec2:CreateTagsstatement and would be pointless if only one resource of a batch were evaluated. The nine ARN formats come from the SAR's resource-types table:arn:${Partition}:ec2:${Region}:${Account}:{type}/{id}for all nine — none has theimageARN's deliberately empty account field.Two AWS behaviours are not modelled and are named in the docs as such:
aws:TagKeysis populated nowhere in the emulator, so theForAllValues:StringEqualsform three of AWS'sDeleteTagsexamples use cannot be satisfied; and the second authorization pass AWS performs onec2:CreateTagswhen a resource-creating action carries tags, keyed onec2:CreateAction, which substrate does not model at all.DeleteTagsdoes not carryec2:CreateAction, so the two actions are identical in resource resolution and differ only in condition-key surface.Compatibility
A multi-resource
CreateTags/DeleteTagsthat a broad-allow-plus-scoped-deny policy previously carried may now be denied — that is the defect, and the denial is the correct answer. Anaws:RequestTagcondition on a direct tagging call now evaluates against keys that were previously absent, so a policy requiring one now grants the calls that satisfy it and denies the ones that do not; previously it could grant neither. Callers with no principal (the built-in unenforced key) are unaffected.Verification
Closes #674