auth: import FileTokenCache into CLI and wire DualWrite#5056
Open
simonfaltum wants to merge 2 commits intomainfrom
Open
auth: import FileTokenCache into CLI and wire DualWrite#5056simonfaltum wants to merge 2 commits intomainfrom
simonfaltum wants to merge 2 commits intomainfrom
Conversation
First of a three-PR sequence that moves file-based OAuth token cache management from the SDK to the CLI. This PR adds a CLI-local copy of FileTokenCache under libs/auth/storage, a DualWrite helper that mirrors the SDK's historical dualWrite + hostCacheKey convention, wires u2m.WithTokenCache at every NewPersistentAuth call site (including CLICredentials, which is used by every non-auth command), and switches auth logout to the CLI FileTokenCache for token removal. The SDK is unchanged so behavior is byte-for-byte identical: two redundant writes to the same file with the same keys and tokens. See documents/fy2027-q2/cli-ga/2026-04-21-move-token-cache-to-cli-plan.md.
Approval status: pending
|
CLI's forbidigo rules forbid os.UserHomeDir (use env.UserHomeDir) and os.IsNotExist (use errors.Is(err, fs.ErrNotExist)). Thread ctx through NewFileTokenCache so the env-based home directory lookup works. Co-authored-by: Isaac
simonfaltum
added a commit
that referenced
this pull request
Apr 22, 2026
The file factory was calling the SDK's cache.NewFileTokenCache(), which is being phased out in favor of the CLI's own storage.NewFileTokenCache(ctx) imported in #5056. Route ResolveCache through it so that legacy and plaintext modes share a single file cache implementation owned by the CLI. Co-authored-by: Isaac
This was referenced Apr 22, 2026
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.
Stack
Entry point for the opt-in secure token storage work. Review and merge top-to-bottom:
This PR is also the first of a separate 3-PR sequence that moves file token cache ownership from the SDK to the CLI. That sequence (SDK PR removing the internal dual-write, then SDK bump in the CLI) can proceed in parallel with #5008 and #5013.
Why
First of 3 PRs moving file-based OAuth token cache ownership from the Go SDK to the CLI. Today the SDK owns both the cache interface and the file-backed implementation, including the dual-write-under-host-key convention. Long-term we want the SDK to stop owning persistence: the OAuth flow and cache interface stay, but file format and host-key conventions move to the CLI. This unblocks secure storage backends and Renaud's Session model on a cleaner foundation.
This PR imports the cache into the CLI and wires it everywhere. Nothing is deleted from the SDK yet. PRs 2 and 3 (SDK PR, then SDK bump) finish the move.
Changes
Before: CLI relied on the SDK's default
FileTokenCache. Dual-write to the legacy host-based key happened insidePersistentAuth.Challenge()andrefresh()via the SDK's internaldualWrite.Now: CLI owns its own
FileTokenCacheatlibs/auth/storage/file_cache.go, a near-verbatim copy from the SDK (same JSON schema, same path~/.databricks/token-cache.json, same permissions). A newstorage.DualWrite(cache, arg, token)helper centralises the dual-write convention. Everyu2m.NewPersistentAuthcall site in the CLI now passesu2m.WithTokenCache(...).The SDK is unchanged. It still dual-writes internally, so the two writes hit the same file with the same keys and bytes, i.e. idempotent. Zero user-visible behavior change.
Files touched:
libs/auth/storage/file_cache.go+ test (new)libs/auth/storage/dualwrite.go+ test (new)cmd/auth/login.go,cmd/auth/token.go,cmd/auth/logout.golibs/auth/credentials.goNEXT_CHANGELOG.mdLint-driven deltas from SDK:
os.UserHomeDir()is forbidden in the CLI, usesenv.UserHomeDir(ctx)instead. Required threadingctxthroughNewFileTokenCache.os.IsNotExist(err)is forbidden, useserrors.Is(err, fs.ErrNotExist).Known edge case: Tokens that exist only under the legacy host key (users who logged in before profile-keyed writes existed and never re-ran
auth login --profile) keep working for now because the SDK's internal dualWrite still runs. After PR 2 (SDK stops dual-writing), re-login will be required for those users. Minimal impact.Test plan
file_cache_test.go(port of SDK tests)dualwrite_test.gocovering no host-key provider, distinct host key, host-key-equals-primary, discovery with populated/emptyGetDiscoveredHostmake checksandmake testpassdatabricks auth login,auth token,auth logouton a live profile before merging