Skip to content

dns-updater: verify record ownership; give app launches their own role for the TLS key - #1607

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/sec-dns-ownership
Nov 12, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/sec-dns-ownership

Conversation

@scttfrdmn

@scttfrdmn scttfrdmn commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #1606 (shares the spored policy schema): this PR's base is main so CI runs, and it carries #1606's commit; review the last commit. Merge #1606 first.

Summary

dns-updater: verify record ownership. The updater authorized the account but not the record within it. It now records which instance owns each record and checks that owner on every change and delete.

  • The owner is an instance as IAM identifies it: an instance-profile session arn:aws:sts::<acct>:assumed-role/<role>/<instance id> of one of spawn's instance roles (spored-instance-role, spawn-instance-*). Those roles trust only ec2.amazonaws.com.
  • The mapping is held server-side, in the zone, as _spore-instance.<fqdn> = "<instance id>". It is written in the same Route53 batch as the A record, and a first claim uses CREATE, so two instances cannot both claim one name. It is deleted together with the record by the updater, by the TTL reaper's DNS teardown and by its lease expiry.
  • An instance may register a free name or update its own record. It may take over another instance's record only once that record's lease is older than LeaseMaxAge (6h).
  • A record from before this change (no marker) may be claimed or deleted only by a request from the address the record points at. Current spored renews hourly, so every live record it owns is claimed within the hour.
  • Deletes are allowed only for the owner.
  • A caller that is not one of these instance sessions (spawn dns register/delete from a workstation) may change only records that no instance owns.
  • Enforce is now the default. DNS_AUTHZ_MODE=audit is the explicit opt-out. Unset, or any other value, enforces. This covers both the account check and the ownership check.

Wildcard TLS key. spawn app launch (web and DCV) now uses its own role, spawn-instance-app. Its inline grants are: the certificate read, limited to the account's own <base36>/ prefix; the DCV license; the ECR pull; and the spored binaries. spored-instance-role drops the read and explicitly denies s3:GetObject on spawn-certs-*, so older CLIs that rewrite the unversioned policy cannot re-add it. The app role is in the spawn-instance-* family, so pkg/instancerole deletes it once it is unused. Spored grant schema 3.

Deploy checklist impact

  • Lambdas changed: spawn-dns-updater (ownership, and the default mode flip) and spawn-ttl-reaper (deletes the owner marker with the record).
  • Manual steps before or with the deploy:
    1. dns-updater: enforce is now the default. Before deploying, put every account that must keep registering but is not in the account registry into DNS_ALLOWED_ACCOUNTS. docs/dns-updater-authorization.md names one such account, whose four live records are under c0zxr0ao. Otherwise, set DNS_AUTHZ_MODE=audit explicitly. Merge into the environment, as scripts/deploy-custom-dns.sh does; do not replace it.
    2. Certificate bucket policy (infra account): spawn-certs-<region> must grant s3:GetObject to role/spawn-instance-app in each entitled account before a release containing this ships. Otherwise app launches on the new CLI get no TLS certificate. Because the role can be reaped and recreated, name it through a condition on aws:PrincipalArn, not as a role-ARN principal. That bucket is provisioned from the umbrella repo.
  • IAM written by the CLI: spored-policy-v3, plus the new role and instance profile spawn-instance-app.

Tests

  • TestAuthorizeOwnership covers the rules as a table. TestHandlerRefusesAnotherInstancesRecord drives the real handler against the Route53 emulator and checks what ends up in the zone. TestCallerInstance, TestAuthzModeDefaultsToEnforce and TestDNSOwnerContractMatchesTheUpdater check the parts the updater and the root module share. The reaper's teardown and lease-expiry tests now expect the marker to be deleted. TestOnlyTheAppRoleReadsTheWildcardKey checks the TLS key access.
  • The emulator does not enforce Route53's CREATE-if-absent semantics, so atomicity of a claim is asserted at the change-action level only. Confirm it live.
  • The hermetic suite and nested-module tests pass, except the space-in-path known failures.

