Repository navigation
fix(iam): ListPolicies applies its filters and sees the catalog (#497) - #646
Merged
Merged
Conversation
ListPolicies parsed Scope and PathPrefix and applied neither, and it enumerated only policies created through CreatePolicy — so the 52 bundled AWS managed policies were invisible to every listing. `--scope AWS` returned whatever the caller happened to have created. The pairing that broke is the one a reader assumes: an ARN GetPolicy resolves appeared in no listing, so a consumer discovering a policy rather than hardcoding its ARN had no testable path at all. Scope now selects the source, and a value outside All/AWS/Local is a ValidationError naming the permitted set. PathPrefix filters on Path, which is why the catalog keeps the path in its own field rather than folded into PolicyName. A prefix must begin and end with a slash per policyPathType, so "/service-role" — the natural typo — is refused here as it is by IAM. AttachmentCount is derived from state rather than read from the stored field. The catalog carries 0 for every bundled policy and no attach increments a count anywhere, so reading the field would leave OnlyAttached=true unable to ever return a managed policy. Counting the three attachment prefixes makes an attach and a detach immediately visible. The listed copy is local, because ListManagedPolicies hands back shared pointers. PolicyUsageFilter is validated and deliberately narrows nothing: the reference does not say which side an entirely-unused policy falls on, and in a fresh substrate every bundled policy is unused, so guessing would drop all 52 from a filtered listing — this bug under a different parameter. Pagination is keyed on the ARN rather than the state key, so the two arms interleave in one stable order. A test walks the listing ten at a time and asserts the pages reassemble the unpaged result exactly, which matters now that the result set pages under the default MaxItems. Closes #497
Codecov Report❌ Patch coverage is
📢 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.
ListPoliciesparsedScopeandPathPrefixand applied neither, and it enumerated onlypolicies created through
CreatePolicy— so the 52 bundled AWS managed policies wereinvisible to every listing.
--scope AWSreturned whatever the caller happened to havecreated and
--path-prefix /service-role/returned the same thing.The pairing that broke is the one a reader assumes: an ARN
GetPolicyresolves appeared inno listing, so a consumer discovering a policy rather than hardcoding its ARN — the whole
point of
list-policies --scope AWS --path-prefix /service-role/then picking a name — hadno testable path at all. A test now walks the entire catalog and asserts every listed ARN
resolves through
GetPolicy, over the whole set rather than a sample, because the failuremode is one entry whose ARN was built differently.
The filters
Scopeselects the source:AWSthe catalog,LocalwhatCreatePolicywrote,Allor absent both. A value outside
All/AWS/Localis aValidationErrornaming thepermitted set, and case matters —
awsis notAWS.PathPrefixfilters onPath. This is whatmpAtkept the path in its own field forrather than folding into
PolicyName. A prefix must begin and end with a slash perpolicyPathType, so/service-role— the natural typo — is refused here as it is by IAM,rather than passing against substrate and failing against AWS.
OnlyAttachednarrows to policies with a non-zero count. See below for why thatrequired a change of source.
PolicyUsageFilteris validated and deliberately narrows nothing (below).AttachmentCount had to become derived
The catalog carries
AttachmentCount: 0for every bundled policy, and no attach operationincrements a count anywhere —
AttachUserPolicyand its siblings record the ARN on theentity's list and never touch the policy. So a listing reading the stored field would report
0 forever, and
OnlyAttached=truecould never return a managed policy, which is the issue'sfourth acceptance criterion.
Counting the
user_policies:/group_policies:/role_policies:lists instead means anattach and a detach are both immediately visible, and reaches all three entity kinds in
one pass over three prefixes without loading a single entity record. A test attaches one
policy to a user, a group and a role, asserts 3, detaches one, and asserts 2 — so a loop
covering only users would fail.
The listed copy is local.
ListManagedPolicieshands back the shared catalog pointers, andwriting a count through one would leak it into
GetPolicyand into every later listing inthe process; the test asserts the catalog entry is unmutated.
PolicyUsageFilter is accepted and not applied
The reference says
PermissionsPolicylists "permissions policies" andPermissionsBoundarylists "the policies used to set permissions boundaries". It does not say which side an
entirely-unused policy falls on — and in a fresh substrate every bundled policy is unused.
Guessing that unattached means "not a permissions policy" would drop all 52 from a filtered
listing, which is exactly the failure this issue reports, reintroduced under a different
parameter. So a valid value is accepted and narrows nothing,
docs/services.mdwill say so(Lane G), and a bad value is still refused because that is a caller error either way.
Pagination
Keyed on the ARN rather than the state key, so the catalog and state arms interleave in one
stable order instead of the bundled policies landing on their own pages. A test walks the
whole listing ten at a time, following the marker to exhaustion, and asserts the pages
reassemble the unpaged result exactly — no repeat, no gap. That matters more than it did
before: the result set is now large enough to page under the default
MaxItemsof 100, so amarker that was merely untested is on every caller's path.
A store failure is not an empty list
Four fault-injection cases assert a broken read surfaces as a server error rather than as an
empty listing — the two are opposite signals, and this issue is itself a report of a listing
that returned nothing when it should have returned something. The one deliberate exception is
a state record that does not decode: it is skipped, because one unreadable key should not
make the 52 catalog policies unlistable, and a test pins that too.
Compatibility
ListPoliciesnow returns the bundled catalog, so a caller counting results sees more.One in-repo test used
ListPoliciesas an ARN lookup for the single policy it created and nowpasses
Scope=Local, which is the correct narrowing for that intent. This goes in therelease's
## Compatibilitysection.Verification
gofmt -l .,go build ./...,go vet ./...,golangci-lint run ./...→ 0 issuesmake test(race) green; coverage 82.6%, withlistPoliciesat 97.6%Scope,PathPrefix,OnlyAttachedandMaxItemsover the queryprotocol, where every value arrives as a string — the IAM MaxItems and MaxSessionDuration are rejected over the wire: a query-protocol integer arrives as a string #642 shape.
Closes #497