Skip to content

feat: remote audit storage backend#22

Open
math280h wants to merge 1 commit into
mainfrom
feat/remote-audit-storage
Open

feat: remote audit storage backend#22
math280h wants to merge 1 commit into
mainfrom
feat/remote-audit-storage

Conversation

@math280h

Copy link
Copy Markdown
Owner

Abstracts the audit log behind an async AuditSink trait with selectable backends.

  • Renames AuditLogger to FileAuditSink (default, unchanged behavior) and implements AuditSink for it.
  • Adds HttpAuditSink that POSTs each audit record as JSON to a configured endpoint, with optional bearer auth.
  • Adds an [audit] config section (backend, endpoint, token_env) with overlay merging plus validation requiring endpoint when backend = http.
  • Builds the sink via build_audit_sink in the service and makes the decision-logging path async; the token is resolved from token_env at construction.
  • Adds a wiremock-backed HTTP sink test, updates the file-backend tests for the rename, and documents the new config keys.

Copilot AI review requested due to automatic review settings June 20, 2026 21:01
@github-actions

github-actions Bot commented Jun 20, 2026

Copy link
Copy Markdown

Coverage

Coverage Report

Metric Value
Total lines 6479
Covered lines 5483
Missed lines 996
Coverage 84.63%
Tests passed 199
Tests failed 0
Tests ignored 0
Coverage command exit 0
Per-file coverage (top 40 by missed lines)
File Stmts Miss Cover Missing
/home/runner/work/safe-pkgs/safe-pkgs/src/service.rs 445 228 48.76% 32, 33, 34, 38, 39, 40, 62, 63, ...
/home/runner/work/safe-pkgs/safe-pkgs/src/custom_rules.rs 194 119 38.66% 41, 70, 71, 80, 81, 82, 83, 96, ...
/home/runner/work/safe-pkgs/safe-pkgs/src/config/custom_rules.rs 152 67 55.92% 134, 161, 164, 170, 173, 192, 193, 195, ...
/home/runner/work/safe-pkgs/safe-pkgs/crates/checks/staleness/src/lib.rs 210 55 73.81% 63, 64, 65, 66, 67, 68, 69, 70, ...
/home/runner/work/safe-pkgs/safe-pkgs/src/policy_snapshot.rs 215 48 77.67% 127, 153, 154, 155, 156, 157, 158, 159, ...
/home/runner/work/safe-pkgs/safe-pkgs/src/config/mod.rs 244 46 81.15% 292, 293, 294, 305, 315, 316, 317, 318, ...
/home/runner/work/safe-pkgs/safe-pkgs/crates/core/src/lib.rs 353 40 88.67% 82, 83, 84, 100, 101, 102, 118, 119, ...
/home/runner/work/safe-pkgs/safe-pkgs/src/main.rs 89 37 58.43% 44, 101, 102, 104, 105, 106, 107, 108, ...
/home/runner/work/safe-pkgs/safe-pkgs/crates/registry/cargo/src/lockfile.rs 432 33 92.36% 27, 28, 29, 44, 45, 46, 63, 72, ...
/home/runner/work/safe-pkgs/safe-pkgs/src/mcp/server.rs 125 32 74.40% 129, 130, 131, 153, 154, 156, 157, 158, ...
/home/runner/work/safe-pkgs/safe-pkgs/src/checks.rs 461 31 93.28% 186, 231, 232, 233, 234, 235, 236, 237, ...
/home/runner/work/safe-pkgs/safe-pkgs/src/cache.rs 127 22 82.68% 25, 26, 27, 28, 29, 30, 31, 32, ...
/home/runner/work/safe-pkgs/safe-pkgs/crates/registry/pypi/src/lockfile.rs 378 22 94.18% 26, 27, 28, 43, 44, 45, 62, 63, ...
/home/runner/work/safe-pkgs/safe-pkgs/crates/registry/npm/src/registry.rs 325 17 94.77% 87, 115, 116, 117, 118, 135, 136, 137, ...
/home/runner/work/safe-pkgs/safe-pkgs/src/bin/safe-pkgs-mcp.rs 37 16 56.76% 12, 13, 14, 15, 16, 18, 21, 22, ...
/home/runner/work/safe-pkgs/safe-pkgs/crates/registry/npm/src/lockfile.rs 395 14 96.46% 27, 28, 29, 44, 45, 46, 66, 94, ...
/home/runner/work/safe-pkgs/safe-pkgs/crates/checks/typosquat/src/lib.rs 119 13 89.08% 68, 79, 82, 83, 91, 120, 162, 163, ...
/home/runner/work/safe-pkgs/safe-pkgs/src/registries/mod.rs 149 9 93.96% 49, 50, 51, 124, 144, 153, 154, 155, ...
/home/runner/work/safe-pkgs/safe-pkgs/crates/registry/pypi/src/registry.rs 273 9 96.70% 67, 68, 69, 74, 75, 76, 233, 235, ...
/home/runner/work/safe-pkgs/safe-pkgs/crates/osv/src/lib.rs 147 9 93.88% 12, 13, 14, 15, 16, 17, 18, 19, ...
/home/runner/work/safe-pkgs/safe-pkgs/crates/registry/cargo/src/registry.rs 299 8 97.32% 57, 58, 59, 64, 65, 66, 230, 232
/home/runner/work/safe-pkgs/safe-pkgs/src/audit_log.rs 88 5 94.32% 94, 170, 190, 192, 223
/home/runner/work/safe-pkgs/safe-pkgs/crates/http/src/lib.rs 184 5 97.28% 46, 47, 52, 53, 149
/home/runner/work/safe-pkgs/safe-pkgs/crates/checks/existence/src/lib.rs 48 3 93.75% 36, 37, 38
/home/runner/work/safe-pkgs/safe-pkgs/crates/checks/advisory/src/lib.rs 112 3 97.32% 67, 128, 141
/home/runner/work/safe-pkgs/safe-pkgs/src/support_map.rs 142 1 99.30% 58
/home/runner/work/safe-pkgs/safe-pkgs/src/metrics.rs 92 0 100.00% -
/home/runner/work/safe-pkgs/safe-pkgs/crates/registry/pypi/src/lib.rs 14 0 100.00% -
/home/runner/work/safe-pkgs/safe-pkgs/crates/registry/npm/src/lib.rs 14 0 100.00% -
/home/runner/work/safe-pkgs/safe-pkgs/crates/registry/cargo/src/lib.rs 14 0 100.00% -
/home/runner/work/safe-pkgs/safe-pkgs/crates/checks/version-age/src/lib.rs 66 0 100.00% -
/home/runner/work/safe-pkgs/safe-pkgs/crates/checks/popularity/src/lib.rs 81 0 100.00% -
/home/runner/work/safe-pkgs/safe-pkgs/crates/checks/install-script/src/lib.rs 55 0 100.00% -

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.

