feat(config): store API keys in OS keychain instead of plaintext#2480
Open
officialasishkumar wants to merge 1 commit intocharmbracelet:mainfrom
Open
feat(config): store API keys in OS keychain instead of plaintext#2480officialasishkumar wants to merge 1 commit intocharmbracelet:mainfrom
officialasishkumar wants to merge 1 commit intocharmbracelet:mainfrom
Conversation
API keys and OAuth tokens are now stored in the operating system's native keychain (macOS Keychain, Windows Credential Manager, Linux Secret Service) instead of plaintext in crush.json. Existing plaintext keys are automatically migrated to the keychain on first load. A placeholder marker (__keyring__) is written to the JSON config file so the config system still recognizes that a provider is configured. When the keychain is unavailable (headless servers, CI, containers), the system falls back to file-based storage with a warning. Set CRUSH_DISABLE_KEYRING=1 to force file-based storage. Closes charmbracelet#2477 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
d30c2b3 to
5f0db27
Compare
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.
This pull request introduces secure credential storage using the operating system's keychain, migrating API keys and OAuth tokens out of plaintext JSON config files where possible. The main changes include the addition of a
KeyringStoreabstraction, automatic migration of existing credentials to the OS keychain, updates to the configuration logic to leverage secure storage, and improved user messaging about where credentials are stored.Secure credential storage and migration:
internal/config/keyring.go, implementingKeyringStorefor storing API keys and OAuth tokens in the OS keychain (macOS Keychain, Windows Credential Manager, or Linux Secret Service), with logic to detect availability and fall back to file-based storage if needed. ([internal/config/keyring.goR1-R156](https://github.com/charmbracelet/crush/pull/2480/files#diff-f36b46e3dd70e8c116136433c381b610392ed6e6d61f6a5ed7076f7f3851945aR1-R156))Ff75ee58L169R169,Ff75ee58L332R332,Ff75ee58L863R863)Configuration logic and API changes:
ConfigStoreto use the keyring for storing and retrieving provider credentials, including new helper methods for persisting API keys and OAuth tokens securely. (Fd22d490L167R167,Fd22d490L265R265,Fd22d490L333R333)[internal/cmd/login.goL114-R114](https://github.com/charmbracelet/crush/pull/2480/files#diff-1e6a22c2133efaeb4e774b02902eaeacea5b7999c4a33c8f909471e6342b7addL114-R114),Fc0b836bL174R174,Fd22d490L167R167,Fd22d490L265R265,Fd22d490L333R333)User experience improvements:
[internal/ui/dialog/api_key_input.goR172-R182](https://github.com/charmbracelet/crush/pull/2480/files#diff-b06a1c11c12e59d8b4b2fd564b34a81445c41cdd2ee9390a31c9c0776665d629R172-R182))Dependency and plumbing updates:
github.com/zalando/go-keyring,github.com/danieljoos/wincred) ingo.mod. ([go.modR64](https://github.com/charmbracelet/crush/pull/2480/files#diff-33ef32bf6c23acb95f5902d7097b7a1d5128ca061167ec0716715b0b9eeaa5f6R64),F4ac52a9L106R106)[[1]](https://github.com/charmbracelet/crush/pull/2480/files#diff-8444bfa4415d597e85ba47f294904015a6a49089e5ed5f7e613c0410b749f7f5R49),[[2]](https://github.com/charmbracelet/crush/pull/2480/files#diff-4aa2cb4ec8ace243da263207905baec16af83599529dc56d987049854ee9dea9R31),Fd22d490L59R59)These changes significantly improve the security of credential storage in the application by leveraging the user's OS keychain when available, while maintaining compatibility with environments where secure storage is not possible.
Closes #2477
CONTRIBUTING.md.