From 85e3a1d5d0bd95ff07a4186534c630d1e118ddb2 Mon Sep 17 00:00:00 2001 From: Matt Van Horn <455140+mvanhorn@users.noreply.github.com> Date: Mon, 13 Jul 2026 02:36:49 -0700 Subject: [PATCH 1/2] Fix auth describe misattributing DATABRICKS_CONFIG_PROFILE as bundle source Inside a bundle root the resolved config labels every attribute with the "bundle" source, so a profile selected via DATABRICKS_CONFIG_PROFILE was rendered as "(from bundle)" instead of "(from DATABRICKS_CONFIG_PROFILE environment variable)". Extend getAuthDetails to detect the env var, mirroring the flag > env precedence in cmd/root/bundle.go:getProfile. The value guard keeps genuine bundle-file profiles reading "(from bundle)". Closes #2303 Co-Authored-By: Claude Opus 4.8 (1M context) Claude-Session: https://claude.ai/code/session_01M1ZTEJFKv3BAW36VmBwe2v --- .../cli/auth-describe-config-profile-env.md | 1 + .../bundle-profile-env/.databrickscfg | 6 ++++++ .../bundle-profile-env/databricks.yml | 5 +++++ .../describe/bundle-profile-env/out.test.toml | 3 +++ .../describe/bundle-profile-env/output.txt | 21 +++++++++++++++++++ .../auth/describe/bundle-profile-env/script | 15 +++++++++++++ cmd/auth/describe.go | 16 ++++++++++++-- 7 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 .nextchanges/cli/auth-describe-config-profile-env.md create mode 100644 acceptance/cmd/auth/describe/bundle-profile-env/.databrickscfg create mode 100644 acceptance/cmd/auth/describe/bundle-profile-env/databricks.yml create mode 100644 acceptance/cmd/auth/describe/bundle-profile-env/out.test.toml create mode 100644 acceptance/cmd/auth/describe/bundle-profile-env/output.txt create mode 100644 acceptance/cmd/auth/describe/bundle-profile-env/script diff --git a/.nextchanges/cli/auth-describe-config-profile-env.md b/.nextchanges/cli/auth-describe-config-profile-env.md new file mode 100644 index 00000000000..44a683612f9 --- /dev/null +++ b/.nextchanges/cli/auth-describe-config-profile-env.md @@ -0,0 +1 @@ +Fixed `databricks auth describe` misattributing a profile selected via `DATABRICKS_CONFIG_PROFILE` as `(from bundle)` when run inside a bundle root ([#2303](https://github.com/databricks/cli/issues/2303)). diff --git a/acceptance/cmd/auth/describe/bundle-profile-env/.databrickscfg b/acceptance/cmd/auth/describe/bundle-profile-env/.databrickscfg new file mode 100644 index 00000000000..cda36ac3800 --- /dev/null +++ b/acceptance/cmd/auth/describe/bundle-profile-env/.databrickscfg @@ -0,0 +1,6 @@ +[DEFAULT] +host = $DATABRICKS_HOST + +[env-profile] +host = $DATABRICKS_HOST +token = $DATABRICKS_TOKEN diff --git a/acceptance/cmd/auth/describe/bundle-profile-env/databricks.yml b/acceptance/cmd/auth/describe/bundle-profile-env/databricks.yml new file mode 100644 index 00000000000..f64132cea83 --- /dev/null +++ b/acceptance/cmd/auth/describe/bundle-profile-env/databricks.yml @@ -0,0 +1,5 @@ +bundle: + name: test-auth + +workspace: + host: $DATABRICKS_HOST diff --git a/acceptance/cmd/auth/describe/bundle-profile-env/out.test.toml b/acceptance/cmd/auth/describe/bundle-profile-env/out.test.toml new file mode 100644 index 00000000000..f784a183258 --- /dev/null +++ b/acceptance/cmd/auth/describe/bundle-profile-env/out.test.toml @@ -0,0 +1,3 @@ +Local = true +Cloud = false +EnvMatrix.DATABRICKS_BUNDLE_ENGINE = ["terraform", "direct"] diff --git a/acceptance/cmd/auth/describe/bundle-profile-env/output.txt b/acceptance/cmd/auth/describe/bundle-profile-env/output.txt new file mode 100644 index 00000000000..38d278a905d --- /dev/null +++ b/acceptance/cmd/auth/describe/bundle-profile-env/output.txt @@ -0,0 +1,21 @@ + +=== Describe inside a bundle attributes the profile to DATABRICKS_CONFIG_PROFILE (#2303) + +>>> [CLI] auth describe +Host: [DATABRICKS_URL] +User: [USERNAME] +Authenticated with: pat +----- +Current configuration: + ✓ host: [DATABRICKS_URL] (from bundle) + ✓ workspace_id: [NUMID] + ✓ token: ******** (from .databrickscfg config file) + ✓ profile: env-profile (from DATABRICKS_CONFIG_PROFILE environment variable) + ✓ config_file: .databrickscfg (from DATABRICKS_CONFIG_FILE environment variable) + ✓ databricks_cli_path: [CLI] + ✓ auth_type: pat + ✓ http_timeout_seconds: 90 (from bundle) + ✓ rate_limit: [NUMID] (from DATABRICKS_RATE_LIMIT environment variable) + ✓ retry_timeout_seconds: 900 (from bundle) + ✓ cloud: AWS + ✓ discovery_url: [DATABRICKS_URL]/oidc/.well-known/oauth-authorization-server diff --git a/acceptance/cmd/auth/describe/bundle-profile-env/script b/acceptance/cmd/auth/describe/bundle-profile-env/script new file mode 100644 index 00000000000..33dc4391829 --- /dev/null +++ b/acceptance/cmd/auth/describe/bundle-profile-env/script @@ -0,0 +1,15 @@ +# Bake the harness host into the bundle file and the profile config. +envsubst < databricks.yml > out.yml && mv out.yml databricks.yml +envsubst < .databrickscfg > out && mv out .databrickscfg +export DATABRICKS_CONFIG_FILE=.databrickscfg + +# Select the profile via the environment, not a flag or databricks.yml. Auth is +# fully determined by the profile, so remove the ambient host/token. +unset DATABRICKS_HOST DATABRICKS_TOKEN +export DATABRICKS_CONFIG_PROFILE=env-profile + +# Inside a bundle root the resolved config labels every attribute "bundle", so +# before #2303 the profile read "(from bundle)" even though it came from +# DATABRICKS_CONFIG_PROFILE. describe must attribute it to the env var. +title "Describe inside a bundle attributes the profile to DATABRICKS_CONFIG_PROFILE (#2303)\n" +trace $CLI auth describe diff --git a/cmd/auth/describe.go b/cmd/auth/describe.go index 890838d3fcc..a58e964de27 100644 --- a/cmd/auth/describe.go +++ b/cmd/auth/describe.go @@ -327,9 +327,21 @@ func getAuthDetails(cmd *cobra.Command, cfg *config.Config, showSensitive bool) } details := cfg.GetAuthDetails(opts...) + ctx := cmd.Context() for k, v := range details.Configuration { - if k == "profile" && cmd.Flag("profile").Changed { - v.Source = config.Source{Type: config.SourceType("flag"), Name: "--profile"} + if k == "profile" { + // Profile-source precedence mirrors cmd/root/bundle.go:getProfile: + // an explicit --profile flag wins, then DATABRICKS_CONFIG_PROFILE. + // Inside a bundle root the resolved config labels every attribute + // "bundle" (bundle/config/workspace.go), which misattributes a + // profile that actually came from the environment (#2303). The + // value guard relabels only when the env var is the profile that + // won, so a profile set in databricks.yml still reads "bundle". + if cmd.Flag("profile").Changed { + v.Source = config.Source{Type: config.SourceType("flag"), Name: "--profile"} + } else if envProfile := env.Get(ctx, "DATABRICKS_CONFIG_PROFILE"); envProfile != "" && envProfile == v.Value { + v.Source = config.Source{Type: config.SourceEnv, Name: "DATABRICKS_CONFIG_PROFILE"} + } } if k == "host" && cmd.Flag("host").Changed { From 3a65e5085d5fa6cbb5b1eca0f458a5927290326d Mon Sep 17 00:00:00 2001 From: Jan N Rose Date: Wed, 15 Jul 2026 10:39:04 +0200 Subject: [PATCH 2/2] Update .nextchanges/cli/auth-describe-config-profile-env.md --- .nextchanges/cli/auth-describe-config-profile-env.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.nextchanges/cli/auth-describe-config-profile-env.md b/.nextchanges/cli/auth-describe-config-profile-env.md index 44a683612f9..4ef0d12dd8e 100644 --- a/.nextchanges/cli/auth-describe-config-profile-env.md +++ b/.nextchanges/cli/auth-describe-config-profile-env.md @@ -1 +1 @@ -Fixed `databricks auth describe` misattributing a profile selected via `DATABRICKS_CONFIG_PROFILE` as `(from bundle)` when run inside a bundle root ([#2303](https://github.com/databricks/cli/issues/2303)). +Fixed `databricks auth describe` misattributing a profile selected via `DATABRICKS_CONFIG_PROFILE` as `(from bundle)` when run inside a bundle root ([#5904](https://github.com/databricks/cli/pull/5904)).