Skip to content

dns-updater: read the account registry with one keyed GetItem (#1611) - #1632

Merged
scttfrdmn merged 3 commits into
mainfrom
hardening/1611-dns-registry-getitem
Nov 14, 2026
Merged

scttfrdmn merged 3 commits into
mainfrom
hardening/1611-dns-registry-getitem

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #1611

What changes

The registry lookup is now a keyed GetItem, on a table that can be keyed by account. The updater used to Scan spawn-user-accounts, which is keyed on user_id (GSIs on cli_iam_arn and email), so it cannot be read by account ID. The Scan grant was never on the live role, so every registration since v0.164.0 logged the registry unreadable and fell back to DNS_ALLOWED_ACCOUNTS.

The updater now makes one GetItem by the SigV4-verified account ID on spore-portal-accounts. That table is keyed on accountId, and dashboard-api already reads it for entitlement (#1605). The read projects accountId and status. An offboarded row, or no row, refuses. Answers are cached per account (5 min if entitled, 1 min if refused), failures are not cached, and DNS_ALLOWED_ACCOUNTS is checked first with no DynamoDB call. DNS_ACCOUNTS_TABLE now defaults to spore-portal-accounts.

Why not stay on spawn-user-accounts: a keyed read there needs a new GSI, which is a live table change. dashboard-api also writes that table on a caller's first request, and before #1605 it did so for any caller, so it is a weaker entitlement source. This changes nothing for the accounts that register today, because live behaviour is already DNS_ALLOWED_ACCOUNTS only.

Where the role policy lives: scripts/deploy-custom-dns.sh, as inline policies on SpawnDNSLambdaExecutionRole:

  • SpawnDNSAccountRegistryRead (same name, so put-role-policy replaces the old Scan grant): dynamodb:GetItem on table/spore-portal-accounts, ForAllValues:StringEquals dynamodb:Attributes [accountId, status], plus Null dynamodb:Attributes false. The Null is needed because ForAllValues passes a no-projection GetItem, which would read the whole row with its onboarding role and ExternalId. dynamodb:Select is a Query/Scan key only.
  • SpawnDNSAccountRegistryKMS: kms:Decrypt on the table's CMK (read from describe-table), with kms:ViaService=dynamodb.us-east-1.amazonaws.com and kms:EncryptionContext:aws:dynamodb:tableName=spore-portal-accounts. This mirrors dashboard-api's grant.

Tests

  • registry_grant_test.go (the test the issue asks for): it parses the script's SpawnDNSAccountRegistryRead heredoc and requires exactly one statement allowing exactly dynamodb:GetItem on the registry. The granted attribute set must equal the attributes registryGetItemInput projects, the Null guard must be present, and the key must be exactly accountId.
  • authorize_test.go covers: no row, an offboarded row, an error, a failure not cached but a success cached, and an allow-listed account making no registry call.
  • The iamcoverage gate passes (it sees dynamodb:GetItem granted). make check is clean apart from the known space-in-path failures. Semgrep and shellcheck are clean.

Deploy steps (966362334030, us-east-1)

  1. Snapshot: aws iam get-role-policy --role-name SpawnDNSLambdaExecutionRole --policy-name SpawnDNSAccountRegistryRead (expect NoSuchEntity, per the production error) and aws lambda get-function-configuration --function-name spawn-dns-updater --query Environment.Variables (keys only).
  2. IAM before code: apply the two policies. Either re-run scripts/deploy-custom-dns.sh --hosted-zone-id Z0341053304H0DQXF6U4X --domain spore.host --region us-east-1, which also redeploys the code and merges env, or put-role-policy the two heredocs by hand.
  3. Check DNS_ACCOUNTS_TABLE: if the live function sets it to spawn-user-accounts, unset it or set it to spore-portal-accounts. Keep DNS_ALLOWED_ACCOUNTS as is (the c0zxr0ao account must stay listed).
  4. Deploy spawn-dns-updater (the script above, or the release's code-only deploy).

Simulate (aws iam simulate-principal-policy --policy-source-arn arn:aws:iam::966362334030:role/SpawnDNSLambdaExecutionRole)

action / resource / context expect
dynamodb:GetItem on table/spore-portal-accounts, dynamodb:Attributes=accountId,status allowed
same, dynamodb:Attributes=accountId,status,onboardRoleArn implicitDeny
same, no dynamodb:Attributes context implicitDeny
dynamodb:Scan on table/spore-portal-accounts implicitDeny
dynamodb:Scan on table/spawn-user-accounts implicitDeny (old grant gone)
kms:Decrypt on the registry key, kms:ViaService=dynamodb.us-east-1.amazonaws.com, tableName context spore-portal-accounts allowed
kms:Decrypt on the key, no kms:ViaService implicitDeny

Both policies contain no ${aws:...} variables in Resource, and every condition key belongs to its action's service. Still do one real put-role-policy (step 2) before relying on it.

Live checks after deploy

  • Register DNS from a spore in an account that is in the portal registry but not in DNS_ALLOWED_ACCOUNTS. It should succeed, and the log should have no registry unreadable or could not read account line.
  • In CloudWatch, the warning: account registry unreadable lines stop (count only).
  • A spore in an unregistered, unlisted account gets a 403 naming spore-portal-accounts.

@codecov

codecov Bot commented Nov 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn force-pushed the hardening/1611-dns-registry-getitem branch from 089b605 to 85a9077 Compare November 14, 2026 20:17
scttfrdmn and others added 3 commits November 14, 2026 14:16
The updater scanned spawn-user-accounts, which is keyed on user_id and
cannot be read by account, and the Scan grant was never on the live role,
so every registration fell back to DNS_ALLOWED_ACCOUNTS and a newly
onboarded account was refused under enforce.

It now GetItems the verified account ID in spore-portal-accounts (keyed on
accountId; dashboard-api's entitlement source), projecting accountId and
status, refusing offboarded rows, caching per account and never caching a
failure. scripts/deploy-custom-dns.sh grants exactly that GetItem (attribute-
scoped, Null-guarded) plus kms:Decrypt on the table key via DynamoDB, under
the same policy name, replacing the Scan. registry_grant_test.go holds the
request and the grant together.
@scttfrdmn
scttfrdmn marked this pull request as ready for review November 14, 2026 22:16
@scttfrdmn
scttfrdmn force-pushed the hardening/1611-dns-registry-getitem branch from 85a9077 to 9a5d305 Compare November 14, 2026 22:16
@scttfrdmn
scttfrdmn merged commit 0289dd6 into main Nov 14, 2026
9 checks passed
@scttfrdmn
scttfrdmn deleted the hardening/1611-dns-registry-getitem branch November 14, 2026 22:32
@scttfrdmn scttfrdmn mentioned this pull request Nov 15, 2026
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.

dns-updater cannot read the account registry: SpawnDNSLambdaExecutionRole lacks dynamodb:Scan on spawn-user-accounts

1 participant