You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(dpapi): add secret store for windows (#000) - #245
Prepares moving the agent token from the config file into an OS secret store.
flowchart TD
S[Agent start] --> P{OS secret store<br/>and production?}
P -- no --> C[ConfigStore: token read<br/>from the config file]
P -- yes --> T{Token in the<br/>config file?}
T -- yes --> I["import(): save in the store,<br/>remove the config line"]
T -- no --> R[Read the token back once]
I --> R
R --> O[Use the OS store]
I -. error .-> X[Log the error, stop the agent]
R -. error .-> X
Loading
Changes
SecretStore::set, and import(): saves the config token in the OS store, then removes the [openaev].token line with toml_edit. Comments and formatting are kept, and the file is rewritten in place, so it keeps its ACL.
secrets::open() uses the OS store in production when the platform has one, and ConfigStore otherwise. There is no configuration key.
Any OS store error (saving the token, removing the line, reading it back) is logged and stops the agent, with a message asking to reinstall it.
The token is optional in the config file. ConfigStore logs an error when it is missing.
Windows service-user installer: the service account gets read and write access on the config file, so the agent can remove the token line.
Impact
New dependency: toml_edit. Its own dependencies are already in the tree through config.
Limitations
Windows service-user agents upgraded by exe swap keep a read-only config file.
The config file is rewritten in place: if the write is interrupted, the agent must be reinstalled.
Linux and macOS keep the token in the config file until their OS stores are added.
❌ Patch coverage is 68.42105% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 41.63%. Comparing base (5239fd8) to head (b0d79b9).
❌ Your patch check has failed because the patch coverage (68.42%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.
Test import rollback when credential read-back fails or mismatches
src/secrets/import.rs:80
The import tests cover a failed set, but not a successful set followed by a failed or mismatching read-back. Add a test store for each case and assert that import returns an error while leaving both the config and bootstrap contents unchanged. These tests protect the check that prevents deletion of the only usable credential copy.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
An unresolved pending-token guard and security-sensitive Windows recovery behavior require correction and platform-specific human validation.
No open issues 🎉
1 previously missed issue
In code that hasn't changed since last review
Return an error when pending token has no verification source
src/secrets/import.rs:94
If a pending marker remains but the bootstrap/config token is no longer available, this branch only logs and import() returns Ok(()), even though it rejected the stored token as unverified. Once an OS store is enabled, open() interprets that success as permission to use the store, so requests can use the unverified value. Return an error for this pending-without-source case and add a regression test with a readable stored token, a pending marker, and no clear-text token. No OS store is enabled in this PR, so this currently affects the migration helper rather than live requests.
Since #245, import() refuses to write the config token when the store
returns a read error, and only writes it when the token is missing.
DpapiStore reported a missing or empty file (the empty file the installer
creates) as a generic error, so older installs with the token only in
the config could never be migrated.
DpapiStore::get now uses missing() for a missing or empty file. A file
that cannot be decrypted is still a read error.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Since #245, import() refuses to write the config token when the store
returns a read error, and only writes it when the token is missing.
DpapiStore reported a missing or empty file (the empty file the installer
creates) as a generic error, so older installs with the token only in
the config could never be migrated.
DpapiStore::get now uses missing() for a missing or empty file. A file
that cannot be decrypted is still a read error.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The reason will be displayed to describe this comment to others. Learn more.
Seen together
Redesign general flow:
remove the explicit os_store config key; encapsulate nominal nehaviour and fallback into respective implementations (e.g. DpApiStore)
remove bootstrap/pending recovery mechanism: if the token is invalid (rejected by server) or the encryption and retrieval flow failed, this is a major error that would mandate reinstalling the agent from scratch after solving the issue
Handle the upgrade path, whenever this happens a new cleartext token is written to the toml file, and must be migrated away; handle this at agent process start, with the selected SecretStore implementation
At agent start (once), the agent picks one store for the whole run:
Windows (DPAPI): if the config file holds a token, it is saved in DPAPI, then its line is removed from the file. The token is then read back once from DPAPI. On any error, the agent logs it and stops (it must be reinstalled).
Linux / macOS: no OS store yet, so the token stays in the config file.
On each request (ping, job polling and job cleaning): the token is read from the chosen store (DPAPI or the config file).
When the token changes: it always arrives through the config file (installation, reinstallation or upgrade). At the next start, it replaces the token stored in DPAPI.
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
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.
Proposed changes
Prepares moving the agent token from the config file into an OS secret store.
flowchart TD S[Agent start] --> P{OS secret store<br/>and production?} P -- no --> C[ConfigStore: token read<br/>from the config file] P -- yes --> T{Token in the<br/>config file?} T -- yes --> I["import(): save in the store,<br/>remove the config line"] T -- no --> R[Read the token back once] I --> R R --> O[Use the OS store] I -. error .-> X[Log the error, stop the agent] R -. error .-> XChanges
SecretStore::set, andimport(): saves the config token in the OS store, then removes the[openaev].tokenline withtoml_edit. Comments and formatting are kept, and the file is rewritten in place, so it keeps its ACL.secrets::open()uses the OS store in production when the platform has one, andConfigStoreotherwise. There is no configuration key.ConfigStorelogs an error when it is missing.Impact
toml_edit. Its own dependencies are already in the tree throughconfig.Limitations
Testing Instructions
Related issues
Checklist
Further comments
toml_edit,windows-sys.