Skip to content

Commit 8a8ff48

Browse files
authored
auth describe: show U2M token storage location and source (#5211)
## Why Users have no way to tell where the CLI is storing their U2M (`databricks-cli`) token. As we move toward making secure storage the default at GA, users need to confirm whether their tokens live in the OS keyring or in `~/.databricks/token-cache.json`, and which precedence level produced that choice. `gh auth status` does this with a `(keyring)` or `(/path/to/hosts.yml)` suffix; we want the same. ## Changes Before: `databricks auth describe` showed host, user, auth type, and a "Current configuration" block, with no information about U2M token storage. Now: For profiles using `auth_type = databricks-cli`, output adds: ``` Token storage: plaintext, ~/.databricks/token-cache.json (from default) ``` or ``` Token storage: secure, OS keyring (service: databricks-cli) (from DATABRICKS_AUTH_STORAGE environment variable) ``` The `(from ...)` clause matches the existing config-attribute annotation style. Other auth types (PAT, M2M, OIDC, Azure, etc.) do not use the U2M cache and the line is omitted entirely (no field in JSON either). JSON output adds a `token_storage: { mode, location, source }` object alongside `details`. Implementation: - `libs/auth/storage/mode.go`: `ResolveStorageModeWithSource` now returns a typed `StorageSource` (`Default | Override | EnvVar | Config`) instead of an opaque bool. `StorageSource.String()` produces user-facing labels matching `config.Source.String()` style. - `libs/auth/storage/cache.go`: only existing in-repo caller updated to use `source.Explicit()`. - `cmd/auth/describe.go`: new `tokenStorageInfo` struct + `resolveTokenStorageInfo` helper. Templates conditionally render the new line. Only resolves when `auth_type == "databricks-cli"`; resolver errors are debug-logged and treated as "no info available" rather than failing describe. No probing of either backend at describe time. The describe command already makes a live API call that validates the token works; double-probing would add a 3-second hang on Linux without Secret Service for no extra signal. Following up with a `--check-token` flag is a separate change if there's appetite for it. ## Test plan - [x] Unit tests for `StorageSource.String()` and `.Explicit()` - [x] Updated `TestResolveStorageModeWithSource` for the new return type - [x] New `TestResolveTokenStorageInfo` table test covering U2M+default, U2M+env, and non-U2M - [x] New `TestGetWorkspaceAuthStatus_U2M_PopulatesTokenStorage` and `TestGetWorkspaceAuthStatus_NonU2M_OmitsTokenStorage` - [x] New acceptance tests at `acceptance/cmd/auth/describe/u2m-plaintext-default/` and `u2m-plaintext-env/` - [x] Existing PAT acceptance test (`default-profile/`) still passes unchanged - [x] Manual smoke: built CLI, ran describe with U2M+default, U2M+secure-env, and PAT profiles. Output is correct in both text and JSON. - [x] `./task checks` and `./task lint-q` clean Secure-storage acceptance tests are intentionally omitted: they would actually query the OS keyring on macOS (potential prompt) or hit the 3s timeout on Linux CI without Secret Service. Unit tests cover the secure path on any platform.
1 parent 1cf1f3b commit 8a8ff48

22 files changed

Lines changed: 482 additions & 58 deletions

File tree

NEXT_CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
### CLI
66

7+
* `databricks auth describe` now reports where U2M (`databricks-cli`) tokens are stored: `plaintext` (`~/.databricks/token-cache.json`) or `secure` (OS keyring), and the source of the choice (env var, config setting, or default).
8+
79
### Bundles
810

911
* Fixed `--force-pull` on `bundle summary` and `bundle open` so the flag bypasses the local state cache and reads state from the workspace.

acceptance/cmd/auth/describe/u2m-json-output/out.test.toml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
>>> [CLI] auth describe --profile u2m-profile --output json
3+
Warn: [hostmetadata] failed to fetch host metadata for https://u2m-profile.databricks.test, will skip for 1m0s
4+
{
5+
"mode": "plaintext",
6+
"location": "~/.databricks/token-cache.json",
7+
"source": "default"
8+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
sethome "./home"
2+
3+
unset DATABRICKS_HOST
4+
unset DATABRICKS_TOKEN
5+
unset DATABRICKS_CONFIG_PROFILE
6+
unset DATABRICKS_AUTH_STORAGE
7+
8+
cat > "./home/.databrickscfg" <<ENDCFG
9+
[u2m-profile]
10+
host = https://u2m-profile.databricks.test
11+
auth_type = databricks-cli
12+
ENDCFG
13+
14+
# Filter to just the new token_storage object so the assertion is focused
15+
# and doesn't churn when other fields evolve.
16+
trace $CLI auth describe --profile u2m-profile --output json | jq '.token_storage'
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Ignore = [
2+
"home"
3+
]

acceptance/cmd/auth/describe/u2m-plaintext-config/out.test.toml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
>>> [CLI] auth describe --profile u2m-profile
3+
Warn: [hostmetadata] failed to fetch host metadata for https://u2m-profile.databricks.test, will skip for 1m0s
4+
Unable to authenticate: error getting token: cache: token not found
5+
Token storage: plaintext, ~/.databricks/token-cache.json (from auth_storage in [__settings__] section of home/.databrickscfg)
6+
-----
7+
Current configuration:
8+
✓ host: https://u2m-profile.databricks.test (from ./home/.databrickscfg config file)
9+
✓ profile: u2m-profile (from --profile flag)
10+
✓ databricks_cli_path: [CLI]
11+
✓ auth_type: databricks-cli (from ./home/.databrickscfg config file)
12+
✓ rate_limit: [NUMID] (from DATABRICKS_RATE_LIMIT environment variable)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
sethome "./home"
2+
3+
unset DATABRICKS_HOST
4+
unset DATABRICKS_TOKEN
5+
unset DATABRICKS_CONFIG_PROFILE
6+
unset DATABRICKS_AUTH_STORAGE
7+
8+
cat > "./home/.databrickscfg" <<ENDCFG
9+
[__settings__]
10+
auth_storage = plaintext
11+
12+
[u2m-profile]
13+
host = https://u2m-profile.databricks.test
14+
auth_type = databricks-cli
15+
ENDCFG
16+
17+
trace $CLI auth describe --profile u2m-profile
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Ignore = [
2+
"home"
3+
]

acceptance/cmd/auth/describe/u2m-plaintext-default/out.test.toml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)