Skip to content

feat(authz): vendor AWS's per-operation authorization data, generated and drift-checked - #797

Merged
scttfrdmn merged 2 commits into
mainfrom
feat/authz-reference-table
Sep 11, 2026
Merged

scttfrdmn merged 2 commits into
mainfrom
feat/authz-reference-table

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Adds the data both #762 and #770 will be decided against. No behaviour change: no
production code reads the new table yet, which is what makes it reviewable in isolation.

The problem this solves first

Both issues turn on a per-action question — which resource types does this action support,
and what shape is a resource ARN of that type?
AWS answers it in the Service Authorization
Reference, whose HTML renders its tables in JavaScript and so cannot be read by a fetch.
docs/services.md already records that dead end for both ELB pages, and it is why some ELB
parameters are still authorized against *. Hand-transcribing 824 EC2 actions was the
alternative, and a hand-written list is an assertion about AWS with no source behind it.

AWS publishes the same data as JSON:

https://servicereference.us-east-1.amazonaws.com/v1/{service}/{service}.json

An action's Resources list names the resource types it supports, and an action with no
Resources list supports none
— that last fact is the whole of #762, published per action.

What lands

  • emulator/authzref/{ec2,iam}.json — pruned snapshots (ec2 v1.4: 824 actions, 114
    resource types; iam v1.4: 190 actions, 15 types), keeping only Name, Version,
    Actions[].Name, Actions[].Resources[].Name, Resources[].Name, Resources[].ARNFormats.
    A directory with no .go files, so no new package.
  • cmd/gen-authz-reference — generates emulator/authz_reference_gen.go from them.
    -check regenerates in memory and diffs, offline. -fetch re-downloads, and is the only
    network path in the tool.
  • emulator/authz_reference.go — the hand-written reader. Nothing else may touch the
    generated maps, so the meaning of an absent key stays in one place.
  • Makefile: authz-reference, authz-reference-check, authz-reference-fetch (the last
    documented as network-dependent and never run by CI).
  • CI: make authz-reference-check as a step on the existing docs-reference job, not a new
    job.

Two decisions worth review

The reader returns two values, not one. An action AWS scopes to * and an action substrate
names but AWS does not publish are different facts and must stay distinguishable — even though
both answers point at *. A resource narrower than the one AWS would use is a grant substrate
would be inventing, and inventing a grant is worse than inventing a refusal: the caller's
test passes here and their deployment fails there.

Deviation from the plan, stated rather than quietly taken. The plan said to prune EC2's
action rows if the generated file exceeded ~1500 lines. It is 1887. Pruning would have dropped
the ARN-format rows, which are precisely what makes the table #770's citation, and the only two
rows genuinely unreadable on one line — ec2:CreateTags and ec2:DeleteTags, over a hundred
resource types each — are already written one type per line by the generator.

Why vendored rather than fetched

Generation, the drift check and the whole test suite stay offline: no CI job and no test may
depend on network access. Refreshing is a deliberate human step and the diff it produces is
the review. The drift check exists because a refreshed snapshot committed without regenerating
would leave the table disagreeing with its own source — which is exactly how the #762 gate
would silently widen behaviour.

Verification

gofmt -l . && go build ./... && go vet ./... && golangci-lint run ./...   # clean
make test                                    # go1.27.1, pass
GOTOOLCHAIN=go1.26.6 make test               # pass
GOTOOLCHAIN=go1.26.6 make coverage           # emulator 83.5% (baseline held), total 82.9%
make docs-reference docs-reference-check docs-versions authz-reference-check   # pass
npm --prefix docs run build                  # pass
go vet -C test/e2e ./... && go test -C test/e2e ./...                          # pass

Total coverage moves 83.0% → 82.9%: the new generator package sits at 49.6%, because -fetch
and main's flag handling are deliberately untested — the first is the network path, and a test
that exercised it would violate the constraint this design exists to satisfy. prune,
writeEntry, render and load's four refusals are covered directly.

One unrelated flake surfaced under -race -cover:
TestConfigChannel_PutIsIdempotentAndASecondNameIsRefused failed once with
read: connection reset by peer against its own httptest server, then passed on re-run. It
touches nothing in this PR; filing separately, since a flake is exactly the signal substrate
exists to eliminate.

Towards #762 and #770.

… and drift-checked

Adds the table #762 and #770 are decided against, with no behaviour change of its
own. Both issues turn on a per-action question — which resource types does this
action support, and what shape is a resource ARN of that type — that AWS answers in
the Service Authorization Reference, whose HTML renders its tables in JavaScript and
so cannot be read by a fetch. docs/services.md already records that dead end for
both ELB pages, which is why some ELB parameters are still authorized against "*".

AWS publishes the same data as JSON at
https://servicereference.us-east-1.amazonaws.com/v1/{service}/{service}.json, where
an action's Resources list names the types it supports and an action with no
Resources list supports none. That last fact is the whole of #762, published per
action rather than argued about.

Pruned snapshots of ec2 (v1.4, 824 actions, 114 resource types) and iam (v1.4, 190
actions, 15 types) are committed under emulator/authzref, and cmd/gen-authz-reference
turns them into emulator/authz_reference_gen.go. Vendored rather than fetched at
generate time so that generation, the drift check and the whole test suite stay
offline: no CI job and no test may depend on network access. Refreshing is a
deliberate human step (make authz-reference-fetch) and the diff it produces is the
review. make authz-reference-check regenerates in memory and diffs, offline, and runs
on the existing docs-reference CI job, mirroring cmd/gen-service-reference — a
refreshed snapshot committed without regenerating would otherwise leave the table
disagreeing with its own source.

The reader returns both the resource types and whether AWS publishes the action at
all, because those are different facts: an action AWS scopes to "*" and an action
substrate names but AWS does not publish must stay distinguishable, even though both
answers point at "*". A resource narrower than the one AWS would use is a grant
substrate would be inventing, and inventing a grant is worse than inventing a
refusal.

Deviation from the plan, stated: the generated file is 1887 lines rather than pruned
below the ~1500 the plan allowed for. The alternative was dropping the ARN-format
rows, which are precisely what makes the table #770's citation, and the only two rows
genuinely unreadable on one line (ec2:CreateTags and ec2:DeleteTags, over a hundred
types each) are already written one type per line.

A test sweeps every resource-ID prefix ec2TaggableResource recognizes and asserts AWS
publishes the resource type substrate names for it. The forthcoming #762 gate compares
those names by string, so a type substrate spells differently from AWS — natgateway is
unhyphenated where every sibling is hyphenated — would silently never match and
quietly widen every operation naming it to "*".

Towards #762 and #770.
@scttfrdmn scttfrdmn added this to the v0.111.0 milestone Sep 11, 2026
@codecov

codecov Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 64.15094% with 57 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/gen-authz-reference/main.go 60.68% 57 Missing ⚠️

📢 Thoughts on this report? Let us know!

download's parse, prune and refusal branches were untested, which left the
generator at 49.6% and the new lines short on patch coverage. An httptest server
covers them without a test that reaches the internet — the constraint the
vendored-snapshot design exists to satisfy — and pins that AWS's per-action
ConditionKeys are dropped by pruning, since substrate reads its condition keys
from the API reference and a second differently-shaped copy would be a source to
keep in sync for no gain.

Generator coverage 49.6% -> 61.8%. Only -fetch's own loop over the fixed endpoint
is left untested; it is the one part that cannot run offline.
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