Skip to content

Commit bf6c3da

Browse files
Fix auth logout failing to clear token for workspace profiles with stale account_id
logout derived the token-cache key by checking whether `account_id` was set on the profile, but a workspace profile can carry a stale `account_id` from an earlier account-level login. This caused logout to build an account-style cache key (`host/oidc/accounts/<id>`) that did not match the workspace-style key the SDK actually wrote, so the cached token was never deleted. Use `config.HostType()` instead to decide the cache-key shape, which matches the SDK's own OAuth routing logic and correctly treats workspace hosts as workspace profiles regardless of leftover account metadata. Co-authored-by: Isaac
1 parent d062420 commit bf6c3da

File tree

15 files changed

+313
-47
lines changed

15 files changed

+313
-47
lines changed

acceptance/cmd/auth/logout/default-profile/out.databrickscfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33

44
; Dev workspace
55
[dev]
6-
host = https://dev.cloud.databricks.com
6+
host = [DATABRICKS_URL]
77
auth_type = databricks-cli

acceptance/cmd/auth/logout/default-profile/output.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
=== Initial config
33
; The profile defined in the DEFAULT section is to be used as a fallback when no profile is explicitly specified.
44
[DEFAULT]
5-
host = https://default.cloud.databricks.com
5+
host = [DATABRICKS_URL]
66
auth_type = databricks-cli
77

88
; Dev workspace
99
[dev]
10-
host = https://dev.cloud.databricks.com
10+
host = [DATABRICKS_URL]
1111
auth_type = databricks-cli
1212

1313
=== Delete the DEFAULT profile
@@ -23,5 +23,5 @@ OK: Backup file exists
2323

2424
; Dev workspace
2525
[dev]
26-
host = https://dev.cloud.databricks.com
26+
host = [DATABRICKS_URL]
2727
auth_type = databricks-cli

acceptance/cmd/auth/logout/default-profile/script

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
sethome "./home"
22

3-
cat > "./home/.databrickscfg" <<'EOF'
3+
cat > "./home/.databrickscfg" <<EOF
44
; The profile defined in the DEFAULT section is to be used as a fallback when no profile is explicitly specified.
55
[DEFAULT]
6-
host = https://default.cloud.databricks.com
6+
host = ${DATABRICKS_HOST}
77
auth_type = databricks-cli
88

99
; Dev workspace
1010
[dev]
11-
host = https://dev.cloud.databricks.com
11+
host = ${DATABRICKS_HOST}
1212
auth_type = databricks-cli
1313
EOF
1414

acceptance/cmd/auth/logout/last-non-default/output.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
; The only non-default profile
77
[only-profile]
8-
host = https://only.cloud.databricks.com
8+
host = [DATABRICKS_URL]
99
auth_type = databricks-cli
1010

1111
=== Delete the only non-default profile

acceptance/cmd/auth/logout/last-non-default/script

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
sethome "./home"
22

3-
cat > "./home/.databrickscfg" <<'EOF'
3+
cat > "./home/.databrickscfg" <<EOF
44
; The profile defined in the DEFAULT section is to be used as a fallback when no profile is explicitly specified.
55
[DEFAULT]
66

77
; The only non-default profile
88
[only-profile]
9-
host = https://only.cloud.databricks.com
9+
host = ${DATABRICKS_HOST}
1010
auth_type = databricks-cli
1111
EOF
1212

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
; The profile defined in the DEFAULT section is to be used as a fallback when no profile is explicitly specified.
22
[DEFAULT]
3-
host = https://default.cloud.databricks.com
3+
host = [DATABRICKS_URL]
44
auth_type = databricks-cli
55

66
; Second workspace — beta
77
[beta]
8-
host = https://beta.cloud.databricks.com
8+
host = [DATABRICKS_URL]
99
auth_type = databricks-cli

acceptance/cmd/auth/logout/ordering-preserved/output.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
=== Initial config
33
; The profile defined in the DEFAULT section is to be used as a fallback when no profile is explicitly specified.
44
[DEFAULT]
5-
host = https://default.cloud.databricks.com
5+
host = [DATABRICKS_URL]
66
auth_type = databricks-cli
77

