Skip to content

Make --profile take precedence over auth environment variables#5702

Draft
radakam wants to merge 5 commits into
mainfrom
cli-5096-fix-profile-not-respected
Draft

Make --profile take precedence over auth environment variables#5702
radakam wants to merge 5 commits into
mainfrom
cli-5096-fix-profile-not-respected

Conversation

@radakam

@radakam radakam commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Why

With an explicit profile (--profile or a bundle's workspace.profile), auth env vars (DATABRICKS_HOST, DATABRICKS_TOKEN, ...) silently shadowed it: the SDK reads env before the config file and never overwrites a set field.

Changes

Fixes #5096

When a profile is selected explicitly, use a shared loader chain (databrickscfg.ProfileAuthLoaders) so the profile wins for host and auth, while env still gap-fills only the auth fields the profile leaves empty (e.g. host-only profile + DATABRICKS_TOKEN). Wired into MustWorkspaceClient, MustAccountClient, Workspace.Client, and databricks api.

Explicit design choices:

  • Scope: only an explicit profile changes behavior. DATABRICKS_CONFIG_PROFILE keeps the SDK's env-first precedence (reordering two env signals is the SDK's domain).
  • Conflicting auth method: a complete auth method in env (e.g. profile PAT + env OAuth client id/secret) still errors with "more than one authorization method configured". This matches pre-fix behavior; it is not silently dropped.
  • SPOG query params: for an explicit profile we skip NormalizeDatabricksConfigFromEnv, so a host-less profile + SPOG-style DATABRICKS_HOST (?o=/?a=) no longer extracts workspace_id/account_id from the query. The profile's host is authoritative instead.

Tests

  • Unit + acceptance: --profile/workspace.profile wins over auth env; DATABRICKS_CONFIG_PROFILE stays env-first; host-only profile fills its token from env; conflicting-method error; SDK-bump guard for newly added internal env attributes.

