Skip to content

Make four gates discover their sets instead of listing them - #847

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/845-handmaintained-lists
Oct 11, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/845-handmaintained-lists

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Closes #845. Correctness audit 2026-10, Phase 4 — the hand-maintained-list class (rule 4),
four instances in one package pair.

1. templateSummary claimed 16 parameters; the template declares 19

fixture:  16
template: 19
missing:  LogRetentionDays, NetResources, Version

The merge-params machinery exists to stop a deploy resetting a live parameter — the thing
that disarmed the production reaper once. For three parameters it was never exercised, and
NetResources is the staged destructive sweep (#685).

Two assertions inside the same file also said "want all 16 declared", so they asserted
against a world three parameters smaller than the real one and passed. All three now derive
from template.yaml.

2. apiServicePrefix omitted route53 — a whole service invisible to its own gate

pkg/reaperiam's gate asserts that every AWS action the reaper calls is granted. Both
halves of the discovery were anchored on four hand-written entries:

var apiServicePrefix = map[string]string{"ec2":"ec2","fsx":"fsx","ssm":"ssm","netResource":"ec2"}
var methodCall = regexp.MustCompile(`\b(ec2|fsx|ssm)Client\.([A-Z][A-Za-z0-9]+)\(`)

The reaper has a route53API interface and a route53Client, and calls
ListResourceRecordSets and ChangeResourceRecordSets. So "every action the reaper calls"
silently excluded a service. Service names are discovered now, and an unmapped one
fails rather than resolving to "":

main.go calls dynamodbClient.PutItem, but "dynamodb" maps to no IAM service — so this
call is invisible to the coverage gate below.

No live defect behind it, checked rather than assumed: the SAM template grants Route53
scoped to the hosted zone, the live production role has it
(TTLReaperFunctionRolePolicy2), and spawn reaper deploy exposes no DNS flags so
ScanSelfPolicyDocument has nothing to grant. The gate would not have said either way,
which is the point.

Two calls nobody had reasoned about

Real discovery surfaced sts:GetCallerIdentity and the two Route53 actions as ungranted —
they had always been excluded, so nobody had ever had to decide. Both are now in a
grantedElsewhere map with a reason.

sts:GetCallerIdentity needing no IAM permission is proven, not assumed: the live
production role grants only sts:AssumeRole (scoped to the cross-account role), the reaper
calls GetCallerIdentity on every invocation, and it has been succeeding every ten minutes.

This is an exception list, not the rule-6 smell: the rule ("every called action must be
granted") is right, and these are scope boundaries with evidence, like
fsx:DeleteFileSystem → #613.

3. The four sentinels were enumerated by hand in two gates

TestSentinelSpellingsAreStable and TestEverySentinelHasAMetricFilter each listed the
same four constants, so a fifth would have had no spelling pin and no metric-filter
requirement. The sentinels are a literal-text contract with CloudWatch metric filters, so
an unalarmed one is a log line nobody sees — the same failure as the heartbeat tag spored
wrote for months with zero readers (#682).

Discovered from failures.go now, with a floor. That also folds the rename case into the
same check, since a renamed constant is a literal the template no longer contains — so one
gate replaces two. Verified against three reverts: a fifth sentinel with no filter, a
rename, and a filter removed from the template.

4. The PARAM_MAP gate never checked the make-variable

if !strings.Contains(string(mk), name+":") {

That matches the CFN key half of a CfnKey:MAKE_VAR pair and nothing else, so
DryRun:DRYRUN satisfied it while make deploy DRY_RUN=true was silently ignored — the
exact failure the PARAM_MAP exists to prevent, undetected by the gate guarding it. It was
also unanchored, so any mention of DryRun: anywhere in the Makefile counted.

It parses the pairs now and checks the make-variable against the SCREAMING_SNAKE
convention, with Environment:ENV as the one documented departure:

PARAM_MAP maps DryRun to the make variable DRYRUN, but the Makefile's own default and
every documented invocation use DRY_RUN. A mismatch here is silent: $(origin DRYRUN) is
undefined, so the parameter is never sent and the deploy inherits whatever is live.

Deliberately not here: the bare-substring sweep → #846

The plan's remaining Phase 4 item. There are 324 strings.Contains(artifact, …)
assertions and most are correct. The narrow defect is a literal that also appears in prose
in the generating source, so the gate cannot fail — I hit two instances today and fixed
each in place (#818's comment, #808's "skipping verification").

I attempted regex detection and it is not trustworthy: 38 candidates dominated by false
positives, because stripping // with a regex also strips inside string literals. It
flagged iam:CreateServiceLinkedRole as comment-only; it is in code at
pkg/aws/iam.go:1013. Doing it properly needs go/ast, which is its own piece of work —
#846.

Verification

make check (all nested modules), make check-docs, changelog gate,
scripts/lambda-deploy-census.sh, semgrep 0 findings, Tier 0 e2e with -count=1.

Eight compiling reverts across the four gates: a wrong make-variable, a parameter dropped
from PARAM_MAP, a fifth sentinel with no filter, a sentinel rename, a filter removed, a new
client with an unmapped service, a genuinely missing grant (still caught), and route53
removed from grantedElsewhere (then correctly reported).

@scttfrdmn scttfrdmn added this to the Correctness audit 2026-10 milestone Oct 11, 2026
All four reported a clean bill of health for everything their list
forgot — rule 4, four times in one package pair.

templateSummary claimed "the 16 parameters the reaper template
declares". It declares 19. NetResources, Version and LogRetentionDays
were added and the fixture never updated, so the merge-params
machinery — whose job is to stop a deploy resetting a live parameter,
the thing that disarmed the production reaper once — was never exercised
for three of them. NetResources is the staged DESTRUCTIVE sweep (#685).
Two assertions in the same file also said "want all 16 declared", so
they asserted against a world three parameters smaller than the real one
and passed. All three derive from template.yaml now.

apiServicePrefix omitted route53, which made a whole service invisible
to its own coverage gate. pkg/reaperiam asserts that every AWS action
the reaper calls is granted, and both halves of the discovery were
anchored on four hand-written entries — `(ec2|fsx|ssm)Client` in the
regex, four keys in the map. The reaper has a route53API interface and
calls ListResourceRecordSets and ChangeResourceRecordSets, so "every
action the reaper calls" silently excluded a service. Service names are
discovered now, and an unmapped one FAILS rather than resolving to "".

That hid no live defect — checked: the SAM template grants Route53
scoped to the hosted zone, the live production role has it, and
`spawn reaper deploy` exposes no DNS flags so ScanSelfPolicyDocument has
nothing to grant. The gate would not have told us either way.

Real discovery surfaced two calls nobody had reasoned about because they
had always been excluded. Both are recorded in grantedElsewhere with a
reason. sts:GetCallerIdentity needing no IAM permission is proven, not
assumed: the live role grants only sts:AssumeRole, and the reaper calls
GetCallerIdentity every invocation and has been succeeding every ten
minutes.

The four reaper sentinels were enumerated by hand in TWO gates, so a
fifth would have had no spelling pin and no metric-filter requirement.
They are discovered from failures.go now, with a floor — which also
folds the rename case into the same check, since a renamed constant is a
literal the template no longer contains.

TestEveryTemplateParameterIsInThePARAMMAP matched the CFN key half of a
CfnKey:MAKE_VAR pair and never the make-variable, so DryRun:DRYRUN
passed while `make deploy DRY_RUN=true` was silently ignored — the exact
failure the PARAM_MAP exists to prevent, undetected by the gate guarding
it. It parses the pairs now and checks the make-variable against the
SCREAMING_SNAKE convention, with Environment:ENV as the one documented
departure.

Two mistakes of my own, both caught and both recorded in place:

A 42 MB pipeline-orchestrator binary went in via `git add -A`, and
TestNoTrackedCompiledBinaries caught it in CI rather than locally. A
single-package `go build ./lambda/<name>/` writes the executable into
the CURRENT directory, so the long-standing lambda/<name>/<name> ignore
entries never covered the repo root. .gitignore covers both paths now,
and TestEveryGoLambdaBinaryIsIgnored checks the root half too — scoped
to lambdas in the ROOT module, since one with its own go.mod cannot be
built from the root at all. Requiring it for all twelve was my first
version: rule 6's mistake inside the fix for rule 4.

And the reaperiam work was lost once before this commit. Verifying a
revert, I used `git checkout pkg/reaperiam/drift_test.go` to discard
it — which discards to HEAD, taking the real change with it, because the
revert and the work were in the same file. Every other revert in this
session used a cp backup. The PR would have claimed a fix it did not
contain.

The bare-substring sweep is #846 rather than this PR: 324 such
assertions exist and most are correct, the narrow defect needs go/ast to
detect, and a regex attempt produced 38 candidates dominated by false
positives — it flagged iam:CreateServiceLinkedRole as comment-only when
it is in code at pkg/aws/iam.go:1013.

Closes #845
@scttfrdmn
scttfrdmn force-pushed the fix/845-handmaintained-lists branch from 312d9c2 to c70c381 Compare October 11, 2026 21:40
@scttfrdmn

Copy link
Copy Markdown
Contributor Author

Force-pushed. Two mistakes of my own in the first push, both worth stating because one of
them would have shipped a PR that claimed a fix it did not contain.

1. The reaperiam work was not in the commit at all. While verifying a revert I used
git checkout pkg/reaperiam/drift_test.go to discard it — and git checkout discards to
HEAD, which took my actual change with it, because the revert and the work were in the
same file. Every other revert in this session used a cp backup for exactly this reason;
this one did not. The PR body described the apiServicePrefix fix and the diff contained
none of it.

I noticed because the diff stat was four files when it should have been five. The fix is
redone and re-verified against both reverts:

R1  a new client whose service is unmapped
    -> main.go calls dynamodbClient.PutItem, but "dynamodb" maps to no IAM service —
       so this call is invisible to the coverage gate below.
R2  route53 removed from grantedElsewhere
    -> the reaper calls AWS actions the scan-self policy does not grant:
       route53:ListResourceRecordSets

2. A 42 MB binary went in via git add -A, which is why CI's Test job failed:

--- FAIL: TestNoTrackedCompiledBinaries
      pipeline-orchestrator (Mach-O 64-bit)

The gate did its job; my make check runs had happened before the build that created it.
A single-package go build ./lambda/<name>/ writes the executable into the current
directory rather than next to its source, so the long-standing lambda/<name>/<name>
ignore entries never covered the repo root.

.gitignore now covers both paths, and TestEveryGoLambdaBinaryIsIgnored — which already
checked the per-directory half — checks the root half too.

And a third, inside that fix. My first version required a root entry for all twelve
lambda directories. Only pipeline-orchestrator is in the root module; the other eight Go
ones have their own go.mod and cannot be built from the repo root at all
(go build ./lambda/scheduler-handler/ → "main module does not contain package"). So the
gate was over-strict and its failure message was false for eight of them. It is scoped to
the root module now.

That is rule 6's mistake — gating a correlate, the set of lambda names, rather than the
mechanism, the set that can produce a root binary — committed inside a PR whose subject is
rule 4. Which is a reasonable argument that the two rules are the same rule seen from
different sides.

@scttfrdmn
scttfrdmn merged commit c127a0e into main Oct 11, 2026
7 checks passed
@scttfrdmn
scttfrdmn deleted the fix/845-handmaintained-lists branch October 11, 2026 21:49
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.

Four gates reported a clean bill of health for sets they only partly covered

1 participant