Skip to content

fix(replay): re-decide authorization, quota, consistency and fault on replay (#833) - #1037

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/833-replay-pre-plugin-pipeline
Sep 17, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/833-replay-pre-plugin-pipeline

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

What

A replay entered the request pipeline at step 5. ReplayEngine.replayEvent called
PluginRegistry.RouteRequest directly, so authorization, quota, consistency and fault
injection — steps 2 through 4.5 — were all bypassed. A recorded 403 or an injected
500 replayed as a 200, and the replay then applied a state change the recorded run
never made: the bucket the recording was refused permission to create existed
afterwards.

Both halves of the contract had been written and never joined. CheckQuota and
CheckRead each open with an isReplaying guard and replayEvent has always set the
flag those guards read, but no replay ever called either controller — so the guards
were unreachable from the only path that sets the flag.

A shared prePluginGates (new emulator/pipeline_gates.go) now runs the four in one
place for both callers and reports which step refused, so the live path and the replay
path cannot answer differently. Server.handleAWSRequest keeps its per-step recording
and metrics by switching on the returned step; ordering, nil-controller skips and the
latency-then-error sequence are preserved exactly. StackDeployer.dispatch and
Server.stateAtSequence keep their own narrower subsets — out of scope here.

Per-step decisions

Step On replay Why
2 authorization re-decided against the principal restored from Event.Principal
3 quota consulted, exempt AC 2's own alternative; the guard stops being dead code
4 consistency consulted, exempt RecordWrite is guarded on the same flag, so no propagation window ever opens
4.5 fault injection re-decided, controller rewound else a spent Times bound makes the replay take the unfaulted path
1.5 credential resolution replaced superseded by principal restoration; the recorded key resolves to nothing
1.6 SigV4 skipped the canonical request cannot be rebuilt (raw query string never recorded; body re-encoded for iam/sts/sqs/sns), and the signature was verified once already
1.65 presigned expiry skipped a statement about the wall-clock moment the URL was signed
1.1 cbor/target conflict skipped a property of the HTTP request, which no event carries
1.4 region allow-list skipped a property of the replay's config, not of the recorded run

Each is stated in replayEvent's doc comment at the call site and in
docs/testing-guide.md under a new What a replay re-executes section (AC 5, AC 7).

Authorization needs nothing from #856

The blocker recorded twice on the issue — a mid-stream CreateAccessKey/AssumeRole
mints a different key on replay, so the recorded Authorization header names a key
absent from replayed state — is true of re-resolving the recorded key, and the key is
the wrong input. CheckAccess and every plugin's own authorize resolve the caller
with resolveIAMEntity(…, Principal.ARN), and an ARN survives a replay where a key
does not: user/<path><name> and assumed-role/<Role>/<Session> are derived from names
the recorded requests carried. replayPrincipal restores from Event.Principal, takes
tags from the replayed entity's record, and sets UserName only when that record
exists — per #745, since a registry hit with no IAM entity synthesizes
…:user/<access-key-id> and deriving a name from that would publish a credential ID as
aws:username.

The one residue that stays with #856 is aws:userid, which is minted and not
recoverable from the ARN, so it is absent rather than wrong — the shape
Principal.UserID already defines for a caller substrate has no ID for. Also worth
noting: a replayed request previously carried no principal at all, so every plugin's
own door was unenforced on replay too, not just the pipeline's.

Fault rewind

FaultController keeps the config it was armed with and rewindForReplay restores it
beside ResetPlugins. Without it a rule that fired during the recording has spent its
Times bound and advanced its PRNG, so an in-process record-then-replay takes the
unfaulted path — the exact divergence this issue is about, arriving through the fix.
Same class as #886/#902/#903. Armed counts are restored rather than zeroed, since a rule
may be armed carrying a non-zero Fired. A latency rule's delay is reported and not
slept: no replay may consume wall-clock time.

Wiring

NewReplayEngine gained one variadic option, WithReplayPipeline, following
NewEventStore's pattern rather than a seventh positional parameter — so the four
existing call sites keep compiling and an ungated replay stays available.
newReplayEngineWiring builds all four from the same quotas:, consistency: and
fault: sections substrate server reads. TestServer gained AuthController() and
FaultController().

Tests

emulator/replay_pipeline_test.go, all recording over the wire:

  • a recorded 403 replays as a 403 with no difference, and the bucket it refused
    is still absent after the replay (AC 1, AC 6);
  • the recorded event's principal is the user ARN, not the access key, and the denial
    names the user — the mechanism the above depends on;
  • an injected fault refuses again on two successive replays, with FaultsFired()
    reading 1 after each rather than accumulating, which is what shows the rewind rather
    than a leftover allowance (AC 3);
  • the rewind restores an armed non-zero Fired rather than zeroing it;
  • quota and consistency each refuse a live request and exempt a replaying one, asserted
    through the gate — a replay cannot distinguish "exempted" from "never reached", which
    is the confusion that left the guards dead (AC 2, AC 4);
  • a latency rule reports its delay alongside a nil error;
  • a replay given no pipeline still reports the recorded refusal as a critical
    difference, the negative control for the whole file.

Three stale comments in replay_reporting_test.go are corrected: a replay bypasses
fault injection only when it is handed no pipeline.

Verification

Nine-command gate green; coverage holds at 85.1% emulator / 84.6% total.

Closes #833

… replay (#833)

ReplayEngine.replayEvent called PluginRegistry.RouteRequest directly, so steps
2 through 4.5 of the server pipeline were bypassed: a request the recording
refused with a 403 or an injected 500 was re-executed on replay and succeeded,
applying a state change the recorded run never made.

Both halves of the contract had been written and never joined — CheckQuota and
CheckRead each open with an isReplaying guard and replayEvent has always set
the flag, but no replay ever called either controller. A shared prePluginGates
now runs the four in one place for the live and the replay path, reporting
which step refused so the server keeps its per-step recording and metrics.

Authorization is re-decided against a principal restored from Event.Principal
(the caller ARN, which survives a replay where an access key does not), so it
needs nothing from #856 beyond aws:userid, which stays absent per #745. Quota
and consistency are consulted and exempt a replay, which is what makes their
guards reachable. Fault injection is re-decided with the controller rewound to
its armed state, without which a rule that fired during the recording is spent
and the replay takes the unfaulted path.

Closes #833
@codecov

codecov Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.08772% with 17 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/replay.go 82.22% 8 Missing ⚠️
emulator/server.go 60.00% 6 Missing ⚠️
cmd/substrate/main.go 81.25% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit e0b4794 into main Sep 17, 2026
16 of 17 checks passed
@scttfrdmn
scttfrdmn deleted the fix/833-replay-pre-plugin-pipeline branch September 17, 2026 18:07
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.

Replay bypasses authorization, quota, consistency and fault injection

1 participant