When --profile is set explicitly, host and auth credentials from the
profile now win over DATABRICKS_HOST/DATABRICKS_TOKEN and other auth env
vars. Previously the SDK's env-first loader order silently shadowed the
selected profile (#5096).
@radakam radakam temporarily deployed to test-trigger-is June 24, 2026 12:00 — with GitHub Actions Inactive
@radakam radakam temporarily deployed to test-trigger-is June 24, 2026 12:00 — with GitHub Actions Inactive
@eng-dev-ecosystem-bot

eng-dev-ecosystem-bot commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

Integration test report

Commit: a673c11

Run: 28100625590

Env ❌​FAIL 🟨​KNOWN 🔄​flaky 💚​RECOVERED 🙈​SKIP ✅​pass 🙈​skip Time
🟨​ aws linux 7 13 244 1024 7:16
🟨​ aws windows 7 13 246 1022 7:33
💚​ aws-ucws linux 7 13 334 940 5:23
💚​ aws-ucws windows 7 13 336 938 6:06
💚​ azure linux 1 15 247 1022 5:16
❌​ azure windows 2 1 1 15 246 1020 8:14
💚​ azure-ucws linux 1 15 339 936 6:08
💚​ azure-ucws windows 1 15 341 934 4:55
💚​ gcp linux 1 15 246 1024 4:21
💚​ gcp windows 1 15 248 1022 5:05
23 interesting tests: 13 SKIP, 7 KNOWN, 2 FAIL, 1 flaky
Test Name aws linux aws windows aws-ucws linux aws-ucws windows azure linux azure windows azure-ucws linux azure-ucws windows gcp linux gcp windows
🟨​ TestAccept 🟨​K 🟨​K 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R
🙈​ TestAccept/bundle/invariant/no_drift 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🙈​ TestAccept/bundle/resources/permissions 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🟨​ TestAccept/bundle/resources/permissions/jobs/destroy_without_mgmtperms/with_permissions 🟨​K 🟨​K 💚​R 💚​R 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🟨​ TestAccept/bundle/resources/permissions/jobs/destroy_without_mgmtperms/with_permissions/DATABRICKS_BUNDLE_ENGINE=direct 🟨​K 🟨​K 💚​R 💚​R
🟨​ TestAccept/bundle/resources/permissions/jobs/destroy_without_mgmtperms/with_permissions/DATABRICKS_BUNDLE_ENGINE=terraform 🟨​K 🟨​K 💚​R 💚​R
🟨​ TestAccept/bundle/resources/permissions/jobs/destroy_without_mgmtperms/without_permissions 🟨​K 🟨​K 💚​R 💚​R 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🟨​ TestAccept/bundle/resources/permissions/jobs/destroy_without_mgmtperms/without_permissions/DATABRICKS_BUNDLE_ENGINE=direct 🟨​K 🟨​K 💚​R 💚​R
🟨​ TestAccept/bundle/resources/permissions/jobs/destroy_without_mgmtperms/without_permissions/DATABRICKS_BUNDLE_ENGINE=terraform 🟨​K 🟨​K 💚​R 💚​R
🙈​ TestAccept/bundle/resources/postgres_branches/basic 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🙈​ TestAccept/bundle/resources/postgres_branches/recreate 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🙈​ TestAccept/bundle/resources/postgres_branches/replace_existing 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🙈​ TestAccept/bundle/resources/postgres_branches/update_protected 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🙈​ TestAccept/bundle/resources/postgres_branches/without_branch_id 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🙈​ TestAccept/bundle/resources/postgres_endpoints/basic 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🙈​ TestAccept/bundle/resources/postgres_projects/update_display_name 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🙈​ TestAccept/bundle/resources/synced_database_tables/basic 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🙈​ TestAccept/bundle/resources/vector_search_endpoints/drift/recreated_same_name 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🙈​ TestAccept/bundle/resources/vector_search_indexes/recreate/embedding_dimension 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🙈​ TestAccept/ssh/connection 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
❌​ TestFetchRepositoryInfoAPI_FromRepo ✅​p ✅​p ✅​p ✅​p ✅​p ❌​F ✅​p ✅​p ✅​p ✅​p
🔄​ TestFetchRepositoryInfoAPI_FromRepo/root ✅​p ✅​p ✅​p ✅​p ✅​p 🔄​f ✅​p ✅​p ✅​p ✅​p
❌​ TestFetchRepositoryInfoAPI_FromRepo/subdir ✅​p ✅​p ✅​p ✅​p ✅​p ❌​F ✅​p ✅​p ✅​p ✅​p
Top 5 slowest tests (at least 2 minutes):
duration env testname
3:21 gcp windows TestAccept
3:16 aws-ucws windows TestAccept
3:13 aws linux TestSecretsPutSecretStringValue
2:41 azure windows TestAccept
2:31 azure-ucws windows TestAccept

Extend the --profile precedence fix (#5096):

- ResolveNonAuthFromEnv now also skips auth_type and discovery_url, which
  are tagged auth:"-" in the SDK and so are invisible to HasAuthAttribute,
  letting DATABRICKS_AUTH_TYPE/DATABRICKS_DISCOVERY_URL shadow the profile.
  It also records the env source so `auth describe` and debug output match
  the SDK loader.
- Workspace.Client uses ResolveNonAuthFromEnv when a profile is set (from
  --profile or workspace.profile) so env auth vars no longer shadow the
  profile for bundle commands.
- Use the reserved .test TLD for new test fixture hosts so the SDK's
  well-known host metadata resolver fast-fails instead of stalling on a
  live network lookup.
@radakam radakam temporarily deployed to test-trigger-is June 24, 2026 12:26 — with GitHub Actions Inactive
@radakam radakam temporarily deployed to test-trigger-is June 24, 2026 12:26 — with GitHub Actions Inactive
A host-only profile combined with DATABRICKS_TOKEN previously failed because
the profile loader chain stopped at the config file. Append
config.ConfigAttributes after the profile so the environment can fill auth
fields the profile does not provide, while the profile still wins for any
field it sets (#5096).
@radakam radakam temporarily deployed to test-trigger-is June 24, 2026 13:05 — with GitHub Actions Inactive
@radakam radakam temporarily deployed to test-trigger-is June 24, 2026 13:05 — with GitHub Actions Inactive
- Centralize the explicit-profile loader chain in databrickscfg.ProfileAuthLoaders
  and extract applyProfileAuthPrecedence so all call sites share one rule.
- Skip host, routing IDs (workspace_id/account_id) and SDK-internal auth-steering
  env attrs; guard the classification with a test that fails on SDK drift.
- Apply profile precedence to `databricks api --profile`.
- Let env gap-fill auth fields a host-only profile leaves empty.
- Add bundle host+profile coverage and acceptance tests; clarify rationale comments.
@radakam radakam force-pushed the cli-5096-fix-profile-not-respected branch from fe17837 to ae05b0e Compare June 26, 2026 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLI profile not respected

2 participants