Repository navigation
Split access tokens that don't fit in one OS keyring item - #7845
simonfaltum wants to merge 6 commits into
Conversation
databricks auth login failed on macOS and Windows with "store token: data passed to Set was too big" when the OAuth access token did not fit in one OS keyring item (#7707). The keyring store now splits such a token: the item under the cache key keeps the token without its access token, the part count and the access token's SHA-256, and the access token goes into 2048-byte parts under <key>#access-token-<n>. The item with the refresh token is written first. A missing or mismatched part returns the token without an access token, so that it is refreshed. Delete removes every part, and auth login rejects profile names that contain #access-token-. A token that fits is stored exactly as before. Co-authored-by: Isaac <no-reply@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
|
Commit: Regression test reportSelected 1 changed tests (limit=20, 0 not selected) 1 tests: regression=1 unreleased=0 coverage=0 failing=0
TestAccept/cmd/auth/login/device-code/non-interactive/errors: branch ✅ | main (36fdeb1) ❌ | latest (v1.27.0) ❌main (36fdeb1): latest (v1.27.0): same output as main (36fdeb1) |
✅ Integration test reportCommit: a83d3a7
Top 3 slowest tests (at least 2 minutes):
|
|
/review |
There was a problem hiding this comment.
Automated review at 6bc858e. Each finding was verified against the code.
No blocking issues found.
This PR adds multi-item keyring storage for OAuth access tokens that exceed OS keyring item size limits on macOS and Windows, fixing databricks auth login failures with store token: data passed to Set was too big. The implementation is careful: the refresh token is written first, a SHA-256 hash guards against torn reads, and tokens that fit in one item stay in the format older CLI versions understand. The code is well tested across both fake and real OS keyring backends, with coverage for size transitions, partial failures, and backward compatibility. No concrete defects were found.
Lookup reads a split entry again (25 ms doubling, 5 attempts) when its access token parts are missing or do not match, so a reader that catches another process writing or deleting the entry neither refreshes with a refresh token that process already used up nor restores a deleted login. Delete counts the parts and deletes them from the last, so a Delete that fails part way leaves parts that the next one still finds. A refresh whose part write fails still succeeds when the store kept the new refresh token: recoverStoreUpdate accepts that partial update, so losing the access token only costs the next command a refresh. auth login rejects #access-token- in any letter case, because Windows Credential Manager ignores case in credential names. On macOS, zalandoBackend rejects a secret that go-keyring is sure to reject without calling it, because go-keyring starts `security -i` before its size check and leaves the process unreaped. keyringEntry embeds a struct that Entry converts to and from again, so a field added to Entry cannot be dropped silently. Also: string slicing in putSplit, doc comments, the service name constant in the new tests, and the original wording of the comments from #7727 except where they became wrong. Co-authored-by: Isaac <no-reply@databricks.com>
The keyring store's Put now wraps a failed access token part write in storage.ErrAccessTokenNotStored, after the entry with the refresh token was stored. PersistentAuth.refresh treats that error as stored and logs it at debug level, instead of recoverStoreUpdate guessing the state from the store's contents, which also matched a Put that wrote nothing when the server does not rotate refresh tokens. recoverStoreUpdate is back to its original form. A split entry now keeps every Entry field, not only the token, so the compile-time Entry mirror holds for both layouts. The Store and Entry docs say what the keyring store does differently. Also: the macOS fd test runs first in its file and requires an equal count, with a named helper instead of a closure; doc comment and wording fixes. Co-authored-by: Isaac <no-reply@databricks.com>
Lookup now waits splitLookupDelay when the store sets no retry delay, so a keyring store built without one still gives a concurrent writer time to finish, and a test pins that schedule. auth login keeps failing on storage.ErrAccessTokenNotStored, unlike a refresh: a comment says why. The new debug line uses libs/log, validateLoginProfileName keeps its original sentence, and TestDarwinCommandTooBig uses require. Co-authored-by: Isaac <no-reply@databricks.com>
There was a problem hiding this comment.
Automated review at 8ba8b84. Each finding was verified against the code.
No blocking issues found. 2 non-blocking comment(s) below.
This PR splits oversized OAuth access tokens across multiple OS keyring items so that databricks auth login works on macOS and Windows when a token exceeds the single-item limit. The implementation is thorough: it stores the refresh token first for safety, verifies reassembled parts with SHA-256, retries on concurrent writes, and cleans up parts on delete. The test coverage is extensive across both fake and real backends. I found only minor style issues; no correctness bugs survived verification.
| // openFileCount returns the number of files this process has open. | ||
| func openFileCount(t *testing.T) int { | ||
| t.Helper() | ||
| entries, err := os.ReadDir("/dev/fd") |
There was a problem hiding this comment.
[nit] openFileCount reads /dev/fd, which doesn't exist on Windows, but this file's build constraint is darwin || windows. The sole caller skips on non-darwin, so nothing breaks today, but a future Windows test in this file that calls openFileCount would fail at runtime with no compile-time hint. Moving the function (and TestZalandoBackend_Set_RejectsLargeSecretWithoutSecurityProcess) into a //go:build darwin-only file would prevent that.
There was a problem hiding this comment.
Moved the test and openFileCount to keyring_darwin_test.go in a83d3a7, so the /dev/fd read only builds on macOS. That file still sorts before the one with TestKeyringSet_RejectsLargeSecret, so the test keeps running first.
| RefreshToken: "first", | ||
| Expiry: time.Now().Add(-time.Minute), | ||
| }}) | ||
| if err != nil { |
There was a problem hiding this comment.
[nit] This new file uses t.Fatalf/t.Errorf throughout (lines 52, 59, 80, 86, 90, 98, …) instead of require/assert, which the testing rule prescribes. The same applies to the new tests in persistent_auth_test.go (TestToken_RefreshesTokenWithoutAccessToken, TestToken_RefreshesWithRefreshTokenStoredByFailedStoreUpdate). The pre-existing code in persistent_auth_test.go uses the same bare-testing style, so this is locally consistent, but other new test files in this PR (logout_keyring_os_test.go, keyring_size_limit_os_test.go) already use testify. Worth aligning the new file at least, or not — your call.
There was a problem hiding this comment.
Switched the new file to require/assert in a83d3a7. I kept persistent_auth_test.go, including its two new tests, in the t.Fatalf style the rest of that file uses.
…2m keychain test openFileCount reads /dev/fd, which Windows lacks, so the test and its helper now live in keyring_darwin_test.go instead of a darwin || windows file. The new u2m real-keychain test uses require and assert like the other new tests. Co-authored-by: Isaac <no-reply@databricks.com>
Changes
databricks auth loginfails on macOS and Windows withstore token: data passed to Set was too bigwhen the OAuth access token doesn't fit in one OS keyring item, and later commands then fail because the new refresh token was never stored. Fixes #7707. A token that doesn't fit is now stored across several items; a token that fits is stored exactly as before.<key>#access-token-<n>in the samedatabricks-cliservice.Lookupreads again for up to about 375 ms, in case another process is writing or deleting them, and then returns the token without an access token, whichPersistentAuth.Token()refreshes.Delete, and soauth logout, removes every part, the last one first, so that an interrupted logout leaves parts the next one finds.auth loginrejects profile names that contain#access-token-in any letter case (Windows Credential Manager ignores case).security -ibefore its size check and leaves the process behind.Why
Windows Credential Manager caps a credential at 2560 bytes, and go-keyring's macOS backend base64-encodes the entry into one
security -iline of at most 4096 bytes. One item therefore holds an access token of about 2.8 KB on macOS and 2.4 KB on Windows; the refresh token is only 36 bytes. The tokens in #7707 are about 3,250 bytes.Decisions to review
tokenfrom a split entry: not nil, because releases before v1.24 dereference it, and without the refresh token, because they would rotate it and then fail to store the result. They fail withtoken refresh: cached token has no refresh token, which asks for a new login.Deletemakes one extra call. Parts stay behind when a token shrinks or an older version logs out, until the nextDelete. A profile that an older version saved with#access-token-in its name can collide with another profile's parts.Tests
Delete, size changes on one key, and part errors and timeouts. Also a refresh without an access token and after a failed part write, the reserved name in any case at--profile(acceptance) and at the prompt, andTestDarwinCommandTooBig.Deletekeeping parts or starting from the first, a nil or refresh-carrying top-leveltoken, 4096-byte parts, and more) fails a named test.CIis set): round trips, a token that fits staying one item, size changes, the one-item boundary, a refresh throughPersistentAuth, andauth logout(TestKeyringStore_RealBackend_*,TestToken_RefreshesLargeTokenInOSKeyring,TestLogoutRemovesSplitTokenFromOSKeyring). On macOS,TestZalandoBackend_Set_RejectsLargeSecretWithoutSecurityProcesschecks that rejecting a large secret leaves nosecurityprocess behind../task testand lint for linux, darwin and windows pass.This pull request and its description were written by Isaac.