Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .nextchanges/cli/auth-describe-config-profile-env.md
Original file line number Diff line number Diff line change
@@ -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)).
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[DEFAULT]
host = $DATABRICKS_HOST

[env-profile]
host = $DATABRICKS_HOST
token = $DATABRICKS_TOKEN
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
bundle:
name: test-auth

workspace:
host: $DATABRICKS_HOST
3 changes: 3 additions & 0 deletions acceptance/cmd/auth/describe/bundle-profile-env/out.test.toml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions acceptance/cmd/auth/describe/bundle-profile-env/output.txt
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions acceptance/cmd/auth/describe/bundle-profile-env/script
Original file line number Diff line number Diff line change
@@ -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
16 changes: 14 additions & 2 deletions cmd/auth/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down