Skip to content

Commit 3a91fa6

Browse files
yolocsIsaac
andcommitted
Infer Docker registry host from workspace profile
Co-authored-by: Isaac <[email protected]>
1 parent 76872b5 commit 3a91fa6

38 files changed

Lines changed: 1250 additions & 284 deletions
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* Deprecate `--region` in `databricks auth docker configure` ahead of its removal in the next release, infer the Artifact Registry region when it is omitted, and add `databricks auth docker host --profile <name>` to show the profile's registry host and credential-helper status. ([#6782](https://github.com/databricks/cli/pull/6782))

‎acceptance/cmd/auth/docker/configure-errors/out.test.toml‎

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
=== Unsupported flag
3+
4+
>>> musterr [CLI] auth docker configure docker-test --workspace-id [NUMID]
5+
Error: --workspace-id is not supported for auth docker configure. Select the workspace with [PROFILE] or --profile instead
6+
7+
=== Profile argument and flag
8+
9+
>>> musterr [CLI] auth docker configure docker-test --profile docker-test
10+
Error: argument "docker-test" cannot be combined with --profile. Use --profile instead
11+
12+
=== Unsupported workspace host
13+
14+
>>> musterr [CLI] auth docker configure unsupported-host
15+
Error: profile "unsupported-host" does not target a supported Databricks workspace host. Select a workspace profile, or create one with databricks auth login --host <workspace-url> --profile <name>
16+
17+
=== Another profile already maps to the workspace
18+
19+
>>> musterr [CLI] auth docker configure docker-test
20+
Error: multiple Databricks profiles match workspace ID [NUMID]: duplicate and docker-test. Remove duplicate workspace_id entries before using Docker credential helper
21+
22+
=== Nothing changed
23+
Docker config not created; profiles unchanged
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
setup_docker_auth
2+
export DOCKER_CONFIG="$HOME/docker"
3+
4+
cat >> "$HOME/.databrickscfg" <<ENDCFG
5+
6+
[unsupported-host]
7+
host = https://workspace.example.test
8+
auth_type = databricks-cli
9+
10+
[duplicate]
11+
host = $DATABRICKS_HOST_ORIG
12+
auth_type = databricks-cli
13+
workspace_id = 900800700600
14+
ENDCFG
15+
cp "$HOME/.databrickscfg" "$HOME/databrickscfg.before"
16+
17+
title "Unsupported flag\n"
18+
trace musterr $CLI auth docker configure docker-test --workspace-id 900800700600
19+
20+
title "Profile argument and flag\n"
21+
trace musterr $CLI auth docker configure docker-test --profile docker-test
22+
23+
title "Unsupported workspace host\n"
24+
trace musterr $CLI auth docker configure unsupported-host
25+
26+
title "Another profile already maps to the workspace\n"
27+
trace musterr $CLI auth docker configure docker-test
28+
29+
title "Nothing changed\n"
30+
assert_not_exists.py "$DOCKER_CONFIG/config.json"
31+
cmp "$HOME/databrickscfg.before" "$HOME/.databrickscfg"
32+
printf 'Docker config not created; profiles unchanged\n'
Lines changed: 96 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,49 @@
11

2+
>>> databricks auth docker host --profile docker-test
3+
Registry host: [NUMID].container.us-west-2.localhost
4+
Credential helper configured: NO
5+
6+
>>> print_requests.py --get //api
7+
{
8+
"method": "GET",
9+
"path": "/api/2.0/preview/scim/v2/Me",
10+
"q": {
11+
"excludedAttributes": "entitlements"
12+
}
13+
}
14+
{
15+
"headers": {
16+
"X-Databricks-Workspace-Id": [
17+
"[NUMID]"
18+
]
19+
},
20+
"method": "GET",
21+
"path": "/api/2.1/unity-catalog/metastore_summary"
22+
}
23+
24+
>>> databricks auth docker configure docker-test
25+
Configured Docker credential helper for [NUMID].container.us-west-2.localhost
26+
Updated Docker config: [TEST_TMP_DIR]/home/docker/config.json
27+
Installed Docker credential helper: [TEST_TMP_DIR]/home/bin/docker-credential-databricks
28+
29+
>>> print_requests.py --get //api
30+
{
31+
"method": "GET",
32+
"path": "/api/2.0/preview/scim/v2/Me",
33+
"q": {
34+
"excludedAttributes": "entitlements"
35+
}
36+
}
37+
{
38+
"headers": {
39+
"X-Databricks-Workspace-Id": [
40+
"[NUMID]"
41+
]
42+
},
43+
"method": "GET",
44+
"path": "/api/2.1/unity-catalog/metastore_summary"
45+
}
46+
247
=== Docker config
348
{
449
"auths": {
@@ -7,17 +52,64 @@
752
}
853
},
954
"credHelpers": {
10-
"[NUMID].container.us-west-2.cloud.databricks.com": "databricks"
55+
"[NUMID].container.us-west-2.localhost": "databricks"
1156
}
1257
}
1358