Pull request overview

This PR adds a pluggable audit logging abstraction (AuditSink) so audit records can be persisted either to the existing local file log or to a remote HTTP endpoint, configured via new [audit] config keys.

Changes:

  • Introduces AuditSink with FileAuditSink (existing behavior) and a new HttpAuditSink that POSTs audit records as JSON.
  • Adds [audit] config (backend, endpoint, token_env) with overlay merging and validation for the HTTP backend.
  • Updates the service decision-logging path to be async and adds wiremock-backed tests for the HTTP sink.

Reviewed changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/audit_log.rs Adds AuditSink, implements file + HTTP backends, and provides build_audit_sink factory.
src/service.rs Switches service to hold an AuditSink and makes decision logging async.
src/config/overlay.rs Adds overlay parsing support for the new [audit] config table.
src/config/mod.rs Adds AuditConfig/AuditBackend, validation, defaults, and overlay merge behavior.
src/tests/audit_log.rs Updates file backend test for rename/async and adds HTTP sink test using wiremock.
docs/configuration-spec.md Documents new [audit] config keys and provides an example.
README.md Marks “remote audit storage backends” as completed in the roadmap list.
Cargo.toml Adds reqwest as a workspace dependency for the HTTP sink.
Cargo.lock Updates lockfile for the added dependency.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/audit_log.rs Outdated
Comment thread src/audit_log.rs Outdated
Comment thread src/audit_log.rs
Comment thread src/tests/audit_log.rs
Comment thread docs/configuration-spec.md
Comment thread src/tests/audit_log.rs
@math280h math280h force-pushed the feat/remote-audit-storage branch from 6c9b3ec to 40feafc Compare June 20, 2026 21:14
Copilot AI review requested due to automatic review settings June 20, 2026 21:34
@math280h math280h force-pushed the feat/remote-audit-storage branch from 40feafc to 3ef2d47 Compare June 20, 2026 21:34

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.

Pull request overview

Copilot reviewed 9 out of 10 changed files in this pull request and generated 3 comments.

Comment thread src/config/mod.rs
Comment thread src/tests/audit_log.rs
Comment thread src/audit_log.rs
Abstract the audit log behind an async AuditSink trait with selectable
backends. Keep the local file backend (default, renamed to FileAuditSink)
and add an HttpAuditSink that POSTs each JSON record to a configured
endpoint with optional bearer auth.

Add an [audit] config section (backend, endpoint, token_env) with overlay
merging and validation, build the sink in the service, and make the
decision logging path async.
@math280h math280h force-pushed the feat/remote-audit-storage branch from 3ef2d47 to 9048624 Compare June 20, 2026 21:41
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.

2 participants