Repository navigation
feat(iam): a managed policy's document is readable over the wire (#498) - #645
Merged
Merged
Conversation
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 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.
GetPolicyreturns metadata only — which matches AWS, where the document lives behindGetPolicyVersion— and substrate routed no version operation at all. So the 52 bundleddocuments, several transcribed from their AWS reference pages, were readable by a Go caller
through
GetManagedPolicyand by no consumer over HTTP: a test could attachAmazonS3ReadOnlyAccessand never see what it granted. This is also what makes a simulateddecision checkable — a caller who gets an
implicitDenycan now read the policy that failedto 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.QueryEscapeencodes a space as+. A decoder following RFC 3986 reads that back as aliteral plus, silently corrupting any document containing a space — which is most of them.
url.PathEscapeleaves:and several sub-delimiters bare, so an ARN in aResourcecomesback differently from what AWS sends.
iamEscapeRFC3986escapes 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%20present,~untouched,:encoded, and that the value round-trips throughurl.PathUnescapeinto the document the catalog holds.One version per policy, said rather than faked
IAMPolicyholds a singleDocumentand aDefaultVersionID; noCreatePolicyVersionorSetDefaultPolicyVersionexists. So aVersionIdthat is not the policy's default answersNoSuchEntityrather than being served the default's document under the requested name — aconsumer pinning a version would otherwise be told a document is
v1that AWS reports assomething else. The catalog makes this immediately reachable rather than hypothetical, because
AWS has edited these policies since publication:
AmazonSSMManagedInstanceCorereportsv2and
AWSLambdaVPCAccessExecutionRolereportsv3.ListPolicyVersionstherefore returnsexactly one member.
ListPolicyVersionsomitsDocument. The model documents that member as returned byGetPolicyVersionandGetAccountAuthorizationDetailsand not byListPolicyVersionsorCreatePolicyVersion— sending it would hand a caller a member AWS does not, which is thekind 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
VersionIdisInvalidInputand is refused before the policy is resolved:the parameter is wrong whether or not the policy exists, and answering
NoSuchEntitywouldsend the caller looking for a policy that is right there. The pattern is anchored, because an
unanchored match would accept
xxv1yyand then misreport it as a missing version.Verification
gofmt -l .,go build ./...,go vet ./...,golangci-lint run ./...→ 0 issuesmake test(race) green; coverage 82.6%operation cannot pass with a green unit suite — which is what Service Quotas: the increase-history operation is unreachable from any SDK #636 was. It also sends
MaxItemsas a string, the IAM MaxItems and MaxSessionDuration are rejected over the wire: a query-protocol integer arrives as a string #642 shape.Closes #498