Skip to content

Resolve --host to matching profile for token cache lookup - #4591

Merged
simonfaltum merged 1 commit into
mainfrom
simonfaltum/auth-token-host-to-profile
Feb 24, 2026
Merged

Resolve --host to matching profile for token cache lookup#4591
simonfaltum merged 1 commit into
mainfrom
simonfaltum/auth-token-host-to-profile

Conversation

@simonfaltum

@simonfaltumsimonfaltum commented Feb 24, 2026

Copy link
Copy Markdown
Member

Why

When you run databricks auth token --host <url>, the CLI looks up the token using the host URL as the cache key. But if you logged in with --profile, the token was stored under the profile name, not the host URL. So --host can't find it — even though the token exists and the profile points to exactly that host.

This is the flip side of the bug fixed in databricks/databricks-sdk-go#1497: that PR made --profile fall back to the host key. This PR makes --host resolve to the profile key.

Together, both directions work: --profile finds host-keyed tokens, and --host finds profile-keyed tokens.

Changes

Two-line change in loadToken (cmd/auth/token.go).

The CLI already loads all profiles matching a given host and errors when there are multiple matches (the ambiguity check). This PR adds an else if branch: when exactly one profile matches, use that profile's name as the cache key instead of the raw host URL.

iflen(matchingProfiles) >1 {
// existing: ambiguity error
} elseiflen(matchingProfiles) ==1 {
args.profileName=matchingProfiles[0].Name
}

The matching is already host-type-aware from the existing code:

  • Workspace hosts match by host URL
  • Account/unified hosts match by host URL + account ID

No new matching logic was added.

Side effect: error messages now suggest --profile <name> instead of --host <url> when the host resolves to a profile. This is better UX — if we know the profile, we should suggest it.

Test plan

Three new test cases added to TestToken_loadToken:

  1. Host with one matching profile resolves to profile key — token exists only under the profile key (not the host URL). --host finds it by resolving to the profile first.
  2. Host with no matching profile uses host key — no profile in .databrickscfg matches the host. Falls back to looking up by host URL directly. Unchanged behavior.
  3. Host with one matching profile, host-key-only token (migration) — profile exists in .databrickscfg but the token was stored under the host URL only (legacy). CLI resolves --host to the profile name, then the SDK's read-fallback (from #1497) finds the token under the host key.

All existing tests continue to pass. One existing test's expected error message changed from --host ... --account-id ... to --profile expired because the host now resolves to the expired profile.

Manual testing

I tested this manually with my local .databrickscfg:

$ databricks auth token --host https://adb-2548836972759138.18.azuredatabricks.net/

This host matches my logfood profile. Before this change, it would look up by host URL. After this change, it resolves to logfood and looks up by profile key. The token is returned in both cases (because dualWrite currently populates both keys), but the cache key used is now the profile name.

When `auth token --host` is provided without `--profile`, and exactly one
profile in .databrickscfg matches that host, use the profile name as the
cache key instead of the host URL. This ensures tokens stored under the
profile key are found regardless of whether --host or --profile was used.
@eng-dev-ecosystem-bot

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

Copy link
Copy Markdown
Collaborator

Commit: 5052555

Run: 22363728967

Env🟨​KNOWN💚​RECOVERED🙈​SKIP✅​pass🙈​skipTime
🟨​aws linux7172687656:57
🟨​aws windows7172707636:09
💚​aws-ucws linux873646816:36
💚​aws-ucws windows873666796:03
💚​azure linux292717635:29
💚​azure windows292737614:33
💚​azure-ucws linux293696777:49
💚​azure-ucws windows293716755:53
💚​gcp linux292677665:24
💚​gcp windows292697644:51
15 interesting tests: 7 KNOWN, 7 SKIP, 1 RECOVERED
Test Nameaws linuxaws windowsaws-ucws linuxaws-ucws windowsazure linuxazure windowsazure-ucws linuxazure-ucws windowsgcp linuxgcp windows
🟨​TestAccept🟨​K🟨​K💚​R💚​R💚​R💚​R💚​R💚​R💚​R💚​R
🙈​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/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/recreate🙈​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/ssh/connection💚​R💚​R💚​R💚​R💚​R💚​R💚​R💚​R💚​R💚​R
Top 20 slowest tests (at least 2 minutes):
durationenvtestname
3:47aws-ucws windowsTestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=direct
3:26azure-ucws windowsTestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=direct
3:23aws-ucws linuxTestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=terraform
3:21azure-ucws windowsTestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=terraform
3:20aws linuxTestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=direct
3:15gcp linuxTestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=terraform
3:11gcp windowsTestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=terraform
3:08aws windowsTestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=terraform
3:08gcp windowsTestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=direct
3:06gcp linuxTestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=direct
3:00aws windowsTestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=direct
2:58aws linuxTestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=terraform
2:51aws-ucws linuxTestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=direct
2:48aws-ucws windowsTestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=terraform
2:20azure windowsTestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=direct
2:15azure windowsTestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=terraform
2:13azure-ucws linuxTestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=terraform
2:10azure linuxTestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=terraform
2:08azure-ucws linuxTestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=direct
2:07azure linuxTestAccept/bundle/resources/apps/inline_config/DATABRICKS_BUNDLE_ENGINE=direct

