fix: unbreak machine account login on macOS#147
Merged
Conversation
The macOS Keychain has a per-item size limit (~4 KB). Machine account sessions exceeded it because StoredCredentials embedded a full PEM-encoded RSA private key alongside the access token, pushing the blob to ~5 KB. Logins would authenticate successfully but then fail with "data passed to Set was too big" when writing to the keyring, leaving no usable session behind. Store the PEM private key in a 0600 file under the user config directory and keep only a PrivateKeyPath pointer in the keyring blob. The access token continues to live in the OS keyring. Token refresh reads the PEM from disk on demand; logout removes the file alongside the keyring entry. Existing Linux sessions (where the PEM fit in the keyring inline) continue to work without migration: if PrivateKey is still set in the blob, it is used as-is; otherwise PrivateKeyPath is consulted. Fixes #146 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Enforce 0700 perms on existing machine-accounts directory, not just on first creation - Use os.CreateTemp for atomic writes so concurrent logins for the same machine account cannot race on the same .tmp filename - Remove the on-disk PEM if the keyring write fails during login, so failed logins don't leave crypto material behind - Also remove the PEM from disk in the logout "user not found but stray state" branch — this is the exact cleanup path users will hit after a failed #146 login - Use WrapUserErrorWithHint for the token refresh error paths to match the surrounding style; acknowledge in the hint that the original credentials file may no longer be available Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
kevwilliams
approved these changes
Apr 10, 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.
Summary
On macOS, logging in with a machine account credentials file authenticates successfully but then fails with
error: failed to store credentials in keyring ... data passed to Set was too big, leaving no usable session behind. Machine account logins are effectively broken on macOS today.The cause is a size limit on macOS Keychain items (~4 KB): the machine account session stored a full PEM-encoded RSA private key alongside the access token, pushing the blob over the limit. Interactive (browser) login doesn't hit this because it has no private key to store.
What changed for users
~/Library/Application Support/datumctl/machine-accounts/on macOS,~/.config/datumctl/machine-accounts/on Linux,%AppData%\datumctl\machine-accounts\on Windows). The access token continues to live in the OS keyring/keychain.Fixes #146
Test plan
datumctl auth login --credentials ./my-key.jsonon macOS — completes without the keyring size error and leaves a working sessiondatumctlcommands use the machine-account session (token refresh works after the initial token expires)datumctl auth logout <machine-account>removes the session and cleans up the on-disk key file🤖 Generated with Claude Code