Skip to content

Authorize DNS-updater callers against the account registry (#835) - #858

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/835-dns-authorize-callers
Oct 12, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/835-dns-authorize-callers

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Advisory GHSA-7pm4-cqjg-vh2q. Refs #835 deliberately — this does not close it; see What this does not do below.

The defect

The Function URL is AuthType: AWS_IAM and the canonical record is namespaced under the SigV4-verified caller account, so a caller cannot write outside its own base36 subdomain. That half was right (#173).

The other half was never written. The function's resource policy is the statement AWS auto-generates for a Function URL — Principal: "*", gated only on lambda:FunctionUrlAuthType — so any principal in any AWS account reached the handler with a verified identity. Read off the live function:

{"Sid":"FunctionURLAllowIAMAccess","Effect":"Allow","Principal":"*",
 "Action":"lambda:InvokeFunctionUrl",
 "Condition":{"StringEquals":{"lambda:FunctionUrlAuthType":"AWS_IAM"}}}

record_name is caller-chosen and the record lands in the real spore.host zone, so a stranger with a free AWS account could publish login.<their-base36>.spore.host pointing anywhere.

Which registry — and the hazard the issue didn't know about

#835 proposed spore-portal-accounts. It holds 0 items, so a lookup against it authorizes nobody. spawn-user-accounts is the populated one (3 items carrying aws_account_id).

But the zone serves four live A records under c0zxr0ao.spore.host — keel-skx, keel-zen4, keel-zen5, loop-l12-esc — and c0zxr0ao decodes to an account that is not in that table. The obvious implementation of this issue, shipped enforcing, would have taken four running hosts off the air. Hence DNS_AUTHZ_MODE: this deploys in audit, the logs say who actually calls, and enforcement is a separate deliberate flip — the staging the TTL reaper shipped with.

Also found: the table's account_base36 is not reliably the encoding of its aws_account_id (the cli row for 435415984226 stores c8s8u, which decodes to 20565246). So ownership questions must derive base36 from the verified account ID, never read it from the registry. Noted in the doc for the next consumer.

The grant

One inline policy, SpawnDNSAccountRegistryRead, scoped to one table, one attribute, and dynamodb:Select = SPECIFIC_ATTRIBUTES. The third is load-bearing: ForAllValues:StringEquals is satisfied by an empty set, so a Scan naming no attributes passes the dynamodb:Attributes condition and reads every field of every item. Same family as ForAllValues:StringNotEquals on aws:TagKeys being defeated by one innocuous tag.

It follows that the handler sets Select explicitly rather than letting DynamoDB infer it — a condition key the request doesn't carry evaluates as absent, so inferring it would leave the grant denying its own only caller, in production and nowhere else.

iam simulate-custom-policy, eight ways:

request decision
Scan, Select=SPECIFIC_ATTRIBUTES, Attributes=[aws_account_id] allowed
Scan also projecting email implicitDeny
Scan with Select=ALL_ATTRIBUTES implicitDeny
Scan with no condition context at all implicitDeny
Scan of a different table implicitDeny
GetItem / PutItem / DeleteTable implicitDeny

(The first run of that simulation errored on --policy-input-list wanting JSON strings. Worth noting because had it silently returned implicitDeny for everything, it would have looked like a flawless deny-all.)

The deploy script was unsafe to run

Which is why spawn-dns-updater was last deployed 2026-06-25. Three defects, each reporting success:

  1. It created and granted to SpawnDNSLambdaRole, which does not exist in the infra account. The function runs under SpawnDNSLambdaExecutionRole. Every permission the script granted went to a role nothing used — so a grant added here for this feature would simply not have taken effect.
  2. Its update path passed --environment Variables={HOSTED_ZONE_ID=…,DOMAIN=…}. --environment replaces the whole map, so running it would have deleted DOMAIN_ZONES (the only variable the live function has) and written DOMAIN, which the handler never reads. It would also have cleared DNS_AUTHZ_MODE — turning this fix off as a side effect of shipping unrelated code.
  3. It parsed --region, printed it, then ignored it: most of its aws calls carried no --region.

Plus --runtime on the update path, not only on create (#716).

Gates

Ten, each watched failing against a revert that compiles:

  • the handler authorization block removed; fail-open on lookup error; empty discovery read as permissive; DNS_AUTHZ_MODE defaulting to enforce; a failed lookup cached; the not-in-set check disabled; a malformed allowlist entry dropped unreported (two ways); a literal --environment on an update; the dynamodb:Select pin removed.

Two of my own gates had to be rewritten after they ran, both rule 6:

  • TestStaticAllowlistEntitlesAndIsValidated passed a revert that deleted the validation entirely. A malformed entry can never authorize anything — caller accounts are validated as 12 digits before the set is consulted — so the set contents were a correlate. The real mechanism is that the operator is told their typo was ignored, otherwise a mistyped account ID silently fails to entitle and the request it breaks is denied minutes later pointing nowhere near the typo. extraAllowedAccounts now returns its rejects and that is what's asserted.
  • TestDeployScriptsDoNotWipeTheEnvironment (already in the tree) matched only the literal Variables={} — the empty map, the memorable half of the bug it was written for. deploy-custom-dns.sh's non-empty literal sailed through and is equally destructive. Generalized to any literal map on an update path, which found the same latent bug in two more scripts: deploy-scheduler-handler.sh and the websocket processor's deploy.sh. Both verified against their live functions as displacing nothing today, and both now carry an adjacent env-replace-ok: marker stating the decision, in the style of the existing swallow-ok:. The generalized gate also could not see its own marker at first: the shared read() helper strips comments on purpose (rule 3), so this one gate reads the raw file.

What this does not do

Deploying this does not close the hole. Two live AWS steps remain, written up with snapshot/rollback in docs/dns-updater-authorization.md:

  1. Narrow the resource policy — the real fix; refuses at the URL before the handler runs and depends on no environment variable. Needs a decision on including the account owning those four records (listing it reduces its access, and grants spore.host nothing in it, so it is not a cross-account trust — but that reasoning should be checked, not taken on faith).
  2. Set DNS_AUTHZ_MODE=enforce once the audit logs confirm who calls.

Separately: #820's fix is merged but not deployed. The deployed binary contains aliasDNSName but not aliasSubdomainOwner or _spore-owner, so GHSA-q9qq-223w-mqx6's alias-hijack is still live. Filed separately.

🤖 Generated with Claude Code

The Function URL is AuthType: AWS_IAM and the record is namespaced under the
SigV4-verified caller, so a caller cannot write outside its own subdomain. The
authorization half was never written: the resource policy is the statement AWS
auto-generates, Principal: "*", so any principal in any AWS account reached the
handler with a verified identity.

The verified account is now checked against spawn-user-accounts plus an explicit
DNS_ALLOWED_ACCOUNTS list, failing closed on a lookup error and on a lookup that
returns nothing at all.

Enforcement is behind DNS_AUTHZ_MODE=enforce and defaults to audit, because the
zone serves four live A records under a subdomain belonging to an account that is
not in the registry. The ship-it-enforcing version would have been an outage.

Also fixes the deploy script, which was unsafe to run and is why this function
had not been deployed since 2026-06-25: it granted IAM to a role that does not
exist, its update path replaced the whole environment (deleting DOMAIN_ZONES),
and it ignored --region.

Refs #835
@codecov

codecov Bot commented Oct 12, 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 merged commit 73bbb66 into main Oct 12, 2026
7 checks passed
@scttfrdmn
scttfrdmn deleted the fix/835-dns-authorize-callers branch October 12, 2026 00:24
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