Make an explicitly selected profile take precedence over auth environment variables#5702
Make an explicitly selected profile take precedence over auth environment variables#5702radakam wants to merge 5 commits into
Conversation
Integration test reportCommit: e16df4f
23 interesting tests: 13 SKIP, 7 KNOWN, 2 flaky, 1 RECOVERED
Top 4 slowest tests (at least 2 minutes):
|
fe17837 to
ae05b0e
Compare
72b1acb to
b2c4d95
Compare
Approval status: pending
|
b2c4d95 to
aeb17ab
Compare
aeb17ab to
7ce0ce7
Compare
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).
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.
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).
- 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.
7ce0ce7 to
e16df4f
Compare
Why
With an explicit profile (
--profileor a bundle'sworkspace.profile), auth env vars (DATABRICKS_HOST,DATABRICKS_TOKEN, ...) silently shadowed it: the SDK reads env before the config file and never overwrites an already-set field.Changes
Fixes #5096
When a profile is selected explicitly, use a shared loader chain (
databrickscfg.ProfileAuthLoaders) so the profile wins for host/auth/routing, while env still gap-fills only the auth fields the profile leaves empty (e.g. host-only profile +DATABRICKS_TOKEN). Non-auth env vars (e.g.cluster_id) stay env-first via a smallResolveNonAuthFromEnvloader. Wired intoMustWorkspaceClient,MustAccountClient,Workspace.Client, anddatabricks api.Explicit design choices:
DATABRICKS_CONFIG_PROFILEkeeps the SDK's env-first precedence.NormalizeDatabricksConfigFromEnv, so a SPOG-styleDATABRICKS_HOST(?o=/?a=) no longer overrides the profile; the profile's host is authoritative.Tests
--profile/workspace.profilewins over auth env;DATABRICKS_CONFIG_PROFILEstays env-first; host-only profile fills its token from env; conflicting-method error.auth:"-") env-backed attribute that hasn't been classified as auth-steering vs. env-first.