Skip to content

fix: unbreak machine account login on macOS#147

Merged
scotwells merged 2 commits intomainfrom
fix/146-macos-keychain-size-limit
Apr 10, 2026
Merged

fix: unbreak machine account login on macOS#147
scotwells merged 2 commits intomainfrom
fix/146-macos-keychain-size-limit

Conversation

@scotwells
Copy link
Copy Markdown
Contributor

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

  • Machine account login now works on macOS.
  • The private key is stored in a 0600 file under the user's config directory (~/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.
  • Logging out removes both the keyring entry and the on-disk key file.
  • Existing sessions on Linux where the key still lived in the keyring keep working without any migration — the client reads from whichever location the key is in.

Fixes #146

Test plan

  • datumctl auth login --credentials ./my-key.json on macOS — completes without the keyring size error and leaves a working session
  • Subsequent datumctl commands 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
  • Existing Linux sessions created with v0.13.1 continue to refresh without re-login

🤖 Generated with Claude Code

scotwells and others added 2 commits April 10, 2026 16:30
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>
@scotwells scotwells merged commit a5fab73 into main Apr 10, 2026
2 checks passed
@scotwells scotwells deleted the fix/146-macos-keychain-size-limit branch April 10, 2026 22:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

auth login --credentials fails to save session on macOS: keyring size limit exceeded

2 participants