Repository navigation
fix(authz): name a REST request by its operation, not its HTTP method (#572) - #573
Merged
Merged
Conversation
…#572) A REST-JSON or REST-XML service carries its operation in the shape of its URL and nowhere else, so extractOperation fell through to its last-resort fallback and the request entered the pipeline named "POST". Authorization, fault injection, cost and consistency all read req.Operation before any plugin runs, while each plugin resolved the real name only at the top of its own HandleRequest — one step too late. Measured on the parent commit, 17 of 18 REST services were affected; S3 was the exception because #480 had wired its resolver in for exactly this reason. This was inert until #411 made the evaluator reachable. A user holding lambda:InvokeFunction was then refused an invoke, because the action evaluated was lambda:POST — precisely the scoped policy the release exists to let a consumer test, getting a false AccessDeniedException. Resolve the name once, before the pipeline reads it, generalizing #480 rather than repeating it 17 times. Each service's resolver already existed and is wrapped rather than reimplemented, so the name that is authorized, metered and recorded cannot drift from the name its plugin routes on. AWSRequest gains HTTPMethod. The verb and the operation had been sharing one field, and resolving the operation destroyed the verb every REST resolver keys on — POST and DELETE on the same path are different operations. The 17 plugin call sites now read requestMethod(req), which prefers HTTPMethod and falls back to a verb still sitting in Operation, as an in-process caller leaves it. The IAM action is not always the operation name, and treating it as such denies a caller whose policy is right, so the mapping is explicit and sourced per operation against the AWS documentation: - lambda:Invoke requires lambda:InvokeFunction; - S3's listings authorize against the bucket — ListObjects/ListObjectsV2 and HeadBucket require s3:ListBucket, ListBuckets requires s3:ListAllMyBuckets, and the versioned and multipart listings have their own bucket-scoped actions; DeleteObjects requires s3:DeleteObject; - API Gateway v1's IAM actions genuinely are HTTP verbs (apigateway:POST, with no apigateway:CreateRestApi), so for that service the verb remains the action — while apigatewayv2 is a separate prefix that does use operation names. Conflating them would have broken v1 in the act of fixing the others. Two consequences beyond authorization, both pre-existing and now fixed: a fault rule can name a REST operation, closing #480's gap for the 17 services its S3-only fix never reached (a rule naming "POST" used to take out every call to the service at once); and a recorded event carries its operation, so an event log is greppable by operation — which is why cfn_nested_test.go's assertion moved from "POST" to "CreateCluster". CloudFormation's resource calls are built in-process and never parsed off the wire, so dispatch resolves them too: a stack's bucket is recorded and authorized as CreateBucket, not PUT. Closes #572
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.
A REST-JSON or REST-XML service carries its operation in the shape of its URL and
nowhere else, so
extractOperationfell through to its last-resort HTTP-methodfallback and the request entered the pipeline named
POST. Authorization, faultinjection, cost and consistency all read
req.Operationbefore any pluginruns, while each plugin resolved the real name only at the top of its own
HandleRequest— one step too late.Measured on the parent commit (
87a966f), 17 of 18 REST services wereaffected. S3 was the only exception, because #480 had wired its resolver in for
exactly this reason.
Why this blocks the release
The defect was inert while the evaluator was unreachable, and stopped being inert
with #411 (merged, unreleased). A user holding
lambda:InvokeFunctionwas refusedan invoke, because the action evaluated was
lambda:POST. A wildcard policy masksit, so it is precisely the scoped policy #411 exists to let a consumer test that
gets a false
AccessDeniedException— the inverse of the release's headline claim.Transcript from a throwaway probe at
87a966f:The fix
Resolve the operation name once, before the pipeline reads it — generalizing
#480 instead of repeating it 17 times. Every entry in the new
operationResolverstable wraps a resolver the service's plugin already owns andalready calls, rather than reimplementing it, so there is one definition of "what
operation is this" and the name the pipeline authorizes, meters and records cannot
drift from the name the plugin routes on.
AWSRequestgainsHTTPMethod. This is the root modeling error: the verb and theoperation had been sharing one field, so resolving the operation destroyed the
verb that all 17 REST resolvers key on —
POSTandDELETEon the same path aredifferent operations. The alternative was 17 defensive guards; splitting the field
is the fix that leaves each resolver's contract intact, and the whole existing
suite went green with no test edits beyond the one intentional behaviour change
noted below.
CloudFormation's resource calls are built in-process and never pass through
ParseAWSRequest, sodispatchresolves too — otherwise a stack's bucket isauthorized as
s3:PUT, which matches no policy a consumer would write.The IAM action is not always the operation name
Treating it as such denies a caller whose policy is right, so the mapping is
explicit and each entry was checked against the AWS documentation rather than
assumed:
lambda:Invokelambda:InvokeFunctions3:ListObjects/ListObjectsV2/HeadBuckets3:ListBuckets3:ListBucketss3:ListAllMyBucketss3:ListObjectVersionss3:ListBucketVersionss3:ListMultipartUploadss3:ListBucketMultipartUploadss3:DeleteObjectss3:DeleteObjectAPI Gateway v1 is the sharp case. Its Service Authorization Reference defines
apigateway:GET/POST/PUT/PATCH/DELETE/HEAD/OPTIONSand noapigateway:CreateRestApi— its IAM actions genuinely are HTTP verbs. So forthat service the verb remains the action, while
apigatewayv2is a separateprefix that does use operation names. Blind resolution would have broken v1 in the
act of fixing the other 16; I had this wrong in a first draft of the tests and the
docs caught it.
Two pre-existing consequences, also fixed
the 17 services its S3-only fix never reached. Before this, a rule naming
POSTtook out every call to the service at once.
greppable by operation. This is the one intentional behaviour change to an
existing test:
dispatchedBody(t, store, "msk", "POST")became"CreateCluster", and the helper's doc comment says why.Compatibility
The action strings a policy must name have changed. A REST call is now
authorized as its real operation rather than as its HTTP verb, and the renames in
the table above apply. A caller whose policy named
lambda:POST(which no AWSpolicy would) is now denied; a caller whose policy named
lambda:InvokeFunction(which every real policy does) is now correctly allowed. A recorded event's
operation for a REST service changes accordingly. Anything with a wildcard policy,
a nil principal, or a credential that resolves to no IAM entity is unaffected.
Verification
87a966fand pass here.8 CAUGHT, 0 survivors, 0 broken. Two rounds were needed. The first found a
real gap:
HTTPMethod's contract held only incidentally, becauseresolveOperationNamebackfills the field, so a REST service added laterwithout a table entry would have reached its plugin with no verb at all. Now
asserted where nothing backfills. One mutant (
resolveOperationName'sresolved-name guard) was provably equivalent — every resolver echoes back the
verb it was handed, never a different one — so rather than leave an unmeasurable
branch, the now-unused
boolreturn was dropped and the""-or-verb contractdocumented.
gofmt -l .,go build ./...,go vet ./...,golangci-lint run ./...→ 0issues,
make test(race),make docs-reference docs-reference-check docs-versions(65 plugins, no change),go vet -C test/e2e ./...,go test -C test/e2e ./...— all green.Provenance
The 17-service list and the false-denial transcript above were measured with
throwaway in-package probes against
87a966f, not read off a reference. Theaction-name mappings and the API Gateway v1 verb-action behaviour are from the AWS
API and Service Authorization references.
Closes #572