auth: silently fall back to plaintext when keyring is unreachable on login#5181
Open
simonfaltum wants to merge 3 commits intomainfrom
Open
auth: silently fall back to plaintext when keyring is unreachable on login#5181simonfaltum wants to merge 3 commits intomainfrom
simonfaltum wants to merge 3 commits intomainfrom
Conversation
…login When secure storage is selected but the OS keyring is unreachable (no D-Bus on Linux, headless SSH session, locked keychain that hangs), databricks auth login now silently falls back to plaintext storage and writes auth_storage = plaintext to .databrickscfg so the choice is sticky for later commands. Mirrors the behavior of GitHub CLI. The probe runs before the browser step so users do not complete OAuth just to fail at the final Store call. Login is the only command that falls back: read paths (auth token, bundle commands) keep the original keyring error so they do not silently mint plaintext copies of tokens that live in the keyring on another machine. Co-authored-by: Isaac
Approval status: pending
|
Differentiate "I asked for secure" from "the default happens to be secure": when the user sets DATABRICKS_AUTH_STORAGE=secure or auth_storage = secure in .databrickscfg, honor it strictly. If the keyring fails the probe, return a clear error rather than silently downgrading to plaintext. The silent fallback now applies only when secure was the implicit default (no override flag, no env var, no config). In that case login still falls back and persists auth_storage = plaintext so subsequent commands route to the file cache without re-probing. Adds ResolveStorageModeWithSource so callers can detect explicit user choice. Splits the login-time policy into applyLoginFallback so it can be unit-tested across the (mode, explicit) input space directly. Co-authored-by: Isaac
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.
Why
Today, when secure storage is selected but the OS keyring is unreachable (no D-Bus on Linux, headless SSH, WSL1, locked keychain that hangs for 3s),
databricks auth loginerrors out and tells the user to setDATABRICKS_AUTH_STORAGE=plaintext. That is a hard wall for users who do not know in advance whether their environment has a working keyring, and the failure typically lands after the user has already completed the browser flow.The team agreed to aim for security by default, but do not block users when the keyring is not available.
Scope of this PR: silent fallback on the default path, sticky persistence in
.databrickscfg, an early-decision UX, and strict honoring of explicit secure choice. Telemetry and thedatabricks auth storage plaintextcommand are intentionally out of scope and tracked separately.Changes
Before:
databricks auth loginwith secure storage on a machine without a keyring fails with an error after OAuth, regardless of how secure was selected.Now:
databricks auth loginprobes the keyring before opening the browser. The behavior on probe failure depends on whether the user explicitly asked for secure:DATABRICKS_AUTH_STORAGE, noauth_storagein.databrickscfg, no flag): silently fall back to plaintext and persistauth_storage = plaintextto[__settings__]so subsequent commands skip the probe and route directly to the file cache.This avoids the divergence GPT 5.5 review caught: writing the token to file while leaving
auth_storage = securein config would makeauth tokenand bundle commands fail on the next call because they would still resolve to secure and hit the unreachable keyring.Implementation:
storage.ProbeKeyring()performs a write+delete cycle with the existing 3s timeout to detect a usable keyring without leaving stray entries.storage.ResolveStorageModeWithSource()returns the resolved mode plus whether it came from an explicit user choice (override / env / config) versus the default.storage.ResolveCacheForLogin()wraps the resolver. For default-secure + probe failure it falls back and writes config; for explicit-secure + probe failure it returns an error; for any non-secure mode it skips the probe entirely.databrickscfg.SetConfiguredAuthStorage()writes the key under[__settings__], mirroringSetDefaultProfile.cmd/auth/login.goswapsResolveCacheforResolveCacheForLogin. Read paths (auth token, bundle commands) keep the original keyring error so they do not silently mint plaintext copies of tokens that live in the keyring on another machine.Test plan
ProbeKeyringsuccess cleans up after itself; Set/Delete error and Set timeout each propagate.ResolveStorageModeWithSourcereturnsexplicit=falsefor default andexplicit=truefor override / env / config.applyLoginFallbackfalls back and persistsauth_storage = plaintextfor default-secure + probe fail.applyLoginFallbackreturns a "secure storage was requested" error for explicit-secure + probe fail, and does not write config.resolveCacheForLoginWitherrors out for explicit secure (env, config, override) when the probe fails.SetConfiguredAuthStoragecreates the file/section as needed and preservesdefault_profile../task checksclean./task lint-q0 issuescmd/auth,libs/auth/storage,libs/databrickscfgunit tests passacceptance/cmd/auth/storage-modesandacceptance/cmd/auth/loginacceptance tests still passThis pull request and its description were written by Isaac.