Skip to content

Move session tokens out of EC2 tags - #1603

Merged
scttfrdmn merged 4 commits into
mainfrom
fix/sec-tokens-dashboard-auth
Nov 12, 2026
Merged

scttfrdmn merged 4 commits into
mainfrom
fix/sec-tokens-dashboard-auth

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Moves DCV and web-app session tokens out of EC2 tags.

What changes

  • spored no longer writes spawn:ready-token, and spawn:ready-url no longer carries a token. It writes spawn:ready-status, a token-free spawn:ready-url, and a new spawn:ready-auth (token | none).
  • Tokens are client-minted. spawn app launch, spawn connect (DCV) and the new spawn app url <instance> mint a 256-bit token locally and register only its SHA-256 on the instance over SSM: /usr/local/bin/spored access-token add --kind dcv|web --sha256 <hex> --ttl <n>s. spored keeps the hashes root-only on tmpfs (/run/spored/access-tokens, 0700/0600).
  • Expiry and rotation. Each token expires (default 12h, max 168h) and is checked on every DCV auth call and on every proxied web request, including the cookie, whose Expires matches the token. Each connect gets a new token. A stop/start or reboot clears them all. spored access-token revoke-all revokes them on demand. The DCV verifier also checks that the request names this instance's session.
  • Upgrade cleanup. On its first tick, a DCV/web spored deletes spawn:ready-token and the previous start's spawn:ready-url / ready-status / ready-auth, so a client waking a stopped instance waits for this start's readiness.
  • dashboard-api leaves spawn:ready-token and spawn:ready-url out of the instance tag passthrough.
  • Older agents. Against an instance whose spored predates this (no spawn:ready-auth), the CLI still uses the token that agent published and prints a warning naming spawn upgrade-spored.
  • ~/.spawn/sessions is now 0700 and its files 0600.
  • docs/reference/cli-iam-actions.md is regenerated: spawn app launch and spawn app url now use ssm:SendCommand / ssm:GetCommandInvocation. spawn connect already did. The spored role already has AmazonSSMManagedInstanceCore. No new IAM is created, and there is nothing to delete.

Wire contract for other clients

A client that opens sessions (spawn-ts, the portal, MCP) mints a token, sends spored access-token add … with the hash via SSM AWS-RunShellScript, and builds https://<host>:8443/?authToken=<t>#<session> or https://<host>/?spore_token=<t>. pkg/accesstoken is the reference implementation.

Deploy checklist impact

  • spored (user-data/bootstrap behaviour): the new spored ships with the release. spored is pinned at launch, so instances that are already running keep the old behaviour until spawn upgrade-spored or a relaunch. Needs the owner's live check before merge (steps are in the PR comment).
  • dashboard-api: the code changed (tag passthrough). Redeploy it with the release. There is no config change.
  • No CloudFormation, IAM or table changes.

Tests

Unit tests with fakes: the token store (expiry, kind, symlink refusal, perms), the DCV verifier, the web gate (cookie expiry, expired/revoked/kind-mismatch), that neither handshake publishes a token, the stale-tag cleanup (also through the monitor tick), the spawn↔spored command contract, and the CLI registration (only the hash goes over SSM, retry while SSM comes up, older-agent detection). Also the spawn app url flow and the dashboard tag passthrough. make check is green. semgrep scan --config=auto --error on the changed paths is clean.

@codecov

codecov Bot commented Nov 12, 2026

Copy link
Copy Markdown

@scttfrdmn

Copy link
Copy Markdown
Contributor Author

