Skip to content

fsx: grant the service-linked-role creation an S3 association needs, and surface its failure - #628

Merged
scttfrdmn merged 3 commits into
mainfrom
fix/622-fsx-dra-slr-and-visibility
Oct 2, 2026
Merged

scttfrdmn merged 3 commits into
mainfrom
fix/622-fsx-dra-slr-and-visibility

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Refs #622. The issue's diagnosis is exactly right and its suggested fix is what this does; I verified each claim in code before implementing.

The bug

FSx creates a per-filesystem service-linked role (AWSServiceRoleForFSxS3Access_<fsid>) on the first CreateDataRepositoryAssociation in an account, and that requires the calling principal to hold iam:CreateServiceLinkedRole. #221 added the fsx:* actions to spored's baseline — necessary but not sufficient. Confirmed: sporedFSxMount granted exactly three fsx: actions, and iam:CreateServiceLinkedRole appeared nowhere in spawn's policy building (only as an SDK call in imagebuilder.go).

Because spored mounts anyway by design, the visible outcome was a mounted but empty 1200 GiB filesystem — the FSx Lustre minimum, ~$174/month — while the CLI printed 🎉 Instance Ready! and the workload read an empty directory.

It looked account-specific only because the role persists once created: anyone who had ever made an association by hand never hit it.

The grant is conditioned on iam:AWSServiceName = s3.data-source.lustre.fsx.amazonaws.com, so this is not a general service-linked-role creation permission.

The silence, which cost as much as the bug

Three changes, because the failure was invisible in three different ways:

  1. It lived only in /var/log/spored.log. spored now tags spawn:fsx-dra-status and spawn:fsx-dra-error, mirroring spawn:dns-status/spawn:dns-error — including clearing a stale error tag on a later success, since an instance carrying both associated and a leftover error would contradict itself (the same reasoning as tagDNSStatus). Tag values are truncated to EC2's 256-char cap, because a rejected CreateTags would lose the whole signal, which is the silence being fixed.

  2. Nothing surfaced it. fsxDRAStatusNotice in spawn status, wired into the same four call sites as dnsStatusNotice. It names the filesystem, the real error, states that the mount is empty for --fsx-import-path and that results won't be copied for --fsx-export-path, and says the filesystem is billing regardless with spawn fsx list / spawn fsx delete.

  3. The wording understated it. "results may not auto-export to S3" is fair for an export failure and badly misleading for an import one — with --fsx-import-path the association is how the data arrives. draImpact now states the consequence for the paths actually given.

The synchronous launch path (pkg/aws/fsx.go:207) already returns this error and fails loudly; only the spored-side async path swallowed it. Left unchanged, noted here so the asymmetry is on record.

Tests

  • pkg/aws/iam_fsx_slr_test.go — the grant is present, and is conditioned: an unconditioned iam:CreateServiceLinkedRole would let a spored instance create a service-linked role for any AWS service, so the test asserts the condition keys on iam:AWSServiceName and names the FSx-S3 principal. Both verified to fail against the pre-fix policy (baseline policy lacks iam:CreateServiceLinkedRole, no statement grants iam:CreateServiceLinkedRole).
  • cmd/fsx_dra_notice_test.go — the notice names the filesystem, the error, EMPTY, the export consequence, that it's billing, and the delete command; is silent on success/absent tags/a stale error beside a success (a notice that fires when things are fine trains users to ignore it); still reports when the detail tag is missing; falls back to spawn:fsx-pending for the id.
  • pkg/agent/fsx_dra_impact_test.go — import-only says EMPTY and doesn't mention export; export-only doesn't claim emptiness; both reports both. Plus tag-value truncation marking what it cut.

One test legitimately updated, not weakened

TestBuildInlinePolicy pinned the spored statement count at 5; there are now 6. I raised the count and recorded why in the comment, rather than loosening the assertion — the pin is deliberate and still doing its job.

Gates

