Skip to content

feat(iam): bundle the five service-role managed policies (#484) - #500

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/484-iam-service-role-policies
Aug 2, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/484-iam-service-role-policies

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

GetPolicy returned NoSuchEntity for AmazonSSMManagedInstanceCore and four sibling
service-role policies, so the sequence every consumer provisioning an SSM-managed instance
profile performs — CreateRole, AttachRolePolicy, GetPolicy — failed at the last step
on an ARN the attach had just accepted.

The gap was a population gap

All 47 bundled policies were human-operator policies: AdministratorAccess,
PowerUserAccess, and per-service FullAccess/ReadOnlyAccess pairs, which are attached
to users and groups. None was a service-role policy — what an instance profile or
execution role carries, and therefore what IaC actually provisions. AmazonSSMFullAccess
was present; AmazonSSMManagedInstanceCore, the policy an SSM-managed instance needs, was
not.

Five policies added, taking the catalog from 47 to 52:

Policy Path Default version
AmazonSSMManagedInstanceCore / v2
AmazonEC2ContainerRegistryReadOnly / v3
AmazonECSTaskExecutionRolePolicy /service-role/ v1
AWSLambdaBasicExecutionRole /service-role/ v1
AWSLambdaVPCAccessExecutionRole /service-role/ v3

Provenance

Each document is verbatim from the policy's page in the AWS managed policy
reference
, fetched at
implementation time rather than written from memory — these are documents the IAM evaluator
reads, so they are behavior, not decoration.

Neither the AWS pages, moto, nor iann0036/iam-dataset carry the real ANPA… policy IDs.
They come from glassechidna/trackiam, which holds per-policy snapshots of real
get-policy output, and which independently corroborated each path and default version.
Default versions follow AWS rather than mp's blanket v1, so a consumer reading
DefaultVersionId back sees what AWS reports.

The catalog can now express a path

mp hardcoded Path: "/" and an ARN without a path component, so a service-role/ policy
could not be expressed at all. New mpAt builds the ARN and the Path field from one
argument so they cannot disagree, and mp is expressed in terms of it. PolicyName stays
the bare name — the distinction ListPolicies --path-prefix reads, and conflating them
would make a policy findable by ARN and invisible to a path query.

Three pre-existing tests assumed a root path or a count of 47 and are updated:
TestListManagedPolicies_Count, _ARNFormat (now asserts the ARN suffix is
Path+PolicyName, the invariant that survives paths) and _RequiredFields.

What this deliberately does not do

#484 offered an alternative: make AttachRolePolicy reject an unresolvable ARN so the
two operations agree. Not taken. Substrate bundles 52 of roughly 1,200 AWS managed
policies, so refusing would fail every attach of the other ~1,150 — a consumer attaching
AmazonEKSWorkerNodePolicy would get a hard failure where AWS succeeds. That trades a
confusing success for a wrong failure, and the wrong failure is worse: it breaks working
consumer code rather than merely failing to catch a typo. A test pins the accepted
behaviour so the decision cannot be changed by accident, and #499 records it.

Follow-ups filed while verifying this

Verification

  • gofmt -l ., go build ./..., go vet ./... clean; golangci-lint run ./... → 0 issues
  • make test (race) passes; go test -C test/e2e ./... passes
  • make docs-reference docs-reference-check docs-versions clean (no new plugin, so no
    generator diff); npm --prefix docs run build succeeds
  • Mutation testing: 17 mutations, 17 caught, 0 survived. Covers the path dropped from
    the ARN, the path leaking into PolicyName, Path reported without its slashes, a
    root-path policy reporting an empty Path, withVersion as a no-op, a policy missing
    entirely, a service-role policy bundled at the root or under the wrong path, a
    synthesised policy ID, a dropped statement, a dropped or added action, Allow flipped to
    Deny, a document scoped away from *, and a dropped description. Two initial harness
    bugs were found and fixed rather than reported as results: one anchor missed gofmt's
    struct alignment, and one matched an identical action string in an existing policy
    earlier in the slice, mutating a policy this PR did not add.
  • End to end through the AWS CLI: all five attach and then resolve, reporting the paths,
    policy IDs and default versions in the table above; an unbundled managed ARN attaches and
    then 404s, which is the IAM: AttachRolePolicy/AttachUserPolicy accept a PolicyArn that GetPolicy cannot resolve #499 behaviour this PR pins.

Closes #484

`GetPolicy` returned `NoSuchEntity` for `AmazonSSMManagedInstanceCore` and four
sibling service-role policies, so the sequence every consumer provisioning an
SSM-managed instance profile performs — `CreateRole`, `AttachRolePolicy`,
`GetPolicy` — failed at the last step on an ARN the attach had just accepted.

The gap was a population gap. All 47 bundled policies were human-operator
policies: `AdministratorAccess`, `PowerUserAccess`, and per-service
`FullAccess`/`ReadOnlyAccess` pairs, which are attached to users and groups.
None was a service-role policy — what an instance profile or execution role
carries, and therefore what IaC provisions. `AmazonSSMFullAccess` was present;
`AmazonSSMManagedInstanceCore`, the policy an SSM-managed instance needs, was
not.

Documents are verbatim from each policy's page in the AWS managed policy
reference, and policy IDs are real, from a recorded `get-policy` snapshot rather
than synthesised. Default versions follow AWS (v2 for
`AmazonSSMManagedInstanceCore`, v3 for `AmazonEC2ContainerRegistryReadOnly` and
`AWSLambdaVPCAccessExecutionRole`) instead of a blanket v1. The documents are
read by the IAM policy evaluator, so they are behavior and not decoration.

The catalog can now express a path, which three of the five need. `mpAt` builds
the ARN and the `Path` field together so they cannot disagree, and `mp` is
expressed in terms of it. `PolicyName` stays the bare name — the distinction
`ListPolicies --path-prefix` reads.

`AttachRolePolicy` still accepts an ARN no `GetPolicy` can resolve, which #484
also offered to fix. Not taken: substrate bundles 52 of ~1,200 AWS managed
policies, so refusing an unresolvable ARN would fail every attach of the other
~1,150, breaking working consumer code where the current behavior merely fails
to catch a typo. Tracked in #499. Two further gaps found while verifying this
one are filed: #497 (`ListPolicies` applies neither `Scope` nor `PathPrefix`)
and #498 (`GetPolicyVersion` unimplemented, so no document is observable over
the wire).

Closes #484
@codecov

codecov Bot commented Aug 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 262b911 into main Aug 2, 2026
16 checks passed
@scttfrdmn
scttfrdmn deleted the feat/484-iam-service-role-policies branch August 2, 2026 21:58
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: no service-role managed policies are seeded, so AttachRolePolicy accepts an ARN that GetPolicy then reports NoSuchEntity

1 participant