14-
=== Installed shim
15-
Platform shim verified
59+
=== Profile with resolved workspace ID
60+
; The profile defined in the DEFAULT section is to be used as a fallback when no profile is explicitly specified.
61+
[DEFAULT]
1662

17-
=== Credential from shim
63+
[docker-test]
64+
host = [DATABRICKS_URL]
65+
auth_type = databricks-cli
66+
workspace_id = [NUMID]
67+
68+
>>> databricks auth docker host --profile docker-test --output json
69+
{
70+
"host": "[NUMID].container.us-west-2.localhost",
71+
"configured": true
72+
}
73+
74+
>>> print_requests.py --get //api
75+
{
76+
"headers": {
77+
"X-Databricks-Workspace-Id": [
78+
"[NUMID]"
79+
]
80+
},
81+
"method": "GET",
82+
"path": "/api/2.1/unity-catalog/metastore_summary"
83+
}
1884

1985
>>> docker-credential-databricks get
2086
{
2187
"Secret": "oauth-token",
2288
"Username": "oauthtoken"
2389
}
90+
91+
>>> musterr docker-credential-databricks erase
92+
docker-credential-databricks only supports get
93+
94+
=== Configure again
95+
Docker config unchanged
96+
97+
>>> print_requests.py --get //api
98+
{
99+
"headers": {
100+
"X-Databricks-Workspace-Id": [
101+
"[NUMID]"
102+
]
103+
},
104+
"method": "GET",
105+
"path": "/api/2.1/unity-catalog/metastore_summary"
106+
}
107+
108+
=== Deprecated --region flag skips workspace lookups
109+
110+
>>> databricks auth docker configure docker-test --region us-west-2
111+
Flag --region has been deprecated, --region will be fully removed in the next release
112+
Configured Docker credential helper for [NUMID].container.us-west-2.localhost
113+
Updated Docker config: [TEST_TMP_DIR]/home/docker/config.json
114+
Installed Docker credential helper: [TEST_TMP_DIR]/home/bin/docker-credential-databricks
115+
No requests sent

‎acceptance/cmd/auth/docker/configure/profile.databrickscfg‎

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,38 @@
11
setup_docker_auth
2-
3-
mkdir -p "$HOME/.databricks"
4-
cp "$TESTDIR/../token/token-cache.json" "$HOME/.databricks/token-cache.json"
5-
cp profile.databrickscfg "$HOME/.databrickscfg"
2+
install_databricks_cli
63

74
export DOCKER_CONFIG="$HOME/docker"
85
mkdir -p "$DOCKER_CONFIG"
96
cp docker-config.json "$DOCKER_CONFIG/config.json"
107

11-
mkdir -p "$HOME/bin"
12-
if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" || "$OSTYPE" == "win32" ]]; then
13-
cli_path="$HOME/bin/databricks.exe"
14-
cp "$(cygpath -u "$CLI")" "$cli_path"
15-
helper="$HOME/bin/docker-credential-databricks.cmd"
16-
else
17-
cli_path="$HOME/bin/databricks"
18-
cp "$CLI" "$cli_path"
19-
chmod +x "$cli_path"
20-
helper="$HOME/bin/docker-credential-databricks"
21-
fi
22-
export PATH="$(dirname "$helper"):$PATH"
23-
24-
"$cli_path" auth docker configure docker-test --region us-west-2 >LOG.configure 2>&1
8+
trace databricks auth docker host --profile docker-test
9+
trace print_requests.py --get //api
10+
11+
trace databricks auth docker configure docker-test
12+
trace print_requests.py --get //api
2513

2614
title "Docker config\n"
2715
jq -S . "$DOCKER_CONFIG/config.json"
2816

