Skip to content

fix(sweep): honour --s3-read/--s3-write, via one IAM predicate shared with the single path - #695

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/539-sweep-s3-iam
Oct 4, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/539-sweep-s3-iam

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #539. Your trace was exact — and the fix for it has been in the tree for a while, which is how I found the part that is still broken.

What I found

applyCLIIAMToSweep exists and its doc comment cites #539, so --iam-role, --iam-policy, --iam-policy-file and --iam-role-tags do reach sweep rows now, folded into paramFormat.Defaults["iam_role"] exactly as you'd expect.

But its trigger condition was:

if iamRole == "" && len(iamPolicy) == 0 && len(iamManagedPolicies) == 0 && iamPolicyFile == "" {
    return nil
}

and the single-instance condition was:

if iamRole != "" || len(iamPolicy) > 0 || len(iamManagedPolicies) > 0 || iamPolicyFile != "" ||
   len(s3ReadBuckets) > 0 || len(s3WriteBuckets) > 0 {

--s3-read and --s3-write appear in one and not the other. #614 added them to the single-instance path after #539's fix landed, so on a sweep they still do exactly what you reported: accepted, never read, never warned, falls back to spored-instance-role, 403 on the first aws s3 call after paying for the boot. grep s3ReadBuckets cmd/launch_sweep.go returned nothing at all.

So this is your bug, re-created in the same function, for the two newest flags — because the condition was duplicated rather than shared. That is the thing I fixed, not just the two flags.

The fix

One predicate, cliIAMFlagsRequireCustomProfile(), called by both paths. A flag listed there is honoured everywhere or nowhere, and a new IAM-ish flag has exactly one place to be added.

The sweep path also now builds the scoped bucket policy through the same taskStagingPolicy the single-instance and task paths use, with the same validateS3BucketFlags pre-check. Deciding "a custom profile is needed" is not sufficient on its own — without the inline policy the role still has no grant on the caller's buckets and every row 403s anyway.

Your observation that the param-file iam_role: key works and is the usable workaround stays true, and a row's own iam_role: still wins over the CLI flag.

On the gate, and a mistake worth recording

The class gate asserts neither path re-spells the condition inline. My first version searched each file for the bare string cliIAMFlagsRequireCustomProfile() — and passed with the drifted condition deliberately restored, because the function is defined in launch_sweep.go, so that file matched its own declaration. It now matches a call site (if [!]cliIAMFlagsRequireCustomProfile()), and fails correctly when I revert the sweep condition.

That is the fourth test I have written today that could not fail, all with one root cause: the assertion was satisfied for a reason other than the one intended. The others were #684's region-substitution test (which set the field no caller set), a Contains(usage, "or") check that matched the "or" inside "spore", and a stream-routing test whose annotations were all empty strings. I am now reverting the fix and watching the test fail before I believe any of them.

Gates

gofmt -l empty, go vet ./..., go test -short ./..., make check-docs, changelog gate, semgrep → 0 findings. Seven-case table test over every IAM flag, plus the two structural gates, each confirmed to fail when the drift is reintroduced.

Not hardware-verified. The predicate and policy construction are pure, but "a sweep row can now read the caller's bucket" is an IAM authorization claim, and make smoke-needed flags pkg/aws/iam.go-adjacent work as hardware-sensitive — a one-row sweep with --s3-read against a real bucket would settle it, and is worth doing before the next tag.

@codecov

codecov Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 53.84615% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/launch_sweep.go 58.33% 5 Missing ⚠️
cmd/launch_single.go 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

… with the single path

#539 was "the sweep path accepts the IAM flags, never reads them, never
warns" — every row fell back to spored-instance-role, whose fixed policy
grants S3 only on spawn's own buckets, so a workload reading the
caller's bucket booted, billed and died on 403.

That was fixed for the flags which existed then. #614 later added
--s3-read/--s3-write to the single-instance condition and not to the
sweep one, so those two kept the original behaviour — the same bug,
re-created in the same place, because the condition was duplicated
rather than shared.

Both paths now call cliIAMFlagsRequireCustomProfile(), and the sweep
path builds the same scoped policy via taskStagingPolicy. A gate asserts
neither path re-spells the condition inline — and it matches a CALL
SITE, because matching the bare name passed vacuously against the file
that holds the definition.

Fixes #539
@scttfrdmn
scttfrdmn force-pushed the fix/539-sweep-s3-iam branch from 5330d29 to e87c2d5 Compare October 4, 2026 23:34
@scttfrdmn
scttfrdmn merged commit eaf81c8 into main Oct 4, 2026
7 checks passed
@scttfrdmn
scttfrdmn deleted the fix/539-sweep-s3-iam branch October 4, 2026 23:44
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-role / --iam-policy / --iam-policy-file are silently ignored on the sweep path (0.100.4)

1 participant