88
; First workspace — alpha
99
[alpha]
10-
host = https://alpha.cloud.databricks.com
10+
host = [DATABRICKS_URL]
1111
auth_type = databricks-cli
1212

1313
; Second workspace — beta
1414
[beta]
15-
host = https://beta.cloud.databricks.com
15+
host = [DATABRICKS_URL]
1616
auth_type = databricks-cli
1717

1818
; Third workspace — gamma
@@ -31,12 +31,12 @@ OK: Backup file exists
3131
=== Config after deleting alpha
3232
; The profile defined in the DEFAULT section is to be used as a fallback when no profile is explicitly specified.
3333
[DEFAULT]
34-
host = https://default.cloud.databricks.com
34+
host = [DATABRICKS_URL]
3535
auth_type = databricks-cli
3636

3737
; Second workspace — beta
3838
[beta]
39-
host = https://beta.cloud.databricks.com
39+
host = [DATABRICKS_URL]
4040
auth_type = databricks-cli
4141

4242
; Third workspace — gamma
@@ -52,10 +52,10 @@ Logged out of and deleted profile "gamma".
5252
=== Config after deleting gamma
5353
; The profile defined in the DEFAULT section is to be used as a fallback when no profile is explicitly specified.
5454
[DEFAULT]
55-
host = https://default.cloud.databricks.com
55+
host = [DATABRICKS_URL]
5656
auth_type = databricks-cli
5757

5858
; Second workspace — beta
5959
[beta]
60-
host = https://beta.cloud.databricks.com
60+
host = [DATABRICKS_URL]
6161
auth_type = databricks-cli

acceptance/cmd/auth/logout/ordering-preserved/script

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
sethome "./home"
22

3-
cat > "./home/.databrickscfg" <<'EOF'
3+
cat > "./home/.databrickscfg" <<EOF
44
; The profile defined in the DEFAULT section is to be used as a fallback when no profile is explicitly specified.
55
[DEFAULT]
6-
host = https://default.cloud.databricks.com
6+
host = ${DATABRICKS_HOST}
77
auth_type = databricks-cli
88

99
; First workspace — alpha
1010
[alpha]
11-
host = https://alpha.cloud.databricks.com
11+
host = ${DATABRICKS_HOST}
1212
auth_type = databricks-cli
1313

1414
; Second workspace — beta
1515
[beta]
16-
host = https://beta.cloud.databricks.com
16+
host = ${DATABRICKS_HOST}
1717
auth_type = databricks-cli
1818

1919
; Third workspace — gamma

acceptance/cmd/auth/logout/stale-account-id-workspace-host/out.test.toml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
=== Profiles before logout — logfood should be valid
3+
4+
>>> [CLI] auth profiles
5+
Name Host Valid
6+
logfood (Default) [DATABRICKS_URL] YES
7+
8+
=== Token cache keys before logout
9+
[
10+
"[DATABRICKS_URL]",
11+
"logfood"
12+
]
13+
14+
=== Logout without --delete
15+
>>> [CLI] auth logout --profile logfood --force
16+
Logged out of profile "logfood". Use --delete to also remove it from the config file.
17+
18+
=== Config after logout — profile should still exist
19+
; The profile defined in the DEFAULT section is to be used as a fallback when no profile is explicitly specified.
20+
[DEFAULT]
21+
22+
[logfood]
23+
host = [DATABRICKS_URL]
24+
account_id = stale-account
25+
auth_type = databricks-cli
26+
27+
[__settings__]
28+
default_profile = logfood
29+
30+
=== Token cache keys after logout — both entries should be removed
31+
[]
32+
33+
=== Profiles after logout — logfood should be invalid
34+
35+
>>> [CLI] auth profiles
36+
Name Host Valid
37+
logfood (Default) [DATABRICKS_URL] NO
38+
39+
=== Logged out profile should no longer return a token
40+
41+
>>> musterr [CLI] auth token --profile logfood
42+
Error: cache: databricks OAuth is not configured for this host. Try logging in again with `databricks auth login --profile logfood` before retrying. If this fails, please report this issue to the Databricks CLI maintainers at https://github.com/databricks/cli/issues/new

0 commit comments

Comments
 (0)