Skip to content

feat(iam): a managed policy's document is readable over the wire (#498) - #645

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/iam-policy-versions
Aug 15, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/iam-policy-versions

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

GetPolicy returns metadata only — which matches AWS, where the document lives behind
GetPolicyVersion — and substrate routed no version operation at all. So the 52 bundled
documents, several transcribed from their AWS reference pages, were readable by a Go caller
through GetManagedPolicy and by no consumer over HTTP: a test could attach
AmazonS3ReadOnlyAccess and never see what it granted. This is also what makes a simulated
decision checkable — a caller who gets an implicitDeny can now read the policy that failed
to grant it.

RFC 3986, not either stdlib escaper

The reference specifies the document is "URL-encoded compliant with RFC 3986", and neither
stdlib escaper is that:

  • url.QueryEscape encodes a space as +. A decoder following RFC 3986 reads that back as a
    literal plus, silently corrupting any document containing a space — which is most of them.
  • url.PathEscape leaves : and several sub-delimiters bare, so an ARN in a Resource comes
    back differently from what AWS sends.

iamEscapeRFC3986 escapes byte-at-a-time to the unreserved set (ALPHA / DIGIT / - . _ ~)
per §2.5. Most SDKs decode this automatically, so getting it wrong breaks the raw HTTP client
and nobody else — exactly the kind of gap that only surfaces in production. The test asserts
no +, a %20 present, ~ untouched, : encoded, and that the value round-trips through
url.PathUnescape into the document the catalog holds.

One version per policy, said rather than faked

IAMPolicy holds a single Document and a DefaultVersionID; no CreatePolicyVersion or
SetDefaultPolicyVersion exists. So a VersionId that is not the policy's default answers
NoSuchEntity rather than being served the default's document under the requested name — a
consumer pinning a version would otherwise be told a document is v1 that AWS reports as
something else. The catalog makes this immediately reachable rather than hypothetical, because
AWS has edited these policies since publication: AmazonSSMManagedInstanceCore reports v2
and AWSLambdaVPCAccessExecutionRole reports v3. ListPolicyVersions therefore returns
exactly one member.

ListPolicyVersions omits Document. The model documents that member as returned by
GetPolicyVersion and GetAccountAuthorizationDetails and not by ListPolicyVersions or
CreatePolicyVersion — sending it would hand a caller a member AWS does not, which is the
kind of difference that makes a consumer work against substrate and fail against AWS. This is
a correction to the plan, which did not state it.

A malformed VersionId is InvalidInput and is refused before the policy is resolved:
the parameter is wrong whether or not the policy exists, and answering NoSuchEntity would
send the caller looking for a policy that is right there. The pattern is anchored, because an
unanchored match would accept xxv1yy and then misreport it as a missing version.

Verification

Closes #498

GetPolicy returns metadata only, matching AWS, where the document lives
behind GetPolicyVersion — and substrate routed no version operation at
all. So the 52 bundled documents were readable by a Go caller through
GetManagedPolicy and by no consumer over HTTP: a test could attach
AmazonS3ReadOnlyAccess and never see what it granted.

The document is percent-encoded to RFC 3986, which neither stdlib
escaper produces. url.QueryEscape emits "+" for a space, which a
strict decoder reads back as a literal plus; url.PathEscape leaves ":"
bare. Substrate escapes byte-at-a-time to the unreserved set per §2.5,
and a test asserts the value round-trips through a strict decoder.

Substrate models one version per policy, so a non-default VersionId is
NoSuchEntity rather than the default's document under the wrong name.
The catalog makes that reachable immediately: AmazonSSMManagedInstanceCore
reports v2 and AWSLambdaVPCAccessExecutionRole v3. ListPolicyVersions
returns exactly one member and omits Document, which the model
documents as returned by GetPolicyVersion and
GetAccountAuthorizationDetails and not by the list call.

A malformed VersionId is InvalidInput and is refused before the policy
is resolved: the parameter is wrong whether or not the policy exists,
and NoSuchEntity would send the caller looking for a policy that is
right there.

Closes #498
@codecov

codecov Bot commented Aug 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 79.66102% with 24 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/iam_policy_versions.go 78.94% 12 Missing and 12 partials ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 4ef5dd4 into main Aug 15, 2026
13 checks passed
@scttfrdmn
scttfrdmn deleted the feat/iam-policy-versions branch August 15, 2026 00:36
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: GetPolicyVersion is unimplemented, so no policy document is observable over the wire

1 participant