Skip to content

feat(agent): read the token on each request instead of keeping it in memory (#000) - #239

Open
Stephanya Casanova (savacano28) wants to merge 13 commits into
mainfrom
sca/agent-secret-store
Open

Stephanya Casanova (savacano28) wants to merge 13 commits into
mainfrom
sca/agent-secret-store

Conversation

@savacano28

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

Copy link
Copy Markdown
Contributor

Proposed changes

The agent now reads its token through a SecretStore on each request, instead of keeping a copy in each thread for the whole run. First step towards storing the token in the OS secret store (#245 and #240 build on it).

flowchart LR
  T[Ping / jobs thread] --> C["Client.post / delete"]
  C --> S["SecretStore.get(token)"]
  S --> F[(config file)]
  S -. unreadable .-> E["Safe error, logged once<br/>no request sent"]
  C --> H["Bearer header<br/>wiped after the request"]
Loading

Changes

  • SecretStore trait and ConfigStore, which reads the token from the config on each call.
  • Client holds the store; post and delete return Result and send nothing if the token cannot be read.
  • The Authorization header owns a Zeroizing buffer, wiped after the request, and is marked sensitive.
  • OpenAEV.token is Zeroizing, and printing the settings shows <redacted>.
  • SettingsSource (the config location only) is shared by start-up and ConfigStore. Config errors are logged once, with a reason that never quotes the token.

Impact

  • Nothing changes on disk or in the installers.
  • A token changed in the config is used at the next request, without a restart.
  • New dependencies: bytes, zeroize.

Limitations

Testing Instructions

Build the branch and install the agent in one mode per OS. On Windows, run the NSIS installer directly, since branch builds aren't release-signed. Then check each row:

Automated: cargo test --locked

Manual (Windows Sandbox, build this branch, then run the NSIS installer directly):

  1. Install the agent (service mode) → it shows online and an inject works.
  2. Search openaev-agent.log for the token → not found.
  3. While the agent runs, set a wrong token in the config → calls fail. Put the right one back → the agent is online again without restart.
  4. Swap the exe of an agent installed from the current release → still online.

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

  • Impact for users: none. Same files, same installers, same behaviour. A changed token in the config is now used without a restart.
  • Limit: the HTTP/TLS libraries and the config loader keep their own copies of the token, which the agent can't wipe. The token is still in clear text on disk;

@codecov

codecov Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 63.91753% with 35 lines in your changes missing coverage. Please review.
✅ Project coverage is 39.51%. Comparing base (d01065f) to head (5239fd8).

Files with missing lines Patch % Lines
src/config/settings.rs 53.33% 14 Missing ⚠️
src/api/mod.rs 81.48% 5 Missing ⚠️
src/main.rs 0.00% 3 Missing ⚠️
src/secrets/config_store.rs 88.88% 3 Missing ⚠️
src/secrets/mod.rs 0.00% 3 Missing ⚠️
src/api/manage_jobs.rs 0.00% 2 Missing ⚠️
src/process/agent_job.rs 0.00% 2 Missing ⚠️
src/process/keep_alive.rs 0.00% 2 Missing ⚠️
src/api/register_agent.rs 0.00% 1 Missing ⚠️

❌ Your patch check has failed because the patch coverage (63.91%) 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             @@
##             main     #239      +/-   ##
==========================================
+ Coverage   32.05%   39.51%   +7.45%     
==========================================
  Files          12       14       +2     
  Lines         680      744      +64     
==========================================
+ Hits          218      294      +76     
+ Misses        462      450      -12     
Flag Coverage Δ
agent 39.51% <63.91%> (+7.45%) ⬆️

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

Files with missing lines Coverage Δ
src/api/register_agent.rs 0.00% <0.00%> (ø)
src/api/manage_jobs.rs 0.00% <0.00%> (ø)
src/process/agent_job.rs 0.00% <0.00%> (ø)
src/process/keep_alive.rs 0.00% <0.00%> (ø)
src/main.rs 0.00% <0.00%> (ø)
src/secrets/config_store.rs 88.88% <88.88%> (ø)
src/secrets/mod.rs 0.00% <0.00%> (ø)
src/api/mod.rs 84.61% <81.48%> (+0.94%) ⬆️
src/config/settings.rs 64.15% <53.33%> (+64.15%) ⬆️

... and 1 file with indirect coverage changes

🚀 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 base branch from main to sca/windows-config-acl October 14, 2026 13:23
@savacano28
Stephanya Casanova (savacano28) changed the base branch from sca/windows-config-acl to main October 14, 2026 13:27
@savacano28 Stephanya Casanova (savacano28) changed the title feat(agent): read the token through a secret store feat(agent): read the token through a secret store (#1) Oct 14, 2026
@savacano28 Stephanya Casanova (savacano28) added the filigran team Item from the Filigran team. label Oct 14, 2026

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

Token import can corrupt the configuration on write failure and remove unrelated TOML settings.

2 open findings
What changed in this PR

Introduces per-request token retrieval through a secret-store abstraction, reducing long-lived plaintext credentials in memory.

Changes:

  • Adds SecretStore, config-backed storage, and token import support.
  • Reads and redacts tokens securely for API requests and settings output.
  • Updates worker threads and tests for shared secret stores.
File Description
Cargo.toml Adds zeroize.
Cargo.lock Locks the dependency update.
src/​api/​mod.rs Retrieves tokens per request and marks headers sensitive.
src/​api/​manage_jobs.rs Propagates authorization failures.
src/​api/​register_agent.rs Propagates authorization failures.
src/​config/​settings.rs Makes tokens optional and redacts debug output.
src/​main.rs Opens and shares the secret store.
src/​process/​agent_job.rs Passes the store to the jobs client.
src/​process/​keep_alive.rs Passes the store to the heartbeat client.
src/​secrets/​mod.rs Defines and opens secret stores.
src/​secrets/​config_store.rs Implements config-backed token retrieval.
src/​secrets/​import.rs Imports and removes plaintext tokens.
src/​tests/​api/​client.rs Tests per-request authorization behavior.
src/​tests/​config/​mod.rs Registers settings tests.
src/​tests/​config/​settings_tests.rs Tests token redaction.
src/​tests/​mod.rs Registers secret-store tests.
src/​tests/​secrets/​mod.rs Adds test secret-store utilities.
src/​tests/​secrets/​config_store_tests.rs Tests config-backed storage.
src/​tests/​secrets/​import_tests.rs Tests token migration scenarios.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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.

🟡 Changes recommended

Token copies remain in non-zeroizing settings and request-header allocations, undermining the stated memory-wiping guarantee.

2 open findings
2 resolved since last review

🧠 Review effort: Balanced

Comment thread src/api/mod.rs Resolved
Comment thread src/config/settings.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

Cleanup ordering can cause a newer bootstrap token to be replaced by a stale config token after restart.

1 open finding
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.

🟡 Changes recommended

Configuration parser diagnostics can expose tokens in logs during malformed live edits.

3 open findings
1 resolved since last review

🧠 Review effort: Balanced

Comment thread src/secrets/config_store.rs Resolved
Comment thread src/api/mod.rs Resolved
Comment thread src/secrets/config_store.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

Production file-backed token reload and recovery need automated coverage before approval.

0 open findings

3 resolved since last review
Previously missed (1)

In code that hasn't changed since last review

Medium severity Add isolated file-backed ConfigStore reload and recovery tests

src/​secrets/​config_store.rs:18

The only ConfigStore test requests refresh_token, returning before this loading path. The rotation and recovery tests use MemoryStore, so they do not verify the production behavior promised by this PR. Please add isolated file-backed tests that read a token, edit it and observe the new value through the same ConfigStore, then verify an unreadable or invalid configuration returns an error and succeeds after repair. Avoid changing shared configuration files or process-wide environment variables in parallel tests.

🧠 Review effort: Balanced

@savacano28
Stephanya Casanova (savacano28) force-pushed the sca/agent-secret-store branch 2 times, most recently from 6d504e8 to 120710f Compare October 16, 2026 09:26
@guillaumejparis Guillaume (guillaumejparis) changed the title feat(agent): read the token through a secret store (#1) feat(agent): read the token through a secret store(#1) Oct 16, 2026

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

lgtm, handful of tidy-ups

Comment thread src/process/agent_job.rs Resolved
Comment thread src/secrets/config_store.rs Resolved
Comment thread src/secrets/config_store.rs Resolved
Comment thread src/secrets/config_store.rs Resolved

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

FIne, some cleanup and small consistency fixes. I just realised that we force-reload the settings only for the one hardcoded secret, to note for later when storing multiple kinds of secrets

Comment thread src/config/settings.rs Resolved
Comment thread src/api/manage_jobs.rs Resolved
Comment thread src/secrets/config_store.rs Resolved
@savacano28 Stephanya Casanova (savacano28) changed the title feat(agent): read the token on each request instead of keeping it in memory (#1) feat(agent): read the token on each request instead of keeping it in memory (#000) Nov 10, 2026
@savacano28

Copy link
Copy Markdown
Contributor Author

Hi antoinemzs, I made the changes (centralize logs, clean code).
Thanks!

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

Since force push, I lost the context of my previous review comments; it seems they were fixed from a cursory look, so thanks

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