gofmt clean · go vet ./... clean · go build ./... clean · go test ./... all green · make check-docs clean · go mod tidy clean · CHANGELOG updated in this PR (it was missed on #627, which is why v0.112.1's entries had to be written at release time).

staticcheck: zero added. Worth noting my usual raw-line diff reported two new findings and was wrong — inserting code shifted existing findings' line numbers, so they appeared as both added and removed. Comparing by message text shows no difference; I'll use that comparison from now on.

Suggested bump: PATCH — an IAM grant fix plus additive reporting; no flag or schema change. Existing instance roles are cached by policy hash, so a launch reusing a pre-#622 role will still fail until it rolls; worth mentioning in the release notes.

…eds, and surface its failure

--fsx-import-path silently did nothing on a fresh filesystem. FSx creates a
per-filesystem service-linked role on the FIRST CreateDataRepositoryAssociation
in an account, which requires the CALLING principal to hold
iam:CreateServiceLinkedRole. #221 added the fsx:* actions to spored's baseline but
not that, so the association failed with 'Amazon FSx is unable to create
Service-Linked-Role to access the S3 bucket' every time.

spored mounts anyway by design, so the visible result was a mounted but EMPTY
1200 GiB filesystem — the FSx Lustre minimum, ~$174/month — while the CLI printed
'Instance Ready!' and the workload read an empty directory. It looked
account-specific only because the role persists once created, so anyone who had
ever made an association by hand never saw it.

The grant is scoped by condition to s3.data-source.lustre.fsx.amazonaws.com, so
this is not a general service-linked-role creation permission.

Second half, the silence. The failure lived only in /var/log/spored.log on the
box: spored now tags spawn:fsx-dra-status / spawn:fsx-dra-error (mirroring
spawn:dns-status / spawn:dns-error, including clearing a stale error on a later
success) and 'spawn status' reports it — naming the filesystem, the underlying
error, and that it is billing regardless, with the list/delete commands.

And the wording. 'results may not auto-export to S3' is fair for an export
failure and badly misleading for an import one: with --fsx-import-path the
association is how the data ARRIVES, so the real outcome is an empty filesystem.
draImpact now states the consequence for the paths actually given.

The synchronous launch path (pkg/aws/fsx.go) already returned this error, so only
the spored-side async path was silent; it is unchanged.

Refs #622
spawn resolves an instance profile through two divergent paths (the #550
contrast). The first commit fixed the dynamic baseline used by
CreateOrGetInstanceProfile; sporedDCVRolePolicy — written by SetupSporedIAMRole,
which is what a launch with NO --iam-* flags gets — already carried the #221
fsx:CreateDataRepositoryAssociation grant but not iam:CreateServiceLinkedRole, so
it had the identical silent-empty-filesystem bug on the simplest invocation there
is.

Fixing only the path #622's reporter happened to use (they passed --iam-policy)
would have left the more common one broken.

A test now asserts BOTH policies carry the grant, keyed to them both granting
fsx:CreateDataRepositoryAssociation, so the two cannot diverge on it again.

Also adds a well-formedness test for sporedDCVRolePolicy: I first annotated the
new statement with a '_comment' key, which IAM rejects as
MalformedPolicyDocument — that would have broken every launch on this path rather
than degrading it. The explanation lives in the constant's doc comment instead,
and the test fails on any non-IAM statement element.

Refs #622
@scttfrdmn

Copy link
Copy Markdown
Contributor Author

Follow-up commit: the grant was missing on both profile paths

While verifying a claim I'd made in the PR body about cached roles, I found that fixing one path wasn't enough — and that the path I'd missed is the more common one.

spawn resolves an instance profile two ways (the #550 contrast documented in CreateOrGetInstanceProfile):

path taken when policy had the SLR grant?
CreateOrGetInstanceProfile any --iam-role/--iam-policy/--iam-policy-file dynamic sporedBaselinePolicyDoc() fixed in the first commit
SetupSporedIAMRole no --iam-* flags at all static sporedDCVRolePolicy no — same bug

sporedDCVRolePolicy already carried the #221 fsx:CreateDataRepositoryAssociation grant but not iam:CreateServiceLinkedRole, so it had the identical silent-empty-filesystem failure. #622's reporter passed --iam-policy s3:ReadOnly, which is why they landed on the path I'd already fixed — but spawn launch --fsx-create --fsx-import-path … with no IAM flags is the simplest invocation there is, and it was still broken.

TestBothSporedPolicyPathsGrantTheFSxServiceLinkedRole now asserts both policies carry the grant, keyed to them both granting fsx:CreateDataRepositoryAssociation, so they cannot diverge on it again.

And a mistake worth recording

My first attempt annotated the new statement with a "_comment" key. IAM rejects unknown statement elements with MalformedPolicyDocument, so that would have broken every launch on this path rather than degrading it — strictly worse than the bug being fixed. The explanation now lives in the constant's Go doc comment, and TestSporedDCVPolicyIsWellFormed fails on any non-IAM statement element. Verified by re-adding _comment and watching it fail.

Correction to the PR body

I wrote that "a launch reusing a pre-#622 role will still fail until it rolls". That's wrong — ensureSporedBaselinePolicy writes the baseline via PutRolePolicy on every launch through CreateOrGetInstanceProfile, and SetupSporedIAMRole likewise rewrites its policy each time. So existing cached roles self-heal on the next launch; no role churn or manual cleanup is needed. The release note should say that rather than warning about stale roles.

Also: my usual staticcheck line-diff reported two added findings and was wrong — inserting code shifts existing findings' line numbers so they show as both added and removed. Comparing by message text shows none added. I've switched to the message comparison.

@codecov

codecov Bot commented Oct 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 55.40541% with 33 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/agent/fsx_mount.go 29.26% 28 Missing and 1 partial ⚠️
cmd/status.go 82.60% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit c859ed7 into main Oct 2, 2026
7 checks passed
@scttfrdmn
scttfrdmn deleted the fix/622-fsx-dra-slr-and-visibility branch October 2, 2026 00:06
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.

1 participant