Repository navigation
Deploy, canary, shadow and roll back from the dashboard - #17
Merged
Merged
Conversation
Every action is two steps: a plan that says exactly what will change, then an apply that carries it out. A single button that immediately moved traffic would be the wrong shape — these operations decide which model answers every request, they are triggered by a mouse rather than a reviewed script, and the cost of a mis-click is wrong predictions rather than an error message. The confirmation is where somebody sees "90/10 becomes 100% v2" before it is true. Apply refuses if the policy changed between the plan and the confirm. Without that the later click wins by arriving later, and the person whose change was discarded has no way to know. The policy label doubles as the comparison token and is order-independent, so two policies that mean the same thing compare equal. This is what the CSRF form field is for. A page with no JavaScript cannot set a header, so the token comes back in the body instead — equally safe, since what makes double-submit work is that a cross-site attacker cannot read the cookie, and that holds wherever the value is echoed. Only form-encoded bodies are parsed for it: calling ParseForm on a JSON request would consume the body the handler is about to decode, so a convenience for HTML forms would have silently broken every API POST. The dashboard and the JSON API now share one applyPolicy, so a version that cannot load is refused identically and a shadow is carried across the same way. Two code paths that both change what serves production traffic would be two places for the rules to drift, and the one with fewer checks becomes the way in. The forms sit behind the admin scope and are not rendered for a read-only credential, since buttons that always refuse are worse than no buttons. Apply redirects afterwards so a refresh does not re-apply, and the audit line records the effect rather than only the route. TestDashboardIsReadOnly asserted the pages contained no form, which this makes false. It is replaced by the properties that still hold: the index carries no actions, every form on the model page carries a CSRF token and uses POST, and the action routes exist only under POST so no amount of link-following changes what serves traffic. Coverage across internal/ is 89.9%.
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.
The thing I deliberately scoped out of the dashboard, now built with the concern I raised about it handled.
Every action is two steps — a plan that says exactly what will change, then an apply:
A single button that immediately moved traffic would be the wrong shape. These operations decide which model answers every request, they are triggered by a mouse rather than a reviewed script, and the cost of a mis-click is wrong predictions rather than an error message.
Two operators cannot silently overwrite each other
The policy as it stood when the confirmation was rendered travels in the form, and apply refuses if it no longer matches:
Without it the later click wins by arriving later, and whoever's change was discarded has no way to know. The label doubles as the comparison token and is order-independent, so two policies meaning the same thing compare equal.
Why the CSRF check now accepts a form field
A page with no JavaScript cannot set a header, so
csrf_tokencomes back in the body. Equally safe: what makes double-submit work is that a cross-site attacker cannot read the cookie, and that holds wherever the value is echoed.Only form-encoded bodies are parsed for it. Calling
ParseFormon a JSON request would consume the body the handler is about to decode — a convenience for HTML forms would have silently broken every API POST.Verified live: a form post with no token gets
403 auth: CSRF check failed: no X-CSRF-Token header or csrf_token field.One code path
The dashboard calls the same
applyPolicythe JSON API does, extracted for this. A version that cannot load is refused identically; a shadow is carried across the same way, matching the CLI. Two paths that both change what serves production traffic would be two places for the rules to drift, and the one with fewer checks becomes the way in.Smaller decisions
adminand not rendered for a read-only credential — buttons that always refuse are worse than no buttons."before":"v1=100%","after":"v1=90% v2=10%".A test I had to delete
TestDashboardIsReadOnlyasserted the pages contained no<form>— which this makes false. Rather than drop it, it is replaced by the properties that still hold: the index carries no actions, every form on the model page carries a CSRF token and uses POST, and the action routes exist only under POST so no amount of link-following changes what serves traffic.Verified live
Through a real browser session against the real binary: 3 forms each with a CSRF field, plan returning a confirmation while leaving the policy untouched, apply moving it to
v1=90% v2=10%and redirecting back, a stale apply refused with the concurrent change preserved, a token-less post refused 403, and the audit line naming the person with before and after.Coverage
89.9% across
internal/.