Skip to content

feat(auth): initiate CLI login and seal cli_login ticket cookie - #1348

Merged
VLukiantsev merged 4 commits into
fix/login-identity-verificationfrom
feat/cli-login-initiation
Oct 21, 2026
Merged

VLukiantsev merged 4 commits into
fix/login-identity-verificationfrom
feat/cli-login-initiation

Conversation

@VLukiantsev

@VLukiantsev VLukiantsev commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Introduces the GET /api/cli/login initiation endpoint on the experiment state server and seals the pending CLI login state into a signed cli_login cookie (aud: xmanager-cloud-cli-login) bound to the oauth_state of the OIDC round trip, then redirects the browser to the identity provider.

Motivation & Context

xmanager login signs the user in through the browser using the existing Dashboard OAuth client and /api/callback redirect URI (google/xmc#1309). Splitting the authorization initiation (GET /api/cli/login) from the callback completion (GET /api/callback and CliLoginCodes persistence) keeps each vertical slice focused and under the repository diff size thresholds with zero dead code.

Key Changes

  • pkg/auth/oauth2/cli_login.go: Implements Authenticator.EnableCLILogin() and Authenticator.HandleCLILogin, validating port (1024..65535), state, S256 code_challenge, code_challenge_method=S256, and optional printable-ASCII login_hint, while enforcing Sec-Fetch-Dest: document and Sec-Fetch-Site: none when fetch metadata headers are present.
  • pkg/auth/oauth2/cli_login_ticket.go: Implements cliLoginTicket, hashOAuthState, and sealCLILoginTicket (sealSigned) to issue HS256-signed cli_login cookies scoped to /api/callback.
  • pkg/auth/oauth2/handlers.go & provider.go: Clears any stale cli_login cookie on Dashboard /api/login requests and forwards optional oauth2.AuthCodeOption parameters (login_hint) through OAuthProvider.AuthCodeURL.
  • cmd/experiment_state_server/cli_login.go & main.go: Registers /api/cli/login on the HTTP mux only when production authentication (!MockAuth && !DisableAuthentication) and a Cloud Spanner client are configured.

Assumptions

None — requirements were fully specified.

Verification & Testing

  • Commands Executed: bazel test --test_env=SPANNER_EMULATOR_HOST=localhost:9010 //cmd/experiment_state_server/... //pkg/auth/oauth2/... and ./.githooks/pre-commit
  • Coverage & Test Status: All unit and Spanner emulator tests in //cmd/experiment_state_server:cli_login_test and //pkg/auth/oauth2:oauth2_test pass, covering parameter validation, Sec-Fetch-* CSRF/embedding rejections, login_hint forwarding, signed cli_login ticket cookie attributes, and /api/login stale cookie deletion.

Related Issues / Bugs

Part of #1309

TAG=agy
CONV=6dd806a4-f14e-436b-bef8-6b53e044b43c

Register `GET /api/cli/login` on the experiment state server when production
authentication and Cloud Spanner are enabled. Validate the loopback port,
OAuth state, S256 PKCE challenge, and optional `login_hint`, enforce
`Sec-Fetch-Dest: document` and `Sec-Fetch-Site: none`, seal the pending
login ticket cookie (`aud: xmanager-cloud-cli-login`) bound to `oauth_state`,
clear any stale `cli_login` cookie on `/api/login`, and redirect to the OIDC
provider.

Fixes #1309

TAG=agy
CONV=6dd806a4-f14e-436b-bef8-6b53e044b43c
@VLukiantsev
VLukiantsev added this pull request to stack #1349 October 21, 2026 07:29

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request implements the backend support for browser-based CLI login (xmc login). It introduces a new endpoint /api/cli/login that initiates the OAuth flow for the CLI, utilizing PKCE and storing state in a signed cli_login cookie. The endpoints are registered only under production authentication when a Spanner client is available. Security measures such as fetch metadata checks (Sec-Fetch-Site and Sec-Fetch-Dest) are implemented to prevent CSRF. I have no feedback to provide as there are no review comments.

@VLukiantsev
VLukiantsev marked this pull request as ready for review October 21, 2026 07:36
@github-actions
github-actions Bot requested a review from andrzejfudro October 21, 2026 07:36
@VLukiantsev
VLukiantsev removed this pull request from stack #1349 October 21, 2026 07:54
@VLukiantsev
VLukiantsev added this pull request to stack #1350 October 21, 2026 07:54
andrzejfudro
andrzejfudro previously approved these changes Oct 21, 2026

@andrzejfudro andrzejfudro left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM but please drop the explciit spannerClient and replace it with storage DI (either in this PR or in the follow up). There is also an AI suggestion that can be done in the follow up.

Comment thread pkg/auth/oauth2/cli_login.go Resolved
…itiation slice

Drop `*spanner.Client` from `registerCLILogin` in the initiation slice (`#1348`)
since login ticket initiation does not persist `CliLoginCodes` yet (and `#1314`
injects `storage.Storage` instead of `*spanner.Client`). Also clarify the
`Sec-Fetch-Site: none` threat-model scope in `docs/design/gateway.md` and
`deploy/helm/README.md`.

Comment link: #1348 (comment)
Comment link: #1348 (comment)

TAG=agy
CONV=6dd806a4-f14e-436b-bef8-6b53e044b43c
github-actions[bot]
github-actions Bot previously approved these changes Oct 21, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🤖 Incremental PR Approval

PR author is a code owner and changes since last approval (28 lines, excluding 36 test file lines) are within the 50-line grace delta.

Preserving prior approval by @andrzejfudro on commit 3a4ae4f.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🤖 Incremental PR Approval

PR author is a code owner and changes since last approval (32 lines, excluding 36 test file lines) are within the 50-line grace delta.

Preserving prior approval by @andrzejfudro on commit 3a4ae4f.

@VLukiantsev
VLukiantsev added this pull request to the merge queue Oct 21, 2026
Merged via the queue into main with commit eddbd06 Oct 21, 2026
14 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