Repository navigation
Style CLI device sign-in with Violet Circuit - #1097
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
@mjudeikis-bot review |
mjudeikis
left a comment
There was a problem hiding this comment.
Two Notes, no Critical or Warning. The approval flow holds up: ownership is checked before the atomic Take, the pending approval (tokens included) is stored only as ciphertext, and the key never leaves the HttpOnly __Host- cookie. Credentials are minted only after Take succeeds, and seedUser now runs on approval instead of before it.
Hunt outcomes
- Correctness: the expired-device-request and store-failure branches in
showDeviceApprovalall return false, so theHandleCallbackdefer recordsserver_error. One misleading error message, below. - Concurrency:
decideDeviceLogindoes Get, Open, then an atomic Take. Two replicas can both decrypt, but only the Take winner issues a result. Not applicable: no new goroutines or locks. - Tenancy and kcp: not applicable. No kcp client or lister is touched.
seedUserandlookupDefaultClusterare the existing calls. - Provider contract: not applicable. No provider, manifest or SDK change.
- API, codegen and storage: the only addition is
PathAuthDeviceApproveand the newapproval:store prefix. Entries last at mostExpiresAt, so there is no stored-format compatibility concern. Noapis/change, so no codegen. - Security: the approval route sits behind
CrossOriginProtectionanddeviceLimiter. The cookie is Secure, HttpOnly and SameSite=Lax. The CSP is unchanged (default-src 'none'; style-src 'unsafe-inline'), and the inline style and SVG are compatible with it. Thehtml/templatefields are auto-escaped. No credential reaches the browser; the test asserts the body contains no refresh token. - Portal: not applicable. The pages are Go-served standalone HTML. I could not render them. The PR body's fixtures cover 320, 768 and 1280 px, and I did not check them.
- Tests: the rewritten
TestDeviceLoginAcrossHubReplicascovers unbound-cookie rejection, replay (410), decline, plaintext-at-rest and approval-write failure. Not covered: theTokenExpiresAtexpiry branch and theExpiresAtbranch inshowDeviceApproval.
Checked
- Read beyond the diff:
deviceBrowserCookie,deviceBrowserHeaders,takeDeviceBrowserState,recordDeviceLoginFailure,storeDeviceResult, and theHandleCallbackdevice branch inhandler.go. Also read the test store fake (failNextWritePrefix) and a grep of docs and code for stale references to the old confirmation page (none found). go build ./pkg/...: ok.go vet ./pkg/server/auth/: clean.go test -count=1 ./pkg/server/auth/: ok.make lint: 0 issues.make verify-boilerplate: ok.- Not run:
make verify-codegen,verify-provider-contractandverify-portalkit, because noapis/, provider or portalkit files changed. - e2e: not run. The runner has no kcp or OIDC stack, and the change is covered by the handler-level multi-replica test.
- Not verified: the rendered pages (no browser here) and the deployed hub, which the PR body also says was not exercised.
| func (h *Handler) approvedDeviceCredentials(r *http.Request, approval deviceApproval) (tenancyv1alpha1.LoginResponse, error) { | ||
| var resp tenancyv1alpha1.LoginResponse | ||
| if time.Now().Unix() >= approval.TokenExpiresAt { | ||
| return resp, fmt.Errorf("verified device identity has expired") |
There was a problem hiding this comment.
Note: An expired ID token is reported as "CLI sign-in unavailable"
The approval page can sit open for longer than the IdP's ID-token lifetime, which is often 5 to 10 minutes. Approving then hits this error. The handler renders the 503 "CLI sign-in unavailable" page (via deviceBrowserUnavailable at line 145) and records server_error. The operator is pointed at a store outage when the real cause is a stale identity. No test covers this branch. Return a sentinel and render a 410 with "Sign-in took too long. Start a new sign-in from the terminal." in that case.
var errDeviceIdentityExpired = errors.New("verified device identity has expired")
// in approvedDeviceCredentials:
return resp, errDeviceIdentityExpired
// in decideDeviceLogin:
if errors.Is(err, errDeviceIdentityExpired) {
http.Error(w, "Sign-in took too long. Start a new sign-in from the terminal.", http.StatusGone)
} else {
h.deviceBrowserUnavailable(w, err)
}| load = h.deviceStore.Take | ||
| } | ||
| payload, err := load(r.Context(), "user:"+code) | ||
| payload, err := h.deviceStore.Take(r.Context(), "user:"+code) |
There was a problem hiding this comment.
Note: Entering a valid code now consumes it before any sign-in or approval
The old flow used Get on the preview and Take only at confirmation. This Take runs on entry, so a valid code is burned as soon as it is typed. If the user closes the tab at the IdP, or the callback fails, the CLI gets no result for that code and the user must restart railgrid login --device. Anyone who learns a live code can also burn it by entering it. This is probably acceptable, because the bound OIDC state still prevents hijack. It is a behaviour change the PR body and docs/security.md don't mention, so say so there. Alternatively keep Get here and Take when the OIDC state is created.
Summary
Verification