@scttfrdmn
scttfrdmn changed the base branch from fix/sec-instance-roles to main November 12, 2026 00:56
@scttfrdmn scttfrdmn closed this Nov 12, 2026
@scttfrdmn scttfrdmn reopened this Nov 12, 2026
@codecov

codecov Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 69.11765% with 21 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/aws/app_role.go 77.04% 14 Missing ⚠️
pkg/dns/lease.go 0.00% 6 Missing ⚠️
cmd/app.go 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn

Copy link
Copy Markdown
Contributor Author

Live check of the self-scope and TLS-key read, using a CLI built from this head: see #1606. From a default-role instance, reading the account's wildcard key returned 403. Not yet run:

  • the DNS ownership checks, which need spawn-dns-updater deployed in audit mode and then enforce, plus a decision on the DNS_ALLOWED_ACCOUNTS entry for the existing c0zxr0ao records;
  • the app TLS path, which needs the spawn-certs-us-east-1 bucket-policy update for spawn-instance-app.

Both are production changes and are waiting on owner approval.

@scttfrdmn

Copy link
Copy Markdown
Contributor Author

Prod prep done 2026-11-12 (owner-approved), ahead of the release that carries this PR. Each change was snapshotted first and diffed afterwards.

  • spawn-dns-updater: pinned DNS_AUTHZ_MODE=audit, so the new enforce-by-default code deploys in audit mode first. Only that variable changed, with the same CodeSha. DNS_ALLOWED_ACCOUNTS already lists the three accounts that use spore.host DNS, so their launches keep registering.
  • spawn-certs-us-east-1: added SporeAppRoleRead, which grants s3:GetObject on the one provisioned cert prefix (c0zxr0ao/*) to role/spawn-instance-app in that prefix's account. The grant is matched by aws:PrincipalArn and aws:PrincipalAccount, so the role need not exist yet. The existing statement is unchanged (S3 only reordered its principals), and the bucket is still not public.
  • Stale DNS: the 10 records whose leases had gone unrenewed for 32–583h (all in one account's subdomain) are expiring via the reaper's built-in lease expiry (REAPER_DNS_LEASE_EXPIRE=true; only that variable changed).

After release:

  1. Deploy the updater (audit) and watch for would refuse lines.
  2. Switch DNS_AUTHZ_MODE to enforce.
  3. Run the cross-instance UPSERT/DELETE 403 check and the app TLS launch.

@scttfrdmn

Copy link
Copy Markdown
Contributor Author

App TLS live check passed (dev, 2026-11-12), using an integration build with #1603. app launch jupyter ran under instance-profile/spawn-instance-app, fetched *.5k0zfnmq.spore.host through the new bucket grant (SporeAppRoleReadDev), and served a certificate that verifies against system trust (ssl_verify=0). The earlier proof stands: a default-role instance reading the key gets 403. Still to run after the updater deploys: DNS ownership (cross-instance UPSERT/DELETE → 403).

…pp launches

The DNS updater now checks that the calling instance owns the record it
changes or deletes, from an ownership marker held in the zone beside the
record (_spore-instance.<fqdn>), written atomically with it and deleted with
it by the updater, the TTL reaper's DNS teardown and its lease expiry. The
updater enforces by default; DNS_AUTHZ_MODE=audit is the explicit opt-out.

spawn app launch now uses its own role, spawn-instance-app, the only spawn
role that may read the account's wildcard TLS key; spored-instance-role
Denies the read. Spored grant schema 3.
@scttfrdmn
scttfrdmn force-pushed the fix/sec-dns-ownership branch from 16f0ca7 to 89df24c Compare November 12, 2026 18:19
@scttfrdmn
scttfrdmn marked this pull request as ready for review November 12, 2026 18:20
@scttfrdmn
scttfrdmn merged commit 4f156bb into main Nov 12, 2026
9 checks passed
@scttfrdmn
scttfrdmn deleted the fix/sec-dns-ownership branch November 12, 2026 18:43
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