Repository navigation
fix(iam): don't emit an empty-Resource write statement for read-only S3 - #677
Merged
Merged
Conversation
taskStagingPolicy appended s3:PutObject unconditionally, so `--s3-read bucket` with no --s3-write shipped "Resource":[] and IAM rejected the whole document — failing the launch before it reached EC2. Same shape broke --s3-read-write on its own (the Snakemake S3-storage case). An empty "Statement" is equally malformed, so with nothing to grant the function now returns "" and the policy is not attached. Fixes #669
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.
Fixes #669. Diagnosis confirmed exactly as filed, including the line number.
Reproduced first
taskStagingPolicy(cmd/task.go) appended itss3:PutObjectstatement unconditionally. On the launch pathoutputBucketsis empty andresultsBucketis"", anddedupeBucketsdrops empty strings, so--s3-read my-inputsalone produced:{"Effect":"Allow","Action":["s3:PutObject"],"Resource":[]}IAM rejects the whole document for an empty
Resource, not just that statement, so the instance profile could not be created and the launch died withMalformedPolicyDocumentbefore reaching EC2.A read-only grant now contains no write statement at all — rather than an unscoped one, which would have been worse than the bug.
Two things beyond the report
--s3-read-writealone was broken the same way. With onlyResources.S3ReadWriteset,writeBis empty too, so the Snakemake S3-storage plugin's shape hit the identical failure. Covered by a test.Guarding the write statement alone would have swapped one invalid document for another. With no buckets at all,
stmtsbecomes empty and the result is{"Version":"2012-10-17","Statement":[]}—MalformedPolicyDocumentjust as surely. The function now returns""when it has nothing to grant, and the policy is simply not attached: bothPutRolePolicycall sites inpkg/aws/iam.go(:687,:744) were already guarded onInlinePolicyJSON != "", so no caller changes were needed.Why this survived so long
There was already a test calling exactly this case —
TestS3FlagsAreAdditiveWithIAMPolicydoestaskStagingPolicy([]string{"b"}, nil, "", nil), which is #669 verbatim. It asserted only that the document starts with{"Version":"2012-10-17", and elsewhere the suite assertedjson.Valid. Both pass for a document IAM refuses:"Resource":[]is perfectly good JSON.So the new
assertIAMAcceptablehelper checks the two shapes IAM rejects thatjson.Validaccepts — an emptyResource, and an emptyStatement— and I strengthened that pre-existing test in place to use it, rather than leaving a test that calls the broken case and declares it fine. That is the same class as the"_comment"incident earlier in this cycle: a policy document no compiler or test could reach.Verification
Every new assertion confirmed to fail against the old code first, reporting the real symptom — the
Resource":[]statement printed in full, not a compile error. All pre-existing S3/IAM/task tests still pass unchanged.Gates clean locally before pushing:
gofmt -lempty,go vet ./...,go test -short ./...(0 failures),make check-docs, changelog gate,semgrep scan --config=auto --error .→ 0 findings.Not verified against live IAM. The assertions encode IAM's documented rejection rules rather than observing them, so if you want certainty that the read-only document is now accepted, a
aws iam create-role+put-role-policyagainst the rendered JSON is the check — worth doing before the release tag since the failure mode is a hard launch failure.