Skip to content

Commit 30afec5

Browse files
authored
Skip workspace selection in auth login on account console hosts (databricks#5504)
## Why Logging in to an account console host (for example `https://accounts.cloud.databricks.com`) with an account ID prompted "Select a workspace", and silently auto-selected one when the account had exactly one workspace. These hosts only serve account-level APIs, so the stored `workspace_id` refers to a workspace the profile can never talk to, and later commands fail in confusing ways. Relates to databricks#5479. ## Changes Before, `databricks auth login --host https://accounts.cloud.databricks.com --account-id <id>` prompted for (or auto-selected) a workspace and wrote `workspace_id` into the profile. Now it skips workspace selection entirely on classic account console hosts and writes no `workspace_id` key. `shouldPromptWorkspace` returns false when the host is a classic account console host, using `auth.IsClassicAccountHost` on the canonical host name (the same check `needsAccountIDPrompt` and `ToOAuthArgument` already use). Passing `--workspace-id` explicitly (or `?w=` / `?o=` host query params) still works and is still written to the profile. SPOG and unified hosts keep prompting exactly as before. ## Test plan - [x] Extended the `shouldPromptWorkspace` unit tests: classic accounts host, accounts-dod host, host without scheme, accounts host with an explicit workspace ID, and a workspace host that still prompts. - [x] `go test ./cmd/auth/... ./libs/auth/...` passes. - [x] Existing auth acceptance tests pass unchanged (`go test ./acceptance -run TestAccept/cmd/auth`). No acceptance test was added: the harness cannot complete an OAuth challenge against an `accounts.*` host, and the workspace selection step only runs after a successful challenge. - [x] `./task fmt-q`, `./task lint-q`, and `./task checks` pass. This pull request and its description were written by Isaac.
1 parent 4821c5a commit 30afec5

3 files changed

Lines changed: 39 additions & 6 deletions

File tree

‎NEXT_CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
### CLI
99
* Added the `databricks quickstart` command, a short introduction to the CLI that prints a human-friendly guide interactively and an agent-oriented version when run non-interactively ([#5464](https://github.com/databricks/cli/pull/5464)).
10+
* `databricks auth login` no longer prompts for workspace selection when logging in to an account console host (`https://accounts.*`). Pass `--workspace-id` explicitly to store a workspace ID on such a profile ([#5504](https://github.com/databricks/cli/pull/5504)).
1011

1112
### Bundles
1213
* Set the default `data_security_mode` to `DATA_SECURITY_MODE_AUTO` in bundle templates ([#5452](https://github.com/databricks/cli/pull/5452)).

‎cmd/auth/login.go‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -410,16 +410,23 @@ a new profile is created.
410410

411411
// shouldPromptWorkspace reports whether the login flow should ask the user to
412412
// pick a workspace. We prompt when we have an account_id but no workspace_id
413-
// and the user did not pass --skip-workspace, with one exception: re-login
414-
// into an existing profile that's already account-only for the SAME account
415-
// (account_id matches and workspace_id is absent or the legacy "none"
416-
// sentinel) honors the user's prior "skip" choice instead of re-prompting on
417-
// every login. We require the account_id to match so reusing a profile name
418-
// against a different account still gets the workspace prompt.
413+
// and the user did not pass --skip-workspace, with two exceptions:
414+
// - Classic account console hosts (accounts.*) serve only account-level
415+
// APIs, so a selected workspace_id would be unusable against that host
416+
// and only misleads later commands.
417+
// - Re-login into an existing profile that's already account-only for the
418+
// SAME account (account_id matches and workspace_id is absent or the
419+
// legacy "none" sentinel) honors the user's prior "skip" choice instead
420+
// of re-prompting on every login. We require the account_id to match so
421+
// reusing a profile name against a different account still gets the
422+
// workspace prompt.
419423
func shouldPromptWorkspace(authArguments *auth.AuthArguments, existingProfile *profile.Profile, skipWorkspace bool) bool {
420424
if authArguments.AccountID == "" || authArguments.WorkspaceID != "" || skipWorkspace {
421425
return false
422426
}
427+
if auth.IsClassicAccountHost((&config.Config{Host: authArguments.Host}).CanonicalHostName()) {
428+
return false
429+
}
423430
if existingProfile != nil &&
424431
existingProfile.AccountID == authArguments.AccountID &&
425432
(existingProfile.WorkspaceID == "" || existingProfile.WorkspaceID == auth.WorkspaceIDNone) {

‎cmd/auth/login_test.go‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,31 @@ func TestShouldPromptWorkspace(t *testing.T) {
566566
authArguments: auth.AuthArguments{AccountID: "acc"},
567567
want: true,
568568
},
569+
{
570+
name: "classic account console host never prompts",
571+
authArguments: auth.AuthArguments{Host: "https://accounts.test", AccountID: "acc"},
572+
want: false,
573+
},
574+
{
575+
name: "classic account console host without scheme never prompts",
576+
authArguments: auth.AuthArguments{Host: "accounts.test", AccountID: "acc"},
577+
want: false,
578+
},
579+
{
580+
name: "accounts-dod host never prompts",
581+
authArguments: auth.AuthArguments{Host: "https://accounts-dod.test", AccountID: "acc"},
582+
want: false,
583+
},
584+
{
585+
name: "workspace host with account_id prompts",
586+
authArguments: auth.AuthArguments{Host: "https://myworkspace.test", AccountID: "acc"},
587+
want: true,
588+
},
589+
{
590+
name: "classic account console host with workspace_id set never prompts",
591+
authArguments: auth.AuthArguments{Host: "https://accounts.test", AccountID: "acc", WorkspaceID: "12345"},
592+
want: false,
593+
},
569594
{
570595
name: "re-login into legacy account-only profile (workspace_id = none)",
571596
authArguments: auth.AuthArguments{AccountID: "spog-account"},

0 commit comments

Comments
 (0)