Skip to content

auth: honor --host on auth describe and prefer default profile when host is ambiguous#5343

Merged
simonfaltum merged 2 commits into
mainfrom
simonfaltum/auth-describe-host-flag
May 28, 2026
Merged

auth: honor --host on auth describe and prefer default profile when host is ambiguous#5343
simonfaltum merged 2 commits into
mainfrom
simonfaltum/auth-describe-host-flag

Conversation

@simonfaltum
Copy link
Copy Markdown
Member

Why

`databricks auth describe --host X` silently ignored the flag. The value was bound to the parent `auth` command's `authArguments.Host` but never read by the describe flow, so the SDK fell back to `[settings].default_profile` (silently describing a different host than the one named) or the "default auth: cannot configure default credentials" error even when a host-matching profile existed. The display still labelled the value `(from --host flag)`, making the mismatch hard to spot. Reported in a bug bash.

Reproduced against `db-deco-test.databricks.com` (which has two matching profiles in my .databrickscfg):
```
$ databricks auth describe --host https://db-deco-test.databricks.com
Host: https://dogfood.staging.databricks.com ← actually dogfood, not db-deco-test
✓ host: https://dogfood.staging.databricks.com (from --host flag) ← misleading label
✓ profile: dogfood
```

Changes

  • `describe.go`: when `--host` is set without `--profile`, resolve the host to a profile name via the existing `resolveHostToProfile` and set `--profile` so the downstream `MustAnyClient` uses it. `DATABRICKS_CONFIG_PROFILE` is left alone — it's an explicit user signal.
  • `resolve.go`: when multiple profiles match a host, prefer `[settings].default_profile` if it's one of the matches before falling back to the picker or ambiguity error. The same helper is used by `auth logout`, which gets the same UX improvement (no prompt when the user's default already disambiguates).

After the fix, against the same host:
```
$ databricks auth describe --host https://db-deco-test.databricks.com
Error: multiple profiles found matching host "https://db-deco-test.databricks.com\":
spog-deco-aws, db-deco-test-chrisst. Please specify the profile name directly
```
And with `default_profile = spog-deco-aws` in `[settings]`, the same command auto-selects `spog-deco-aws` without prompting.

Test plan

  • Reproduced against `db-deco-test.databricks.com`: confirmed the original bug (default profile silently used, misleading source label).
  • After the fix: single-host-match case picks the matching profile, multi-match case prefers the configured default, no-match case gives a clean error.
  • No-flag case still uses `default_profile` as before — no regression.
  • New unit test: `TestResolveHostToProfilePrefersConfiguredDefault`.
  • `go test ./cmd/auth/...`, `./task checks`, `./task lint-q`.

…rofile

`databricks auth describe --host X` silently ignored the flag: the value
was bound to the parent command's `authArguments.Host` but never read by
the describe flow, so the SDK fell back to
[__settings__].default_profile (silently describing a different host) or
the "default auth: cannot configure default credentials" error even when
a host-matching profile existed. The display still labelled the value
"(from --host flag)", making the mismatch hard to spot.

- describe.go: when --host is set without --profile, resolve the host to
  a profile name (via the existing `resolveHostToProfile`) and set
  --profile so MustAnyClient uses it. DATABRICKS_CONFIG_PROFILE is left
  alone — it's an explicit user signal.
- resolve.go: when multiple profiles match a host, prefer the
  [__settings__].default_profile if it's one of them, before falling
  back to the picker or ambiguity error. Same helper is used by `auth
  logout`, which gets the same UX improvement.

Co-authored-by: Isaac
@eng-dev-ecosystem-bot
Copy link
Copy Markdown
Collaborator

eng-dev-ecosystem-bot commented May 27, 2026

Commit: 9fe91b9

Run: 26514529200

GPT review caught two test gaps:

- TestResolveHostToProfileMatchesMultipleProfiles relied on whatever
  default_profile happened to be in the caller's real .databrickscfg.
  After the new prefer-default branch, a local default could
  inadvertently resolve the call instead of returning the expected
  ambiguity error. Point DATABRICKS_CONFIG_FILE at an empty temp file
  for the test.

- The auth describe --host wiring (resolveProfileFromHostFlag) had no
  direct test; the only coverage was indirect through
  resolveHostToProfile. Add focused subtests for the no-op, --profile
  precedence, single-match, no-match, and DATABRICKS_CONFIG_PROFILE
  bail-out cases.

Co-authored-by: Isaac
Comment thread cmd/auth/resolve.go
Comment on lines +78 to +88
// Prefer the configured default profile when it's one of the host
// matches, so commands that pass --host don't trip the picker for
// users who already picked a default.
if defaultProfile, _ := databrickscfg.GetDefaultProfile(ctx, env.Get(ctx, "DATABRICKS_CONFIG_FILE")); defaultProfile != "" {
for _, p := range hostProfiles {
if p.Name == defaultProfile {
log.Debugf(ctx, "multiple profiles match host %q; using default profile %q", host, defaultProfile)
return p.Name, nil
}
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This behaviour would also propagate to auth logout but I'd say that's fine.

@simonfaltum simonfaltum added this pull request to the merge queue May 28, 2026
Merged via the queue into main with commit c19a115 May 28, 2026
27 checks passed
@simonfaltum simonfaltum deleted the simonfaltum/auth-describe-host-flag branch May 28, 2026 11:08
@eng-dev-ecosystem-bot
Copy link
Copy Markdown
Collaborator

Commit: c19a115

Run: 26571063307

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants