feat(credential_store): default keyring backend to OS-only, add keyring-with-file option#488
feat(credential_store): default keyring backend to OS-only, add keyring-with-file option#488cross32768 wants to merge 3 commits intogoogleworkspace:mainfrom
Conversation
🦋 Changeset detectedLatest commit: d69a5e3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly refines the encryption key storage strategy by modifying the default behavior of the Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a significant security improvement by changing the default keyring backend to store the encryption key exclusively in the OS keyring, avoiding writing it to disk. The previous behavior is preserved under a new keyring-with-file backend. The changes are well-structured, with clear separation of concerns and extensive test coverage for the new logic paths.
I've found one potential critical issue related to race condition handling when a key file is created, which could lead to inconsistent state between processes. My feedback includes a suggestion to make the race-handling logic safer and more consistent.
a34f480 to
e7a3840
Compare
|
/gemini review |
…ng-with-file option
e7a3840 to
33adcde
Compare
There was a problem hiding this comment.
Code Review
This pull request refactors the credential store to change the default behavior of the keyring backend. It will now store the encryption key exclusively in the OS keyring, enhancing security on platforms with hardware-backed keychains. The previous behavior of syncing the key to a file is preserved under a new keyring-with-file backend. The changes are well-implemented and include comprehensive updates to documentation and tests.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the credential storage to make the OS keyring the default, exclusive backend, which is a great security improvement. A new keyring-with-file option is introduced to maintain the old behavior for users who need it. The changes are well-documented and thoroughly tested.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request is a significant improvement to the credential store's security by defaulting the keyring backend to OS-only storage, preventing the encryption key from being written to disk unnecessarily. The introduction of the keyring-with-file option provides a good backward-compatibility path for users who need a file backup. The logic is well-structured and the accompanying tests are thorough. I've identified one critical issue related to non-atomic file writes that could lead to key file corruption, which I've detailed in a review comment.
…uption on crash (Address review feedback from gemini-code-assist)
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a significant and valuable security enhancement by changing the default keyring backend to store the encryption key exclusively in the OS keyring, avoiding writing it to disk. A new keyring-with-file option is added for users who need the previous file-backup behavior. The implementation includes making key file writes atomic, which improves robustness. The changes are well-documented and accompanied by a comprehensive set of new tests. However, I've found a critical race condition in the error recovery logic that could lead to key loss, which needs to be addressed.
Description
PR #373 enabled native OS keyring backends (
apple-native,windows-native), but thekeyringbackend still unconditionally writes the encryption key to~/.config/gws/.encryption_keyon every run. This means the AES-256-GCM encryption ofcredentials.encis only as strong as file permissions (0600), even on platforms where the OS keychain provides hardware-backed protection (macOS Keychain via Secure Enclave, Windows Credential Manager).This PR changes the default
keyringbackend to store the encryption key exclusively in the OS keyring, and introduces a newkeyring-with-filevalue that preserves the previous behavior for users who want a durable file backup.GOOGLE_WORKSPACE_CLI_KEYRING_BACKENDvalues.encryption_keyfilekeyring(default)keyring-with-filefileMigration
.encryption_keyfile: on first run, the key is read from the file and copied into the OS keyring. A note is printed suggesting the user remove the file for keyring-only security.GOOGLE_WORKSPACE_CLI_KEYRING_BACKEND=keyring-with-fileto restore the previous behavior.filebackend is unchanged.Note on backward compatibility
This changes the default behavior:
.encryption_keyis no longer written to disk under thekeyringbackend. If this is a concern given the history of keyring reliability issues (#344, #359, #360, #373), an alternative approach would be to keep the current default as-is and add a separatekeyring-onlyvalue for opt-in keyring-exclusive storage. Happy to adjust the naming/defaults if that direction is preferred.Checklist:
AGENTS.mdguidelines (no generatedgoogle-*crates).cargo fmt --allto format the code perfectly.cargo clippy -- -D warningsand resolved all warnings.pnpx changeset) to document my changes.