Repository navigation
fsx: grant the service-linked-role creation an S3 association needs, and surface its failure - #628
Conversation
…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
Follow-up commit: the grant was missing on both profile pathsWhile 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
And a mistake worth recordingMy first attempt annotated the new statement with a Correction to the PR bodyI wrote that "a launch reusing a pre-#622 role will still fail until it rolls". That's wrong — Also: my usual |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
# Conflicts: # CHANGELOG.md
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 firstCreateDataRepositoryAssociationin an account, and that requires the calling principal to holdiam:CreateServiceLinkedRole. #221 added thefsx:*actions to spored's baseline — necessary but not sufficient. Confirmed:sporedFSxMountgranted exactly threefsx:actions, andiam:CreateServiceLinkedRoleappeared nowhere in spawn's policy building (only as an SDK call inimagebuilder.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:
It lived only in
/var/log/spored.log. spored now tagsspawn:fsx-dra-statusandspawn:fsx-dra-error, mirroringspawn:dns-status/spawn:dns-error— including clearing a stale error tag on a later success, since an instance carrying bothassociatedand a leftover error would contradict itself (the same reasoning astagDNSStatus). Tag values are truncated to EC2's 256-char cap, because a rejectedCreateTagswould lose the whole signal, which is the silence being fixed.Nothing surfaced it.
fsxDRAStatusNoticeinspawn status, wired into the same four call sites asdnsStatusNotice. It names the filesystem, the real error, states that the mount is empty for--fsx-import-pathand that results won't be copied for--fsx-export-path, and says the filesystem is billing regardless withspawn fsx list/spawn fsx delete.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-paththe association is how the data arrives.draImpactnow 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 unconditionediam:CreateServiceLinkedRolewould let a spored instance create a service-linked role for any AWS service, so the test asserts the condition keys oniam:AWSServiceNameand 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 tospawn:fsx-pendingfor 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
TestBuildInlinePolicypinned 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
gofmtclean ·go vet ./...clean ·go build ./...clean ·go test ./...all green ·make check-docsclean ·go mod tidyclean · 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.