Live check before merge (owner; spore-host-dev, TTL on every launch, leak-check after)

  1. Build: go build -o ~/.xtmp/spawn-pr . and GOOS=linux GOARCH=amd64 go build -o ~/.xtmp/spored-pr ./cmd/spored. Put spored-pr in a scratch bucket and aws s3 presign it.
  2. spawn-pr app launch jupyter --ttl 1h --no-open. A dev spawn installs the published spored, so you should see the older-agent warning and a link that works.
  3. Swap in the branch spored over SSM: curl -o /tmp/spored <presigned> && install -m0755 /tmp/spored /usr/local/bin/spored && systemctl restart spored.
  4. Tags on the instance: no spawn:ready-token, spawn:ready-url=https://<host>/ (no token), spawn:ready-auth=token, spawn:ready-status=ready.
  5. spawn-pr app url <id> opens Jupyter. A bare https://<host>/ returns 403. aws ssm list-commands --instance-id <id> shows only --sha256 <hex>. After sudo spored access-token revoke-all the open tab gets 403, and a new app url works. A second machine's app url also works.
  6. DCV: spawn-pr app launch desktop --ttl 1h, swap spored, spawn stop <id>, then spawn connect <id>. The session opens with no login prompt, and spawn:ready-url is https://<host>:8443/#console.
  7. Lifecycle: the TTL deadline is unchanged across the spored restart, idle-stop still fires, and spawn extend works.
  8. Terminate everything and check for leftover spawn:managed instances in every region.

@scttfrdmn

Copy link
Copy Markdown
Contributor Author

Partial live check (spore-host-dev, 2026-11-12):

  • `app launch jupyter` with this PR's CLI, then its spored swapped in: no `spawn:ready-token` tag. spored ran 0.163.3-dev (`92e95796`).
  • Blocked: the web path end to end (proxy 403 on a bare URL, `app url` minting and registering a hash, revoke-all). The dev account has no wildcard certificate (`spawn-certs-us-east-1` holds only one other account's prefix), so the TLS reverse proxy never starts: `load webproxy cert … no such file` and `spawn:ready-status=web-proxy-failed`. This predates the PR. It needs either a dev wildcard cert or an account that has one.

Instance terminated, leak check clean.

@scttfrdmn

Copy link
Copy Markdown
Contributor Author

Live check passed end to end (spore-host-dev, 2026-11-12). The build was a local integration of this PR with #1607, on a c7i.large. Dev now has a wildcard cert (#712).

check result
tags after this spored starts `ready-auth=token`, `ready-status=ready`, `ready-url=https:///` (no token); `spawn:ready-token` absent
`spawn app url` a fresh 64-char token
bare URL / correct token / wrong token 403 / 302 (into the app) / 403
plaintext token in any SSM command's parameters / outputs 0 / 0; only its sha256 appears
`spored access-token revoke-all` → old token 403; a fresh `app url` gives a different, working token
published spored (0.163.2) the CLI warns that it publishes the token in a tag and names `upgrade-spored`

Teardown is clean: the instance is terminated, and the scratch bucket and `spawn-web` SG are deleted. Independent leak check: nothing left.

Not run: DCV (`app launch desktop`), and dashboard-api, which belongs to #1605's deploy.

spored now publishes only that a DCV or web-app session is ready
(spawn:ready-status, spawn:ready-auth, a token-free spawn:ready-url).
Clients mint the token locally and register its SHA-256 on the instance
over SSM (spored access-token add); spored checks presented tokens
against the registered hashes, which expire (12h default) and live on
tmpfs. spored deletes the legacy token tags at start, dashboard-api
stops returning them, and spawn app url prints a fresh link.
@scttfrdmn
scttfrdmn force-pushed the fix/sec-tokens-dashboard-auth branch from 92e9579 to 8ad8ca9 Compare November 12, 2026 19:25
@scttfrdmn
scttfrdmn marked this pull request as ready for review November 12, 2026 19:25
@scttfrdmn
scttfrdmn merged commit bb670a3 into main Nov 12, 2026
9 checks passed
@scttfrdmn
scttfrdmn deleted the fix/sec-tokens-dashboard-auth branch November 12, 2026 19:43
scttfrdmn added a commit that referenced this pull request Nov 13, 2026
The session page embeds the DCV session token. #1603 made new pages 0600
and the sessions directory 0700, but ~/.spawn itself was still created
0755 by spawn cleanup's log, and pages older releases wrote stayed 0644.
spawnHomeSubdir creates and tightens ~/.spawn and the subdirectory to
0700; getSessionsDir tightens existing pages to 0600; the sweeps state
dir and the cleanup log follow.
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