Skip to content

Commit 79702a7

Browse files
yolocsIsaac
andcommitted
Allow auth docker configure when profiles share a workspace
auth docker configure now prints a warning instead of failing when several databricks-cli profiles match the workspace. auth docker token uses the first logged-in matching profile, skipping only profiles with no cached login or a rejected refresh token; any other error is returned so the helper never switches identity on a transient failure. Co-authored-by: Isaac <no-reply@databricks.com>
1 parent c461a8f commit 79702a7

16 files changed

Lines changed: 316 additions & 129 deletions

File tree

‎.nextchanges/cli/docker-duplicate-profile-hint.md‎

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* Allow `databricks auth docker configure` when multiple profiles match the same workspace. It now prints a warning, and the Docker credential helper uses the first logged-in profile, checking `[DEFAULT]` first and then the others in `.databrickscfg` order. ([#7383](https://github.com/databricks/cli/pull/7383))

‎acceptance/cmd/auth/docker/configure-errors/output.txt‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,5 @@ Error: profile "m2m" uses client credentials. Docker credential helper requires
4545
>>> musterr [CLI] auth docker configure blank-auth
4646
Error: profile "blank-auth" uses auth_type "". Docker credential helper requires a profile created by databricks auth login
4747

48-
=== Another profile already maps to the workspace
49-
50-
>>> musterr [CLI] auth docker configure docker-test
51-
Error: multiple Databricks profiles match workspace ID [WORKSPACE_ID]: duplicate and docker-test. Docker credential helper requires exactly one profile per workspace. Remove the duplicate profile with: databricks auth logout --profile <profile-name> --delete
52-
5348
=== Nothing changed
5449
Docker config not created; profiles unchanged

‎acceptance/cmd/auth/docker/configure-errors/script‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ cat >> "$HOME/.databrickscfg" <<ENDCFG
1111
host = https://workspace.example.test
1212
auth_type = databricks-cli
1313

14-
[duplicate]
15-
host = $DATABRICKS_HOST_ORIG
16-
auth_type = databricks-cli
17-
workspace_id = 900800700600
18-
1914
[pat]
2015
host = $DATABRICKS_HOST_ORIG
2116
auth_type = pat
@@ -54,9 +49,6 @@ trace musterr $CLI auth docker configure pat
5449
trace musterr $CLI auth docker configure m2m
5550
trace musterr $CLI auth docker configure blank-auth
5651

57-
title "Another profile already maps to the workspace\n"
58-
trace musterr $CLI auth docker configure docker-test
59-
6052
title "Nothing changed\n"
6153
assert_not_exists.py "$DOCKER_CONFIG/config.json"
6254
cmp "$HOME/databrickscfg.before" "$HOME/.databrickscfg"

‎acceptance/cmd/auth/docker/configure/output.txt‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,28 @@ Warning: ensure [TEST_TMP_DIR]/home/bin is on PATH before any other docker-crede
154154
"method": "GET",
155155
"path": "/api/2.1/unity-catalog/metastore_summary"
156156
}
157+
158+
=== Profiles sharing the workspace
159+
160+
>>> databricks auth docker configure docker-test
161+
Warning: multiple Databricks profiles match workspace ID [WORKSPACE_ID]: docker-test, shared. Docker credential helper uses the first logged-in profile in this order
162+
Configured Docker credential helper for [WORKSPACE_ID].container.us-west-2.localhost
163+
Updated Docker config: [TEST_TMP_DIR]/home/docker/config.json
164+
Installed Docker credential helper: [TEST_TMP_DIR]/home/bin/docker-credential-databricks
165+
166+
>>> print_requests.py --get //api
167+
{
168+
"headers": {
169+
"X-Databricks-Workspace-Id": [
170+
"[WORKSPACE_ID]"
171+
]
172+
},
173+
"method": "GET",
174+
"path": "/api/2.1/unity-catalog/metastore_summary"
175+
}
176+
177+
>>> docker-credential-databricks get
178+
{
179+
"Secret": "oauth-token",
180+
"Username": "oauthtoken"
181+
}

‎acceptance/cmd/auth/docker/configure/script‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,15 @@ trace print_requests.py --get //api
6363
title "Configure with the installation directory absent from PATH\n"
6464
PATH="$path_without_cli" trace command "$HOME/bin/databricks" auth docker configure docker-test
6565
trace print_requests.py --get //api
66+
67+
title "Profiles sharing the workspace\n"
68+
cat >> "$HOME/.databrickscfg" <<ENDCFG
69+
70+
[shared]
71+
host = $DATABRICKS_HOST_ORIG
72+
auth_type = databricks-cli
73+
workspace_id = 900800700600
74+
ENDCFG
75+
trace databricks auth docker configure docker-test
76+
trace print_requests.py --get //api
77+
printf '%s\n' "$registry_host" | trace docker-credential-databricks get | jq -S .

‎acceptance/cmd/auth/docker/help/output.txt‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,13 @@ Use "databricks auth docker [command] --help" for more information about a comma
6565
This command installs docker-credential-databricks and configures Docker to use
6666
it for the selected workspace's Artifact Registry host. If the selected profile
6767
does not already include a workspace_id, the command resolves and saves it so
68-
the Docker helper can map the registry host back to the profile. The registry
69-
region is inferred from the workspace's metastore. Select the workspace with
70-
[PROFILE] or --profile; --host, --account-id, and --workspace-id are not
71-
supported. The deprecated --region flag is retained for compatibility; omit it
72-
because it will be fully removed in the next release.
68+
the Docker helper can map the registry host back to the profile. If several
69+
profiles match the workspace, the helper uses the first logged-in one, checking
70+
[DEFAULT] first and then the others in file order. The registry region is
71+
inferred from the workspace's metastore. Select the workspace with [PROFILE] or
72+
--profile; --host, --account-id, and --workspace-id are not supported. The
73+
deprecated --region flag is retained for compatibility; omit it because it will
74+
be fully removed in the next release.
7375

7476
Usage:
7577
databricks auth docker configure [PROFILE] [flags]

‎acceptance/cmd/auth/docker/token/output.txt‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,25 @@ Error: auth docker token does not support --workspace-id
5151
>>> musterr [CLI] auth docker token
5252
Error: no Databricks profile found for workspace ID 444555666 from registry host 444555666.container.us-west-2.localhost. Run databricks auth login --host <workspace-url> and set workspace_id for that profile
5353

54-
=== Multiple profiles for the workspace
54+
=== Multiple profiles for the workspace use the first logged-in profile
55+
56+
>>> [CLI] auth docker token --no-force-refresh
57+
{
58+
"Secret": "docker-test-access-token",
59+
"Username": "oauthtoken"
60+
}
61+
62+
=== Profiles that are not logged in are skipped
63+
64+
>>> [CLI] auth docker token
65+
{
66+
"Secret": "oauth-token",
67+
"Username": "oauthtoken"
68+
}
69+
70+
=== No logged-in profile for the workspace
5571

5672
>>> musterr [CLI] auth docker token
57-
Error: multiple Databricks profiles match workspace ID [WORKSPACE_ID]: docker-test and duplicate. Docker credential helper requires exactly one profile per workspace. Remove the duplicate profile with: databricks auth logout --profile <profile-name> --delete
73+
Error: no logged-in Databricks profile for workspace ID 555666777 from registry host 555666777.container.us-west-2.localhost. Run databricks auth login --profile <profile-name> for one of these profiles:
74+
profile "logged-out-a": cache: databricks OAuth is not configured for this host. no cached credentials; run `databricks auth login` to sign in
75+
profile "logged-out-b": cache: databricks OAuth is not configured for this host. no cached credentials; run `databricks auth login` to sign in

‎acceptance/cmd/auth/docker/token/script‎

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,39 @@ workspace_id = 444555666
3737
ENDCFG
3838
printf '%s\n' "444555666.container.us-west-2.localhost" | trace musterr $CLI auth docker token
3939

40-
title "Multiple profiles for the workspace\n"
40+
title "Multiple profiles for the workspace use the first logged-in profile\n"
4141
cat >> "$HOME/.databrickscfg" <<ENDCFG
4242

4343
[duplicate]
4444
host = $DATABRICKS_HOST_ORIG
4545
auth_type = databricks-cli
4646
workspace_id = 900800700600
4747
ENDCFG
48-
printf '%s\n' "$registry_host" | trace musterr $CLI auth docker token
48+
cp token-cache.json "$HOME/.databricks/token-cache.json"
49+
printf '%s\n' "$registry_host" | trace $CLI auth docker token --no-force-refresh | jq -S .
50+
51+
title "Profiles that are not logged in are skipped\n"
52+
cat - "$HOME/.databrickscfg" > "$HOME/databrickscfg.new" <<ENDCFG
53+
[logged-out]
54+
host = $DATABRICKS_HOST_ORIG
55+
auth_type = databricks-cli
56+
workspace_id = 900800700600
57+
58+
ENDCFG
59+
mv "$HOME/databrickscfg.new" "$HOME/.databrickscfg"
60+
printf '%s\n' "$registry_host" | trace $CLI auth docker token | jq -S .
61+
62+
title "No logged-in profile for the workspace\n"
63+
cat >> "$HOME/.databrickscfg" <<ENDCFG
64+
65+
[logged-out-a]
66+
host = $DATABRICKS_HOST_ORIG
67+
auth_type = databricks-cli
68+
workspace_id = 555666777
69+
70+
[logged-out-b]
71+
host = $DATABRICKS_HOST_ORIG
72+
auth_type = databricks-cli
73+
workspace_id = 555666777
74+
ENDCFG
75+
printf '%s\n' "555666777.container.us-west-2.localhost" | trace musterr $CLI auth docker token
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"version": 1,
3+
"tokens": {
4+
"docker-test": {
5+
"access_token": "docker-test-access-token",
6+
"token_type": "Bearer",
7+
"refresh_token": "docker-test-refresh-token",
8+
"expiry": "2099-01-01T00:00:00Z"
9+
},
10+
"duplicate": {
11+
"access_token": "duplicate-access-token",
12+
"token_type": "Bearer",
13+
"refresh_token": "duplicate-refresh-token",
14+
"expiry": "2099-01-01T00:00:00Z"
15+
}
16+
}
17+
}

0 commit comments

Comments
 (0)