Repository navigation
feat(iam): bundle the five service-role managed policies (#484) - #500
Merged
Merged
Conversation
`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 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.
GetPolicyreturnedNoSuchEntityforAmazonSSMManagedInstanceCoreand four siblingservice-role policies, so the sequence every consumer provisioning an SSM-managed instance
profile performs —
CreateRole,AttachRolePolicy,GetPolicy— failed at the last stepon 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-serviceFullAccess/ReadOnlyAccesspairs, which are attachedto users and groups. None was a service-role policy — what an instance profile or
execution role carries, and therefore what IaC actually provisions.
AmazonSSMFullAccesswas present;
AmazonSSMManagedInstanceCore, the policy an SSM-managed instance needs, wasnot.
Five policies added, taking the catalog from 47 to 52:
AmazonSSMManagedInstanceCore/AmazonEC2ContainerRegistryReadOnly/AmazonECSTaskExecutionRolePolicy/service-role/AWSLambdaBasicExecutionRole/service-role/AWSLambdaVPCAccessExecutionRole/service-role/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-datasetcarry the realANPA…policy IDs.They come from
glassechidna/trackiam, which holds per-policy snapshots of realget-policyoutput, and which independently corroborated each path and default version.Default versions follow AWS rather than
mp's blanketv1, so a consumer readingDefaultVersionIdback sees what AWS reports.The catalog can now express a path
mphardcodedPath: "/"and an ARN without a path component, so aservice-role/policycould not be expressed at all. New
mpAtbuilds the ARN and thePathfield from oneargument so they cannot disagree, and
mpis expressed in terms of it.PolicyNamestaysthe bare name — the distinction
ListPolicies --path-prefixreads, and conflating themwould 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 isPath+PolicyName, the invariant that survives paths) and_RequiredFields.What this deliberately does not do
#484 offered an alternative: make
AttachRolePolicyreject an unresolvable ARN so thetwo 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
AmazonEKSWorkerNodePolicywould get a hard failure where AWS succeeds. That trades aconfusing 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
ListPoliciesparsesScopeandPathPrefixand applies neither, and neverlists bundled policies, so
--scope AWSreturns zero of the 52.GetPolicyVersionis unimplemented, so no policy document is observable overthe wire at all. The seeded documents are readable in process; the AWS operation that
returns one is absent.
Verification
gofmt -l .,go build ./...,go vet ./...clean;golangci-lint run ./...→ 0 issuesmake test(race) passes;go test -C test/e2e ./...passesmake docs-reference docs-reference-check docs-versionsclean (no new plugin, so nogenerator diff);
npm --prefix docs run buildsucceedsthe ARN, the path leaking into
PolicyName,Pathreported without its slashes, aroot-path policy reporting an empty
Path,withVersionas a no-op, a policy missingentirely, 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,
Allowflipped toDeny, a document scoped away from*, and a dropped description. Two initial harnessbugs 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.
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