Skip to content

Deploy, canary, shadow and roll back from the dashboard - #17

Merged
sahilkalgutkar merged 1 commit into
mainfrom
feature/dashboard-actions
Aug 31, 2026
Merged

sahilkalgutkar merged 1 commit into
mainfrom
feature/dashboard-actions

Conversation

@sahilkalgutkar

Copy link
Copy Markdown
Owner

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:

Confirm this change to fraud-score
Send 10% of traffic to version 2, keeping 90% on version 1.

Now          After
v1=100%      v1=90% v2=10%

This changes which model answers live requests, immediately.

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:

This model changed while you were looking at it. It was "v1=100%" when the
confirmation was shown and is "v1=90% v2=10%" now, so nothing was applied.

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_token comes 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 ParseForm on 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 applyPolicy the 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

  • Forms are behind admin and not rendered for a read-only credential — buttons that always refuse are worse than no buttons.
  • Apply redirects afterwards, so a refresh does not re-apply.
  • Actions live on the model page, not the index: a stray action on a list of every model is a click away from changing the wrong one.
  • A canary percentage must be 1–99. Zero deploys nothing while looking like a canary; 100 is a full deploy wearing a canary's name. Both are better expressed by the action that means them.
  • The audit line records the effect, not just the route: "before":"v1=100%","after":"v1=90% v2=10%".

A test I had to delete

TestDashboardIsReadOnly asserted 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/.

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

codecov Bot commented Aug 31, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.02151% with 26 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/api/actions.go 86.16% 13 Missing and 9 partials ⚠️
internal/api/api.go 84.61% 1 Missing and 1 partial ⚠️
internal/auth/session.go 80.00% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@sahilkalgutkar
sahilkalgutkar merged commit 3fe35fc into main Aug 31, 2026
3 checks passed
@sahilkalgutkar
sahilkalgutkar deleted the feature/dashboard-actions branch August 31, 2026 23:59
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