@simonfaltum
simonfaltum marked this pull request as ready for review February 24, 2026 18:27
@simonfaltum
simonfaltum added this pull request to the merge queueFeb 24, 2026
Merged via the queue into main with commit 1899134Feb 24, 2026
18 checks passed
@simonfaltum
simonfaltum deleted the simonfaltum/auth-token-host-to-profile branch February 24, 2026 19:55
deco-sdk-taggingBot added a commit that referenced this pull request Feb 26, 2026
## Release v0.290.0
### CLI
* Add `completion install`, `uninstall`, and `status` subcommands ([#4581](#4581))
* Wire profile name through CLI ToOAuthArgument for profile-based cache keys ([#4562](#4562))
* Add host disambiguation and positional profile support to auth token ([#4574](#4574))
* Update error messages to suggest 'databricks auth login' ([#4587](#4587))
* Resolve --host to matching profile for token cache lookup ([#4591](#4591))
* Improve auth token UX: profile selection and better empty-state handling ([#4584(#4584)
### Bundles
* Added support for git_source and git_repository for Apps ([#4538](#4538))
### Dependency updates
* Upgrade TF provider to 1.109.0 ([#4561](#4561))
* Upgrade Go SDK to v0.110.0 ([#4552](#4552))
### API Changes
* Bump databricks-sdk-go from v0.111.0 to v0.112.0.
denik pushed a commit that referenced this pull request May 20, 2026
## Why
When you run `databricks auth token --host <url>`, the CLI looks up the
token using the host URL as the cache key. But if you logged in with
`--profile`, the token was stored under the profile name, not the host
URL. So `--host` can't find it — even though the token exists and the
profile points to exactly that host.
This is the flip side of the bug fixed in
databricks/databricks-sdk-go#1497: that PR made `--profile` fall back to
the host key. This PR makes `--host` resolve to the profile key.
Together, both directions work: `--profile` finds host-keyed tokens, and
`--host` finds profile-keyed tokens.
## Changes
Two-line change in `loadToken` (`cmd/auth/token.go`).
The CLI already loads all profiles matching a given host and errors when
there are multiple matches (the ambiguity check). This PR adds an `else
if` branch: when exactly one profile matches, use that profile's name as
the cache key instead of the raw host URL.
```go
if len(matchingProfiles) > 1 {
// existing: ambiguity error
} else if len(matchingProfiles) == 1 {
args.profileName = matchingProfiles[0].Name
}
```
The matching is already host-type-aware from the existing code:
- Workspace hosts match by host URL
- Account/unified hosts match by host URL + account ID
No new matching logic was added.
**Side effect**: error messages now suggest `--profile <name>` instead
of `--host <url>` when the host resolves to a profile. This is better UX
— if we know the profile, we should suggest it.
## Test plan
Three new test cases added to `TestToken_loadToken`:
1. **Host with one matching profile resolves to profile key** — token
exists only under the profile key (not the host URL). `--host` finds it
by resolving to the profile first.
2. **Host with no matching profile uses host key** — no profile in
`.databrickscfg` matches the host. Falls back to looking up by host URL
directly. Unchanged behavior.
3. **Host with one matching profile, host-key-only token (migration)** —
profile exists in `.databrickscfg` but the token was stored under the
host URL only (legacy). CLI resolves `--host` to the profile name, then
the SDK's read-fallback (from
[#1497](databricks/databricks-sdk-go#1497))
finds the token under the host key.
All existing tests continue to pass. One existing test's expected error
message changed from `--host ... --account-id ...` to `--profile
expired` because the host now resolves to the `expired` profile.
### Manual testing
I tested this manually with my local `.databrickscfg`:
```
$ databricks auth token --host https://adb-2548836972759138.18.azuredatabricks.net/
```
This host matches my `logfood` profile. Before this change, it would
look up by host URL. After this change, it resolves to `logfood` and
looks up by profile key. The token is returned in both cases (because
`dualWrite` currently populates both keys), but the cache key used is
now the profile name.
denik pushed a commit that referenced this pull request May 20, 2026
## Release v0.290.0
### CLI
* Add `completion install`, `uninstall`, and `status` subcommands ([#4581](#4581))
* Wire profile name through CLI ToOAuthArgument for profile-based cache keys ([#4562](#4562))
* Add host disambiguation and positional profile support to auth token ([#4574](#4574))
* Update error messages to suggest 'databricks auth login' ([#4587](#4587))
* Resolve --host to matching profile for token cache lookup ([#4591](#4591))
* Improve auth token UX: profile selection and better empty-state handling ([#4584(#4584)
### Bundles
* Added support for git_source and git_repository for Apps ([#4538](#4538))
### Dependency updates
* Upgrade TF provider to 1.109.0 ([#4561](#4561))
* Upgrade Go SDK to v0.110.0 ([#4552](#4552))
### API Changes
* Bump databricks-sdk-go from v0.111.0 to v0.112.0.
Sign up for freeto 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.

3 participants

@simonfaltum@eng-dev-ecosystem-bot@renaudhartert-db