Add auth logout command with --profile and --force flags#4613
Closed
mihaimitrea-db wants to merge 20 commits intomainfrom
Closed
Add auth logout command with --profile and --force flags#4613mihaimitrea-db wants to merge 20 commits intomainfrom
mihaimitrea-db wants to merge 20 commits intomainfrom
Conversation
Collaborator
|
Commit: c9e8d79
20 interesting tests: 7 SKIP, 6 flaky, 6 RECOVERED, 1 FAIL
Top 40 slowest tests (at least 2 minutes):
|
0b2d46f to
5f039b9
Compare
simonfaltum
approved these changes
Mar 2, 2026
Member
simonfaltum
left a comment
There was a problem hiding this comment.
Looks good! Maybe add an extra test but can also be done in a follow up at a later stage
pietern
reviewed
Mar 3, 2026
Contributor
pietern
left a comment
There was a problem hiding this comment.
I recommend adding a few acceptance tests to test this e2e.
That would also capture some of the error messages.
Contributor
|
An acceptance test will also confirm the before/after state of the I would like to see if comments, ordering, etc, are retained upon profile deletion. |
b8fed18 to
0ca6e59
Compare
9cf58d8 to
66871b3
Compare
66871b3 to
1764259
Compare
Implement the initial version of databricks auth logout which removes a profile from ~/.databrickscfg and clears associated OAuth tokens from the token cache. This iteration supports explicit profile selection via --profile and a --force flag to skip the confirmation prompt. Interactive profile selection will be added in a follow-up. Token cache cleanup is best-effort: the profile-keyed token is always removed, and the host-keyed token is removed only when no other profile references the same host.
Replace plain fmt.Sprintf confirmation prompt with a structured template using cmdio.RenderWithTemplate. The warning now uses color and bold formatting to clearly highlight the profile name, config path, and consequences before prompting for confirmation.
Resolve config path from the profiler instead of hardcoding fallbacks. Delete the profile before clearing the token cache so a config write failure does not leave tokens removed. Fix token cleanup for account and unified profiles by computing the correct OIDC cache key (host/oidc/accounts/<account_id>). Drop the nil profiler guard, add a success message on logout, and extract backupConfigFile in ops.go to remove duplication. Consolidate token cleanup tests into a table-driven test covering shared hosts, unique hosts, account, and unified profiles.
Merge shared-host token deletion verification into one main parametrized test by addding the hostBasedKey and isSharedKey parameters to each case. This replaces the TestLogoutTokenCacheCleanup test with an assertion: host-based keys are preserved when another profile shares the same host, and deleted otherwise.
Rewrite the test to use inline config seeds and explicit expected state. Add cases for deleting the last non-default profile, deleting a unified host profile with multiple keys, and deleting the DEFAULT section.
- Use profiler.GetPath() to resolve config path instead of hardcoding platform-specific defaults for the help text. - Read DATABRICKS_CONFIG_FILE via env.Get(ctx, ...) instead of os.Getenv to respect context-level env overrides. - Add abort message when user declines the confirmation prompt. - Guard DeleteProfile against non-existent profiles to avoid creating unnecessary backup files. - Add TestDeleteProfile_NotFound for the error path.
Cover four scenarios: profile ordering and comments are preserved after deletion, deleting the last non-default profile leaves an empty DEFAULT section, deleting the DEFAULT profile itself clears its keys and restores the default comment, and error paths for non-existent profiles and missing --profile in non-interactive mode.
By default, Authentication related commands. For more information regarding how authentication for the Databricks CLI and SDKs work please refer to the documentation linked below. AWS: https://docs.databricks.com/dev-tools/auth/index.html Azure: https://learn.microsoft.com/azure/databricks/dev-tools/auth GCP: https://docs.gcp.databricks.com/dev-tools/auth/index.html Usage: databricks auth [command] Available Commands: describe Describes the credentials and the source of those credentials, being used by the CLI to authenticate env Get env login Log into a Databricks workspace or account profiles Lists profiles from ~/.databrickscfg token Get authentication token Flags: --account-id string Databricks Account ID --experimental-is-unified-host Flag to indicate if the host is a unified host -h, --help help for auth --host string Databricks Host --workspace-id string Databricks Workspace ID Global Flags: --debug enable debug logging -o, --output type output type: text or json (default text) -p, --profile string ~/.databrickscfg profile -t, --target string bundle target to use (if applicable) Use "databricks auth [command] --help" for more information about a command. now only clears cached OAuth tokens without removing the profile from ~/.databrickscfg. Pass --delete to also remove the profile entry from the config file.
Existing acceptance tests that verify profile deletion now use --delete since profile removal is opt-in. Two new acceptance tests verify token-only logout: one for a unique host (both cache entries cleared) and one for a shared host (host-keyed token preserved).
Replace manual strings.TrimRight(host, /) with the SDK's config.Config.CanonicalHostName(), which handles scheme normalization, trailing slashes, and empty hosts consistently with how the SDK itself computes token cache keys.
- Make Long description static to avoid calling logger and GetPath at command construction time before the logger is initialized. - Remove empty test.toml files from acceptance tests. - Add \n to error-case titles so errors appear on a separate line. - Use .tokens | keys in jq queries for token cache to reduce verbosity. - Switch test profiles from PAT to auth_type=databricks-cli (U2M) so token cache tests exercise a realistic OAuth logout flow. - Add AuthType field to profile.Profile to detect non-U2M profiles; skip token cache cleanup and adjust success message accordingly. - Add delete-m2m-profiles acceptance test covering PAT profile logout with and without --delete. - Fix DeleteProfile to clear DEFAULT section keys instead of deleting and recreating it, preserving its position in the file.
- Rename isU2MProfile to isCreatedByLogin to accurately reflect that the check is specific to profiles created by . - Tighten success and error messages: drop "Successfully", add actionable suggestions (e.g. "Use --delete to also remove it"), and include retry guidance on partial failures. - Return errors instead of logging on DeleteProfile failure so callers see a non-zero exit code. - Fix token-only acceptance test: use OIDC-style cache key (host/oidc/accounts/<id>) for account profiles so both token cache entries are correctly cleaned up.
25dca58 to
22d250f
Compare
github-merge-queue bot
pushed a commit
that referenced
this pull request
Mar 12, 2026
…ckers (#4647) ## 🥞 Stacked PR Use this [link](https://github.com/databricks/cli/pull/4647/files/e5a1d8842ee9a458d4ffb3cea672a0f88077356f..51f14b5c7ea409cffdc78a3025a70de5c674fa9a) to review incremental changes. - [stack/auth_logout](#4613) [[Files changed](https://github.com/databricks/cli/pull/4613/files)] - [stack/auth_logout_profile_picker](#4616) [[Files changed](https://github.com/databricks/cli/pull/4616/files/c9e8d79e276d6c33faa1e859ca20cc5136f9efb7..e5a1d8842ee9a458d4ffb3cea672a0f88077356f)] - [**stack/auth_logout_deduplication**](#4647) [[Files changed](https://github.com/databricks/cli/pull/4647/files/e5a1d8842ee9a458d4ffb3cea672a0f88077356f..51f14b5c7ea409cffdc78a3025a70de5c674fa9a)] --------- Four places built nearly identical `promptui.Select` prompts for interactive profile selection (`auth logout`, `auth token`, `cmd/root/auth.go`, `cmd/root/bundle.go`). This PR extracts a reusable `profile.SelectProfile` function that accepts a declarative `SelectConfig` with label, profiles, and template strings, replacing all four implementations. ## Changes - Add `profile.SelectProfile` in `libs/databrickscfg/profile/select.go` — a shared interactive profile picker that accepts a `SelectConfig` (label, profiles, template strings) and returns the selected profile name. - Replace the four inline `promptui.Select` implementations in `cmd/auth/logout.go`, `cmd/auth/token.go`, `cmd/root/auth.go`, and `cmd/root/bundle.go` with calls to `SelectProfile`. - Add `AccountID` to `Profiles.SearchCaseInsensitive` so all pickers support searching by account ID, not just name and host. - Extract `writeConfigFile` helper in `libs/databrickscfg/ops.go` to consolidate the repeated default-comment / backup / save sequence shared by `SaveToProfile` and `DeleteProfile`. ## Why The four profile pickers each duplicated the same prompt setup, searcher wiring, and result extraction. This made it easy for behavior to diverge (e.g., only the logout picker searched by account ID). A single shared helper keeps the UX consistent and reduces the surface area for future changes. ## Tests - Existing unit and acceptance tests for `auth logout`, `auth token`, workspace/account profile selection, and bundle profile resolution continue to pass — the refactor is behavior-preserving. - The `SelectProfile` helper is exercised indirectly through all existing callers. --------- Co-authored-by: simon <simon.faltum@databricks.com>
mihaimitrea-db
added a commit
that referenced
this pull request
Mar 12, 2026
The auth logout feature (PRs #4613, #4616, #4647) was squashed into a single commit cb3c326 titled after #4647 only, losing traceability for the new command itself. This followup: - Adds a comment block to logout.go linking each original PR with its commit range and purpose. - Adds a NEXT_CHANGELOG entry for auth logout under CLI. - Removes Hidden: true so the command appears in help and completion. - Aligns the Long description with the public documentation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🥞 Stacked PR
Use this link to review incremental changes.
Implement
databricks auth logoutwhich clears cached OAuth tokens for a profile and, optionally, removes the profile from ~/.databrickscfg.By default the command only clears tokens, requiring re-authentication on next use. Pass
--deleteto also remove the profile entry from the config file. This iteration supports explicit profile selection via--profileand a--forceflag to skip the confirmation prompt. Interactive profile selection will be added in a follow-up.Token cache cleanup is best-effort: the profile-keyed token is always removed, and the host-keyed token is removed only when no other profile references the same host.
Changes
databricks auth logoutcommand (cmd/auth/logout.go) registered under the auth command group.--profileselects the profile to log out of;--forceskips the confirmation prompt.--deleteopts in to removing the profile section from ~/.databrickscfg. Without it, only cached OAuth tokens are cleared.clearTokenCacheremoves the profile-keyed token and, if no other profile shares the same host, the host-keyed token. Host URLs are normalized (trailing slash stripped) to match token cache keys.DeleteProfileinlibs/databrickscfg/ops.goremoves a named section from ~/.databrickscfg, creating a .bak backup first.Why
There is currently no way to log out of a Databricks profile from the CLI. Users must manually edit ~/.databrickscfg and locate/delete token cache entries. This command provides a safe, single-step logout that handles token cleanup and optional profile removal.
Open issue from users requesting this feature: #1639
Tests
runLogoutcovering: successful logout, logout with--delete, non-interactive mode without--force, non-existent profile, shared-host token preservation, and logout with an empty token cache.DeleteProfilecovering: deleting an existing profile, profile not found, and custom config path.--profilein non-interactive mode.