Repository navigation
fix(replay): re-decide authorization, quota, consistency and fault on replay (#833) - #1037
Merged
Merged
Conversation
… 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 Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A replay entered the request pipeline at step 5.
ReplayEngine.replayEventcalledPluginRegistry.RouteRequestdirectly, so authorization, quota, consistency and faultinjection — steps 2 through 4.5 — were all bypassed. A recorded
403or an injected500replayed as a200, and the replay then applied a state change the recorded runnever made: the bucket the recording was refused permission to create existed
afterwards.
Both halves of the contract had been written and never joined.
CheckQuotaandCheckReadeach open with anisReplayingguard andreplayEventhas always set theflag 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(newemulator/pipeline_gates.go) now runs the four in oneplace for both callers and reports which step refused, so the live path and the replay
path cannot answer differently.
Server.handleAWSRequestkeeps its per-step recordingand metrics by switching on the returned step; ordering, nil-controller skips and the
latency-then-error sequence are preserved exactly.
StackDeployer.dispatchandServer.stateAtSequencekeep their own narrower subsets — out of scope here.Per-step decisions
Event.PrincipalRecordWriteis guarded on the same flag, so no propagation window ever opensTimesbound makes the replay take the unfaulted pathEach is stated in
replayEvent's doc comment at the call site and indocs/testing-guide.mdunder 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/AssumeRolemints a different key on replay, so the recorded
Authorizationheader names a keyabsent from replayed state — is true of re-resolving the recorded key, and the key is
the wrong input.
CheckAccessand every plugin's ownauthorizeresolve the callerwith
resolveIAMEntity(…, Principal.ARN), and an ARN survives a replay where a keydoes not:
user/<path><name>andassumed-role/<Role>/<Session>are derived from namesthe recorded requests carried.
replayPrincipalrestores fromEvent.Principal, takestags from the replayed entity's record, and sets
UserNameonly when that recordexists — 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 asaws:username.The one residue that stays with #856 is
aws:userid, which is minted and notrecoverable from the ARN, so it is absent rather than wrong — the shape
Principal.UserIDalready defines for a caller substrate has no ID for. Also worthnoting: 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
FaultControllerkeeps the config it was armed with andrewindForReplayrestores itbeside
ResetPlugins. Without it a rule that fired during the recording has spent itsTimesbound and advanced its PRNG, so an in-process record-then-replay takes theunfaulted 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 notslept: no replay may consume wall-clock time.
Wiring
NewReplayEnginegained one variadic option,WithReplayPipeline, followingNewEventStore's pattern rather than a seventh positional parameter — so the fourexisting call sites keep compiling and an ungated replay stays available.
newReplayEngineWiringbuilds all four from the samequotas:,consistency:andfault:sectionssubstrate serverreads.TestServergainedAuthController()andFaultController().Tests
emulator/replay_pipeline_test.go, all recording over the wire:403replays as a403with no difference, and the bucket it refusedis still absent after the replay (AC 1, AC 6);
names the user — the mechanism the above depends on;
FaultsFired()reading 1 after each rather than accumulating, which is what shows the rewind rather
than a leftover allowance (AC 3);
Firedrather than zeroing it;through the gate — a replay cannot distinguish "exempted" from "never reached", which
is the confusion that left the guards dead (AC 2, AC 4);
difference, the negative control for the whole file.
Three stale comments in
replay_reporting_test.goare corrected: a replay bypassesfault injection only when it is handed no pipeline.
Verification
Nine-command gate green; coverage holds at 85.1% emulator / 84.6% total.
Closes #833