Skip to content

fix/storage-encryption - #80

Merged
RambokDev merged 6 commits into
mainfrom
fix/storage-encryption
Jul 11, 2026
Merged

fix/storage-encryption#80
RambokDev merged 6 commits into
mainfrom
fix/storage-encryption

Conversation

@RambokDev

@RambokDev RambokDev commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features

    • Added support for securely retrieving and displaying encrypted database storage information.
    • Added compatibility for status responses that omit optional storage fields.
  • Bug Fixes

    • Improved handling of both legacy plaintext and encrypted storage status formats.
    • Added clearer failure handling when encrypted storage data is missing, invalid, or cannot be decrypted.

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The change adds AES-256-GCM decryption for encrypted agent storage status data, makes storage fields backward-compatible during deserialization, integrates decryption into StatusService::ping, adds coverage for plaintext and encrypted responses, and updates the configured edge key.

Changes

Encrypted storage status handling

Layer / File(s) Summary
Storage status deserialization contract
src/services/api/models/agent/status.rs, src/tests/services/api_models_tests.rs
Storage fields now default when omitted, with tests covering legacy plaintext and encrypted response shapes.
AES-GCM decryption utility
src/utils/file.rs, src/tests/utils/file_tests.rs
Adds base64 envelope decryption with validation and tests for successful, incorrect-key, and short-input cases.
Status service integration
src/services/status.rs, docker-compose.yml
StatusService::ping decrypts and parses encrypted storage data, while the compose configuration updates EDGE_KEY.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant StatusService
  participant AgentAPI
  participant decrypt_json_gcm
  participant DatabaseStatus
  StatusService->>AgentAPI: agent_status(...)
  AgentAPI-->>StatusService: encrypted DatabaseStatus
  StatusService->>decrypt_json_gcm: decrypt storages_ciphertext
  decrypt_json_gcm-->>StatusService: plaintext JSON
  StatusService->>DatabaseStatus: parse and assign storages
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is clearly related to the main change: adding and handling storage encryption/decryption support.
Docstring Coverage ✅ Passed Docstring coverage is 90.91% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/storage-encryption

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docker-compose.yml`:
- Line 22: The docker-compose EDGE_KEY embeds a reusable AES-256 master key.
Remove the hardcoded value, source EDGE_KEY from an untracked environment or
secret configuration, and provide a clearly documented local-development
placeholder or setup path; verify the exposed key is revoked and never reused by
real edge or agent deployments.

In `@src/services/status.rs`:
- Around line 50-55: Replace the `.unwrap()` in the `agent_status` call within
the ping/status handling method with explicit `Option`-to-error conversion,
returning a descriptive error when the response is `None` while preserving the
existing `Result<PingResult, Box<dyn Error>>` flow.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 37545fd7-2042-4054-8619-6e086d1f7108

📥 Commits

Reviewing files that changed from the base of the PR and between fd3b007 and 6cddc73.

📒 Files selected for processing (6)
  • docker-compose.yml
  • src/services/api/models/agent/status.rs
  • src/services/status.rs
  • src/tests/services/api_models_tests.rs
  • src/tests/utils/file_tests.rs
  • src/utils/file.rs

Comment thread docker-compose.yml
LOG: debug
TZ: "Europe/Paris"
EDGE_KEY: "eyJzZXJ2ZXJVcmwiOiJodHRwOi8vbG9jYWxob3N0Ojg4ODciLCJhZ2VudElkIjoiMWM4NmQ5NGEtMGVjOC00NzkxLTk0ZTEtOWRlYmJmMWY0M2I5IiwibWFzdGVyS2V5QjY0IjoiMUh0djdtWCtYVkJxL0IzUEV2WDlZZjlQeUdVZW5oRHlXemo5THRqNW90WT0ifQ=="
EDGE_KEY: "eyJzZXJ2ZXJVcmwiOiJodHRwOi8vbG9jYWxob3N0Ojg4ODciLCJhZ2VudElkIjoiZWZhYTM0YTQtZDY1NC00OGQ3LTgwNDYtNjRkMWExYTA1M2FlIiwibWFzdGVyS2V5QjY0IjoiMUh0djdtWCtYVkJxL0IzUEV2WDlZZjlQeUdVZW5oRHlXemo5THRqNW90WT0ifQ=="

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔒 Security & Privacy | 🟡 Minor | ⚡ Quick win

Committed EDGE_KEY embeds a real AES-256 master key.

This value base64-decodes to JSON containing masterKeyB64 — the actual AES-256 master key used by decrypt_json_gcm. Even for a local dev compose, committing a working master key to VCS is a secret-hygiene risk (and it triggers the secret scanner). Confirm this key is dev-only, is never reused for any real edge/agent, and consider sourcing it from an untracked .env / secret instead of inlining it.

🧰 Tools
🪛 Betterleaks (1.6.0)

[high] 22-22: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)


[high] 22-22: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docker-compose.yml` at line 22, The docker-compose EDGE_KEY embeds a reusable
AES-256 master key. Remove the hardcoded value, source EDGE_KEY from an
untracked environment or secret configuration, and provide a clearly documented
local-development placeholder or setup path; verify the exposed key is revoked
and never reused by real edge or agent deployments.

Source: Linters/SAST tools

Comment thread src/services/status.rs
Comment on lines +50 to 55
let mut result = self
.ctx
.api
.agent_status(&edge_key.agent_id, &version_str, databases_payload)
.await?
.unwrap();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Avoid .unwrap() on the status response — convert None to an error.

agent_status(...).await?.unwrap() panics if the endpoint returns None, taking down the ping task instead of surfacing a recoverable error via the Result<PingResult, Box<dyn Error>> return type.

🛡️ Proposed fix
-        let mut result = self
-            .ctx
-            .api
-            .agent_status(&edge_key.agent_id, &version_str, databases_payload)
-            .await?
-            .unwrap();
+        let mut result = self
+            .ctx
+            .api
+            .agent_status(&edge_key.agent_id, &version_str, databases_payload)
+            .await?
+            .ok_or("agent_status returned no PingResult")?;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/services/status.rs` around lines 50 - 55, Replace the `.unwrap()` in the
`agent_status` call within the ping/status handling method with explicit
`Option`-to-error conversion, returning a descriptive error when the response is
`None` while preserving the existing `Result<PingResult, Box<dyn Error>>` flow.

@codecov

codecov Bot commented Jul 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.20513% with 17 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/services/status.rs 0.00% 17 Missing ⚠️

📢 Thoughts on this report? Let us know!

@RambokDev
RambokDev merged commit 20b3b58 into main Jul 11, 2026
2 checks passed
@RambokDev
RambokDev deleted the fix/storage-encryption branch July 11, 2026 10:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant