Skip to content

feat(setup-account): --remove/--offboard, and provision the user lifecycle-lease policy (#1656, #1666) - #1669

Merged
scttfrdmn merged 3 commits into
mainfrom
feat/1656-setup-account-remove
Nov 20, 2026
Merged

scttfrdmn merged 3 commits into
mainfrom
feat/1656-setup-account-remove

Conversation

@scttfrdmn

@scttfrdmn scttfrdmn commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1656. Closes #1666. Part of the leave-no-trace epic, spore-host/spore-host#752 (Phase 3).

spawn setup-account provisions the user lease permissions (#1666)

spawn setup-account now also creates the customer-managed policy spore-host/spawn-user-lifecycle. It grants these actions on arn:aws:dynamodb:*:<account>:table/spore-host-lifecycle, with the account written in rather than a policy variable (#1069):

  • dynamodb:ConditionCheckItem, CreateTable, DeleteItem, DescribeTable, GetItem, PutItem, TagResource and UpdateItem.

How the list is held:

  • The list is lifecyclemark.UserActions(): RequiredActions plus the new VerdictReadActions (GetItem).
  • A new iamcoverage test, TestUserLifecyclePolicyGrantsWhatTheLeaseCallersCall, holds it equal to the DynamoDB actions that three callers reach in the call graph: lifecyclemark.Mark, lifecyclemark.Probe (spawn doctor) and (*lifecycle.Client).Get (reaper teardown --if-idle-for).
  • Checked against a mutation: swapping GetItem for Scan fails the test.

Tags and lifecycle:

  • It is tagged spore-host:managed-by=spawn, spore-host:permanent=true and spore-host:component=user-lifecycle. It is never tagged spore-host:role=service.
  • Footprint classes it permanent, so no idle teardown deletes it. Its name also matches no teardown pattern.
  • It is created idempotently. A re-run is read-only once the policy is current. A drifted document gets a new default version, pruned under the five-version cap, and missing tags are converged.
  • It is not created in the infra account, which has no lease.
  • The output tells the admin to attach it, with aws iam attach-group-policy ... --policy-arn <arn>.

The spawn doctor "idle teardown" warning and the mark's diagnostic line now name the policy and its ARN. They no longer say spore.host doesn't provision it.

Owner decision (confirmed): spore-host/spawn-user-lifecycle is permanent account setup, like the boundary. It keeps the permanent=true tag, and --remove is the only way it goes. footprintspawn.Classify also classes it permanent by ARN or name (IsUserLifecyclePolicy, mirroring footprint.IsBoundary), so a copy created untagged, when tagging was refused, is kept too. TestUserLifecyclePolicyIsPermanent covers this: disabling the rule fails 3 of its cases. Help text, docs-gen, the CHANGELOG and comments that called the boundary "the one permanent piece" now name exactly two pieces: the boundary and the user lifecycle policy. The cleanup --instance-roles keep reason also no longer says #1656 is unimplemented.

spawn setup-account --remove (#1656)

  • Report mode: without --yes, --remove only prints the numbered plan.
  • Refusals (nothing is deleted):
    • while any role or user has spore-host/spawn-instance-boundary as its permissions boundary (ListEntitiesForPolicy, PolicyUsageFilter=PermissionsBoundary). The refusal names each role or user;
    • while the boundary is attached as a regular policy;
    • while the user policy is someone's boundary;
    • in the infra account 966362334030, or an account that can't be identified. This is checked before any IAM call.
  • Order:
    1. The user policy: detach it from every group, user and role, delete its non-default versions oldest first, then DeletePolicy.
    2. With --offboard, the onboard role.
    3. The boundary, last. It is re-read just before deletion, so a role given the boundary since the plan was made refuses the step. Then its non-default versions are deleted, then DeletePolicy.
  • --offboard (only valid with --remove) also deletes spore-portal-onboard: its inline policies, then its managed attachments, then the role.
  • --yes and --offboard without --remove are usage errors.

The new IAM actions are in cli-iam-actions.md: iam:ListEntitiesForPolicy, DeletePolicy, DetachGroupPolicy, DetachUserPolicy, DetachRolePolicy, ListRolePolicies, ListAttachedRolePolicies, DeleteRolePolicy, DeleteRole and TagPolicy.

Tests (hermetic: no AWS)

pkg/testutil.IAMAccount is a new in-memory IAM account. It enforces that IAM refuses to delete a policy that is attached or has versions, refuses to delete a role that still has policies, and caps versions at five. It deliberately does not refuse to delete a policy that is in use as a boundary, so only spawn's guard can.

pkg/aws/iam_account_setup_test.go covers:

  • the exact document, with no ${ in it;
  • create-then-idempotent, and the tags;
  • the drift update;
  • footprint keeping the policy, whether attached or not;
  • the refusal while the boundary is in use;
  • the re-check before deleting the boundary;
  • that the plan only reads;
  • the exact deletion sequence: detach, then versions, then the policy, with the boundary last;
  • an empty account;
  • infra and empty account IDs, including a forged plan;
  • --offboard's order;
  • a foreign or stack-made role;
  • unreadable usage.

cmd/setup_account_test.go covers create plus re-run, the infra account, access denied, report mode, --yes, --offboard, the in-use refusal, the infra refusal and the flag errors. There are also tests in pkg/doctor and pkg/lifecyclemark.

Revert check: two mutations that compile, run separately:

  • disabling ExecuteAccountRemoval's re-check fails TestRemoveRechecksTheBoundaryBeforeDeletingIt;
  • disabling both that re-check and the plan's refusal fails that test and TestRemoveRefusesWhileTheBoundaryIsInUse.

Gates

  • make check, run from a space-free copy at /private/tmp: all checks passed.
  • make gen-docs, make cli-iam-actions and make api-snapshot were run and committed. The API snapshot has additions only, in pkg/aws.
  • The Tier 0 coverage reason for setup-account was updated in test/e2e/tier0_coverage_test.go.
  • CHANGELOG entries are under Added and Changed.
  • semgrep scan --config=auto --error on the changed files: 0 findings.

Not done here: a real CreatePolicy / PutRolePolicy / simulation of the user policy document. No AWS was touched in this work.

Companion docs: spore-host/spore-host (principle page and iam-permissions.md), spore-host/lagotto#339.

@codecov

codecov Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 51.81159% with 266 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/testutil/iamaccount.go 0.00% 215 Missing ⚠️
pkg/aws/iam_account_setup.go 85.41% 35 Missing ⚠️
cmd/setup_account.go 84.41% 12 Missing ⚠️
pkg/aws/iam_boundary.go 40.00% 3 Missing ⚠️
pkg/doctor/aws_prober.go 83.33% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn

Copy link
Copy Markdown
Contributor Author

Owner decision (2026-11-20): spore-host/spawn-user-lifecycle is permanent account setup, like the boundary, and only setup-account --remove removes it. The spore-host:permanent=true tag stands. The docs should list exactly these two as what spore.host leaves while an account is set up.

IAM verification (dev): a real CreatePolicy of the documented statement was accepted. Simulation:

  • allowed: UpdateItem, CreateTable, ConditionCheckItem, GetItem on spore-host-lifecycle;
  • implicitDeny: DeleteTable and Scan on it, UpdateItem on spawn-user-accounts, UpdateItem on another account's spore-host-lifecycle.

The test policy and role were deleted.

@scttfrdmn
scttfrdmn marked this pull request as ready for review November 20, 2026 19:04
…cycle-lease policy (#1656, #1666)

spawn setup-account now also creates spore-host/spawn-user-lifecycle, the
customer-managed policy granting CLI users the lease actions spawn's
creators, doctor and reaper teardown --if-idle-for call on
table/spore-host-lifecycle (held to the call graph by an iamcoverage test).
Tagged managed-by=spawn and permanent=true, never role=service.

spawn setup-account --remove deletes the boundary and the user policy:
report mode without --yes; refused while any role or user has the boundary
as its permissions boundary (named), and in the infra account; user policy
detached, older versions then the policy, boundary last after a re-read.
--offboard also deletes spore-portal-onboard (refusing a foreign or
CloudFormation-made role).

spawn doctor and the mark's diagnostic name the policy.

Part of spore-host/spore-host#752.
…, like the boundary (#1666)

Owner decision: spore-host/spawn-user-lifecycle is permanent; only
spawn setup-account --remove removes it. footprintspawn classes it
permanent by ARN or name (IsUserLifecyclePolicy), so an untagged one
(tagging refused at create) is kept too; TestUserLifecyclePolicyIsPermanent.

Wording everywhere that called the boundary the one permanent piece now
says exactly two: the boundary and the user lifecycle policy (help text of
setup-account, cleanup, footprint and teardown, docs-gen, CHANGELOG,
comments, and the cleanup keep reason, which named #1656 as unimplemented).
@scttfrdmn
scttfrdmn force-pushed the feat/1656-setup-account-remove branch from 58fab11 to 2b580bc Compare November 20, 2026 19:05
@scttfrdmn
scttfrdmn merged commit bdf49bb into main Nov 20, 2026
9 checks passed
@scttfrdmn
scttfrdmn deleted the feat/1656-setup-account-remove branch November 20, 2026 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant