Skip to content

fix(iam): ListPolicies applies its filters and sees the catalog (#497) - #646

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/iam-list-policies-filters
Aug 15, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/iam-list-policies-filters

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

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 and --path-prefix /service-role/ returned the same thing.

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 — the whole
point of list-policies --scope AWS --path-prefix /service-role/ then picking a name — had
no 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 failure
mode is one entry whose ARN was built differently.

The filters

  • Scope selects the source: AWS the catalog, Local what CreatePolicy wrote, All
    or absent both. A value outside All/AWS/Local is a ValidationError naming the
    permitted set, and case matters — aws is not AWS.
  • PathPrefix filters on Path. This is what mpAt kept the path in its own field for
    rather than folding 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,
    rather than passing against substrate and failing against AWS.
  • OnlyAttached narrows to policies with a non-zero count. See below for why that
    required a change of source.
  • PolicyUsageFilter is validated and deliberately narrows nothing (below).

AttachmentCount had to become derived

The catalog carries AttachmentCount: 0 for every bundled policy, and no attach operation
increments a count anywhere — AttachUserPolicy and its siblings record the ARN on the
entity's list and never touch the policy. So a listing reading the stored field would report
0 forever, and OnlyAttached=true could never return a managed policy, which is the issue's
fourth acceptance criterion.

Counting the user_policies:/group_policies:/role_policies: lists instead means an
attach 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. ListManagedPolicies hands back the shared catalog pointers, and
writing a count through one would leak it into GetPolicy and into every later listing in
the process; the test asserts the catalog entry is unmutated.

PolicyUsageFilter is accepted and not applied

The reference says PermissionsPolicy lists "permissions policies" and PermissionsBoundary
lists "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.md will 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 MaxItems of 100, so a
marker 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

ListPolicies now returns the bundled catalog, so a caller counting results sees more.
One in-repo test used ListPolicies as an ARN lookup for the single policy it created and now
passes Scope=Local, which is the correct narrowing for that intent. This goes in the
release's ## Compatibility section.

Verification

Closes #497

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

codecov Bot commented Aug 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.91919% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/iam_list_policies.go 91.91% 4 Missing and 4 partials ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit c62b0d6 into main Aug 15, 2026
13 checks passed
@scttfrdmn
scttfrdmn deleted the fix/iam-list-policies-filters branch August 15, 2026 00:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IAM: ListPolicies ignores Scope and PathPrefix and never lists bundled managed policies

1 participant