Skip to content

Style CLI device sign-in with Violet Circuit - #1097

Merged
cwilhit merged 4 commits into
mainfrom
codex/device-login-design
Nov 14, 2026
Merged

cwilhit merged 4 commits into
mainfrom
codex/device-login-design

Conversation

@cwilhit

@cwilhit cwilhit commented Nov 14, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Give the code entry and confirmation steps a shared, standalone Violet Circuit layout with the Railgrid mark, violet primary actions, and monospaced request details.
  • Keep the account-access warning beside approval and return keyboard focus to the code field on invalid submissions.
  • Retain the CLI network prefix whenever available. Approximate location would require a verified source of ingress location data.

Verification

  • Auth package tests, Go lint, and UI conformance passed.
  • Chromium fixtures from the Go handlers covered entry, confirmation, and invalid-code states at 320, 768, and 1280 pixels, including keyboard focus and 44-pixel controls.
  • The updated screens have not been exercised on the deployed hub.

@cwilhit
cwilhit requested a review from mjudeikis as a code owner November 14, 2026 19:36
@railgrid-prow

railgrid-prow Bot commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign cwilhit for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@cwilhit

cwilhit commented Nov 14, 2026

Copy link
Copy Markdown
Collaborator Author

@mjudeikis-bot review

@mjudeikis mjudeikis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 showDeviceApproval all return false, so the HandleCallback defer records server_error. One misleading error message, below.
  • Concurrency: decideDeviceLogin does 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. seedUser and lookupDefaultCluster are the existing calls.
  • Provider contract: not applicable. No provider, manifest or SDK change.
  • API, codegen and storage: the only addition is PathAuthDeviceApprove and the new approval: store prefix. Entries last at most ExpiresAt, so there is no stored-format compatibility concern. No apis/ change, so no codegen.
  • Security: the approval route sits behind CrossOriginProtection and deviceLimiter. 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. The html/template fields 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 TestDeviceLoginAcrossHubReplicas covers unbound-cookie rejection, replay (410), decline, plaintext-at-rest and approval-write failure. Not covered: the TokenExpiresAt expiry branch and the ExpiresAt branch in showDeviceApproval.

Checked

  • Read beyond the diff: deviceBrowserCookie, deviceBrowserHeaders, takeDeviceBrowserState, recordDeviceLoginFailure, storeDeviceResult, and the HandleCallback device branch in handler.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-contract and verify-portalkit, because no apis/, 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.

Comment thread pkg/server/auth/device_approval.go Outdated
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")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
}

Comment thread pkg/server/auth/device.go
load = h.deviceStore.Take
}
payload, err := load(r.Context(), "user:"+code)
payload, err := h.deviceStore.Take(r.Context(), "user:"+code)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@cwilhit
cwilhit merged commit 861e32a into main Nov 14, 2026
1 of 17 checks passed
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.

2 participants