Repository navigation
Support device code login for account and unified hosts - #7710
Conversation
Device code login is now enabled on the server for account and unified (SPOG) hosts, so remove the checks that limited it to workspace hosts. Classic account hosts build their OAuth endpoints without fetching the OIDC discovery document, so device code login fetches it to find the device authorization endpoint. Co-authored-by: Isaac <no-reply@databricks.com>
|
Commit: Regression test reportSelected 4 changed tests (limit=20, 0 not selected) 4 tests: regression=3 unreleased=0 coverage=1 failing=0
TestAccept/cmd/auth/login/device-code/non-interactive/errors: branch ✅ | main (9175b8f) ❌ | latest (v1.26.0) ❌main (9175b8f): latest (v1.26.0): TestAccept/cmd/auth/login/device-code/unified-host: branch ✅ | main (9175b8f) ❌ | latest (v1.26.0) ❌main (9175b8f): latest (v1.26.0): same output as main (9175b8f) TestAccept/cmd/auth/login/device-code/unsupported-host: branch ✅ | main (9175b8f) ❌ | latest (v1.26.0) ❌main (9175b8f): latest (v1.26.0): same output as main (9175b8f) |
✅ Integration test reportCommit: 7bde7ae
Top 11 slowest tests (at least 2 minutes):
|
No remaining flag needs the comparison with the default, which was added for --skip-workspace. Co-authored-by: Isaac <no-reply@databricks.com>
The filter missed the account-scoped device authorization path. Co-authored-by: Isaac <no-reply@databricks.com>
testserver.New registered the default /.well-known/databricks-config handler before any test stub, and the router keeps the first registration, so test.toml overrides of that path were ignored. Register it as a fallback that serves only requests no other handler matches. Co-authored-by: Isaac <no-reply@databricks.com>
The fake server's default host metadata has a workspace ID, so the account login saved one and never reached the account-level path. Serve unified host metadata without it. Co-authored-by: Isaac <no-reply@databricks.com>
The token endpoint of account and unified hosts depends on the account ID, so a pending login started for one account would send its device code to another account's token endpoint. Store the account ID with the pending login and reject a completion with a different one, like a different host. Co-authored-by: Isaac <no-reply@databricks.com>
simonfaltum
left a comment
There was a problem hiding this comment.
🤖 Automated review from simonfaltum's review agent (pr-review skill) at 3a2bb24. Each finding was verified against the code; simonfaltum may follow up.
No blocking issues found, approving. 8 non-blocking comment(s) and 2 question(s) below.
This PR lets auth login --use-device-code work with account and unified hosts. It fetches the account OIDC discovery document for classic account hosts and also checks the account ID when completing a non-interactive login. The core logic looks right and CI is green: the OAuth argument type checks don't overlap, and pending logins saved by earlier versions stay compatible. Nothing blocks the merge. The main suggestions are a unit test for the account-ID branch, and keeping the completion step from opening the workspace picker when it runs in a terminal. The rest are doc and comment nits, plus two non-blocking questions about the test-server fallback and the classic-account endpoints.
Questions
HandleFallbackexists so that per-test[[Server]]stubs can override the default/.well-known/databricks-config..agents/rules/testing.mdasks to model behavior inlibs/testserver/and to keep[[Server]]for routes the test server doesn't model. The change also makes the existing stub inacceptance/cmd/auth/profiles/spog-account/test.tomltake effect for the first time; until now the default registered intestserver.Newshadowed it. That test's output didn't change, but it now runs as a SPOG host. Would you rather make unified-host metadata a test server option, note the side effect in the description, or move the router change to its own PR? (non-blocking)- For classic account hosts,
deviceCodeConfigfetches the account discovery document but takes onlydevice_authorization_endpointfrom it, and keeps the token URL built byGetAccountOAuthEndpoints. The unified path uses the fetched document for every endpoint. Would it be simpler and more consistent to build the device code config from the fetched document's endpoints for classic accounts too? (non-blocking)
Accepted answers
- Why re-merge setHost/setAccountID into setHostAndAccountId
Comments outside the changed lines
- [nice to have]
cmd/auth/login.go:492:--confirmation-codesetsnonInteractive, but after the token exchangeshouldPromptWorkspace→promptForWorkspaceSelectionchecks onlyIsPromptSupported. Now that account and unified hosts are allowed, an account-level login (--host "https://<spog>?a=<id>") completed in a terminal (as in the docs, where only step 1 uses< /dev/null) calls the workspaces API and blocks on a picker. Without a TTY, the same step only prints a hint.setHostAndAccountIdcan likewise prompt for the account ID in step 2. Consider skipping the workspace picker whennonInteractive(print the hint instead), the same way--configure-clusteris rejected for this mode. - [nit]
docs/device-code-login.md:140: This row (... was started with a different host (or client ID, or scopes)) and thecmd/auth/README.md:154-157paragraph ("The second step also checks the host, client ID and scopes...") both predate the new account ID check inchangedSetting. A user who completes an account or unified-host login with a different?a=or--account-idgets an error neither one lists. Add the account ID to both. - [nit]
docs/device-code-login.md:134: "the workspace then discards the login" (line 132) and "in this workspace" (line 134) now apply to accounts too. Also, "Each profile, or host without a profile, has one pending login" (line 108) is now per host and account for account or unified hosts without a profile, because the key is<host>/oidc/accounts/<id>. Reword these lines. - [nit]
libs/testserver/router.go:32: The type doc still says AddDefaultHandlers "installs fallback handlers that any test stub for the same pattern can override" (first-wins).HandleFallbackadds a second "fallback" with different precedence: it loses to any exact or wildcard route, whatever the registration order. MentionHandleFallbackin the type doc, and say when to use which.
Co-authored-by: Isaac <no-reply@databricks.com>
…lier Co-authored-by: Isaac <no-reply@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
The second step of a device code login can run in a terminal. For an account-level login on a unified host it then listed the workspaces and waited on a picker, although the non-interactive login never prompts. Co-authored-by: Isaac <no-reply@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
|
Thanks for the review! Q1. Good catch on Q2. On the classic-account endpoints: agreed that using the fetched document would be more consistent with unified hosts. Browser login and token refresh build these endpoints with |
Changes
auth login --use-device-codeto workspace hosts: account and unified (SPOG) hosts are no longer rejected,--skip-workspacecan be combined with--use-device-code, and the profile picker lists account profiles again.setHostAndAccountIdis merged back into one function, since it was only split to fit the host check in./oidc/accounts/<account-id>/.well-known/oauth-authorization-serverto finddevice_authorization_endpoint. Unified hosts already fetch it.device code login is not enabled for this workspacebecomes... for this host, and--use-device-code requires a workspace hostbecomes... requires a host.docs/device-code-login.mdandcmd/auth/README.md.Why
The server now supports device code login for account and unified hosts. It is opt-in per account, and so far only in dev and staging.
Tests
libs/testserverserves account-scoped OIDC routes. A newdevice-code/unified-hostacceptance test covers an account-level and a workspace-level login on a unified host, and checks that a login started for one account cannot be completed for another.unsupported-hostcovers an account without device code login.This pull request and its description were written by Isaac.