29-
title "Installed shim\n"
30-
if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" || "$OSTYPE" == "win32" ]]; then
31-
test -f "$helper"
32-
else
33-
test -x "$helper"
34-
fi
35-
printf 'Platform shim verified\n'
36-
37-
title "Credential from shim\n"
38-
cat > "$HOME/.databrickscfg" <<ENDCFG
39-
[docker-test]
40-
host = $DATABRICKS_HOST_ORIG
41-
auth_type = databricks-cli
42-
workspace_id = 123456789
43-
ENDCFG
44-
printf '%s\n' "$TEST_DAR_REGISTRY_HOST" | trace docker-credential-databricks get | jq -S .
17+
title "Profile with resolved workspace ID\n"
18+
cat "$HOME/.databrickscfg"
19+
20+
trace databricks auth docker host --profile docker-test --output json | tee "$HOME/host.json"
21+
trace print_requests.py --get //api
22+
23+
registry_host=$(jq -r .host "$HOME/host.json")
24+
printf '%s\n' "$registry_host" | trace docker-credential-databricks get | jq -S .
25+
26+
trace musterr docker-credential-databricks erase
27+
28+
title "Configure again\n"
29+
cp "$DOCKER_CONFIG/config.json" "$HOME/config.before.json"
30+
databricks auth docker configure docker-test &>LOG.configure-again
31+
cmp "$HOME/config.before.json" "$DOCKER_CONFIG/config.json"
32+
printf 'Docker config unchanged\n'
33+
trace print_requests.py --get //api
34+
35+
title "Deprecated --region flag skips workspace lookups\n"
36+
trace databricks auth docker configure docker-test --region us-west-2
37+
assert_not_exists.py "$OUT_REQUESTS"
38+
printf 'No requests sent\n'

‎acceptance/cmd/auth/docker/configure/test.toml‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
Ignore = [
2-
"home",
3-
]
4-
5-
EnvMatrix.DATABRICKS_BUNDLE_ENGINE = ["direct"]
6-
7-
Timeout = "15s"
1+
RecordRequests = true
2+
IncludeRequestHeaders = ["X-Databricks-Workspace-Id"]
83

94
# git-bash can't resolve/exec the installed .cmd shim on Windows; that path is
105
# covered by Go unit tests in libs/dockercredentials. Run this end-to-end on Unix.

‎acceptance/cmd/auth/docker/help/out.test.toml‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Usage:
4242

4343
Available Commands:
4444
configure (Experimental) Configure Docker authentication for Databricks Artifact Registry
45+
host (Experimental) Show the registry host and credential helper status for a profile
4546
token (Experimental) Generate a Docker credential
4647

4748
Flags:
@@ -57,3 +58,54 @@ Global Flags:
5758
--workspace-id string Databricks Workspace ID
5859

5960
Use "databricks auth docker [command] --help" for more information about a command.
61+
62+
>>> [CLI] auth docker configure --help
63+
(Experimental) Configure Docker authentication for Databricks Artifact Registry.
64+
65+
This command installs docker-credential-databricks and configures Docker to use
66+
it for the selected workspace's Artifact Registry host. If the selected profile
67+
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.
73+
74+
Usage:
75+
databricks auth docker configure [PROFILE] [flags]
76+
77+
Flags:
78+
-h, --help help for configure
79+
--region string Artifact Registry region; we recommend omitting this flag because the region is inferred automatically (DEPRECATED: --region will be fully removed in the next release)
80+
81+
Global Flags:
82+
--account-id string Databricks Account ID
83+
--debug enable debug logging
84+
--host string Databricks Host
85+
-o, --output type output type: text or json (default text)
86+
-p, --profile string ~/.databrickscfg profile
87+
-t, --target string bundle target to use (if applicable)
88+
--workspace-id string Databricks Workspace ID
89+
90+
>>> [CLI] auth docker host --help
91+
(Experimental) Show the Databricks Artifact Registry host and Docker credential helper status for a profile.
92+
93+
The --profile flag is required.
94+
95+
Usage:
96+
databricks auth docker host [flags]
97+
98+
Examples:
99+
databricks auth docker host --profile DEFAULT
100+
101+
Flags:
102+
-h, --help help for host
103+
104+
Global Flags:
105+
--account-id string Databricks Account ID
106+
--debug enable debug logging
107+
--host string Databricks Host
108+
-o, --output type output type: text or json (default text)
109+
-p, --profile string ~/.databrickscfg profile
110+
-t, --target string bundle target to use (if applicable)
111+
--workspace-id string Databricks Workspace ID

0 commit comments

Comments
 (0)