Skip to content

feat(dpapi): add secret store for windows (#000) - #245

Open
Stephanya Casanova (savacano28) wants to merge 1 commit into
sca/agent-secret-storefrom
sca/secret-store-with-import
Open

Stephanya Casanova (savacano28) wants to merge 1 commit into
sca/agent-secret-storefrom
sca/secret-store-with-import

Conversation

@savacano28

@savacano28 Stephanya Casanova (savacano28) commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

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 .-> 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.

Testing Instructions

  1. Same steps as feat(agent): read the token on each request instead of keeping it in memory (#000) #239

Related issues

Checklist

  • I consider the submitted work as finished
  • I tested the code for its functionality
  • I wrote test cases for the relevant uses case
  • I added/update the relevant documentation (either on github or on notion)
  • Where necessary I refactored code to improve the overall quality
  • For bug fix -> I implemented a test that covers the bug

Further comments

  • New deps: toml_edit, windows-sys.

@savacano28
Stephanya Casanova (savacano28) changed the base branch from main to sca/agent-secret-store October 18, 2026 15:47
@codecov

codecov Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ 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).

Files with missing lines Patch % Lines
src/secrets/mod.rs 0.00% 14 Missing ⚠️
src/main.rs 0.00% 3 Missing ⚠️
src/secrets/import.rs 96.66% 1 Missing ⚠️

❌ 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.

Additional details and impacted files

Impacted file tree graph

@@                    Coverage Diff                     @@
##           sca/agent-secret-store     #245      +/-   ##
==========================================================
+ Coverage                   39.51%   41.63%   +2.11%     
==========================================================
  Files                          14       15       +1     
  Lines                         744      795      +51     
==========================================================
+ Hits                          294      331      +37     
- Misses                        450      464      +14     
Flag Coverage Δ
agent 41.63% <68.42%> (+2.11%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/config/settings.rs 64.15% <ø> (ø)
src/secrets/config_store.rs 88.88% <100.00%> (ø)
src/secrets/import.rs 96.66% <96.66%> (ø)
src/main.rs 0.00% <0.00%> (ø)
src/secrets/mod.rs 0.00% <0.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@savacano28 Stephanya Casanova (savacano28) changed the title feat(dpapi): add secret store with import for dpapi feat(dpapi): add secret store with import for dpapi (#1) Oct 18, 2026
@savacano28
Stephanya Casanova (savacano28) marked this pull request as ready for review October 19, 2026 07:10
Copilot AI balanced review requested due to automatic review settings October 19, 2026 07:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Migration can overwrite newer stored tokens, and Windows replacement failure cleanup can delete the configuration.

2 open issues
What changed in this PR

Adds token-migration groundwork for OS secret stores while keeping production on clear-text storage until an OS backend is connected.

Changes:

  • Reads bootstrap tokens before config tokens and makes config tokens optional.
  • Adds verified migration, clear-text cleanup, and permission-preserving file replacement.
  • Adds migration and replacement tests and supporting dependencies.
File Description
src/​tests/​secrets/​replace_tests.rs Tests replacement, permissions, and failure handling.
src/​tests/​secrets/​mod.rs Adds writable store doubles and test modules.
src/​tests/​secrets/​import_tests.rs Tests migration precedence and cleanup.
src/​tests/​secrets/​config_store_tests.rs Tests bootstrap reads and precedence.
src/​tests/​config/​settings_tests.rs Tests optional config tokens.
src/​secrets/​replace.rs Adds platform-specific file replacement.
src/​secrets/​mod.rs Adds migration setup and bootstrap reading.
src/​secrets/​import.rs Implements verified token migration and cleanup.
src/​secrets/​config_store.rs Reads bootstrap tokens before config tokens.
src/​main.rs Passes the startup token into store initialization.
src/​config/​settings.rs Makes tokens optional and adds path helpers.
Cargo.toml Adds TOML editing and Windows API dependencies.
Cargo.lock Locks the added dependencies.

Review effort: Balanced

Comment thread src/secrets/import.rs Resolved
Comment thread src/secrets/replace.rs Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Windows migration recovery can block restart or leave plaintext backups once migration is enabled.

2 open issues
1 previously missed issue

In code that hasn't changed since last review

Medium severity 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.

2 resolved since last review

Review effort: Balanced

Comment thread src/secrets/import.rs Resolved
Comment thread src/secrets/replace.rs Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Retrying a config-only import after failed verification can delete the only valid token.

1 open issue
2 resolved since last review

Review effort: Balanced

Comment thread src/secrets/import.rs Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Unresolved migration-safety issues and cross-platform credential cleanup require fixes and human validation.

2 open issues
1 resolved since last review

Review effort: Balanced

Comment thread src/secrets/import.rs Resolved
Comment thread src/secrets/import.rs Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Medium severity 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.

2 resolved since last review

Review effort: Balanced

Stephanya Casanova (savacano28) added a commit that referenced this pull request Oct 19, 2026
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>
Stephanya Casanova (savacano28) added a commit that referenced this pull request Oct 19, 2026
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>
@savacano28
Stephanya Casanova (savacano28) force-pushed the sca/secret-store-with-import branch 2 times, most recently from 158faf2 to 06a5f31 Compare October 19, 2026 15:49

@damgouj damgouj (damgouj) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok for me but please create 2 issues for the future :

  • 1 issue to clear the code when all the agents will be updated with the store
  • 1 issue if it's possible to not set the token to the toml through the installers but directly to the stores

@antoinemzs antoinemzs left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seen together

Redesign general flow:

  1. remove the explicit os_store config key; encapsulate nominal nehaviour and fallback into respective implementations (e.g. DpApiStore)
  2. 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
  3. 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

Comment thread src/config/settings.rs Resolved
@savacano28 Stephanya Casanova (savacano28) changed the title feat(dpapi): add secret store with import for dpapi (#1) feat(dpapi): add secret store for windows Nov 10, 2026
@savacano28 Stephanya Casanova (savacano28) changed the title feat(dpapi): add secret store for windows feat(dpapi): add secret store for windows (#330) Nov 10, 2026
@savacano28 Stephanya Casanova (savacano28) changed the title feat(dpapi): add secret store for windows (#330) feat(dpapi): add secret store for windows (#0000) Nov 10, 2026
@savacano28 Stephanya Casanova (savacano28) changed the title feat(dpapi): add secret store for windows (#0000) feat(dpapi): add secret store for windows (#000) Nov 10, 2026
@savacano28

Stephanya Casanova (savacano28) commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi antoinemzs, I've updated the pr:

How it works

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

filigran team Item from the Filigran team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants