feat(integration): audit logger + scanner round-trip - 26 tests#20
Open
Pranjal0410 wants to merge 1 commit intoc2siorg:mainfrom
Open
feat(integration): audit logger + scanner round-trip - 26 tests#20Pranjal0410 wants to merge 1 commit intoc2siorg:mainfrom
Pranjal0410 wants to merge 1 commit intoc2siorg:mainfrom
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Audit logger + scanner-to-sidecar integration proof of concept
Two new modules that connect pre-GSoC components into a working round-trip: scanner → firewall → audit log.
What this adds
acf/audit.py— Append-only JSONL audit logger.Every ALLOW/SANITISE/BLOCK decision is recorded with timestamp, hook type, risk score, policy name, and input hash. Sensitive fields (raw input text) are SHA-256 hashed - the log records what happened, not what the user said. Uses
os.O_APPENDfor atomic writes on POSIX. Audit failure never blocks the enforcement path.Entry schema:
{"ts":"2026-03-23T...","hook":"on_prompt","decision":"BLOCK","score":0.87,"policy":"prompt/instruction_override","input_hash":"sha256:a1b2c3...","session_id":"abc","signals":[...],"latency_ms":3.2}acf/integration.py-FirewallWithScannerclass.Runs the scan → send → log pipeline in one call. Scanner produces signals, signals go into the RiskContext, firewall sends to sidecar over UDS, response + signals get logged to JSONL. Works with or without a running sidecar (graceful fallback). Scanner import uses
try/exceptwithSimpleNamespacefallback — no dependency onacf.scannersbeing installed, works cleanly with mocks.Why this matters
In Phase 1, the sidecar returns hardcoded ALLOW. But the round-trip proves:
When Phase 2 lands (scan.go reads the signals field), the Python side is already producing the right data. Zero changes needed.
Tests - 26 passing
Audit (16 tests): hash correctness, determinism, truncation, JSON validity, single-line entries, file creation, append-not-overwrite, input text hashed not stored, signals recorded, UTC timestamps, empty file read, clear, atomic multi-entry writes, policy field, latency field.
Integration (10 tests): full round-trip (scanner → firewall → audit), audit entry schema validation, input text never in log, works without scanner, works without firewall (offline mode), multiple signals, policy field from top signal, audit failure doesn't block enforcement, latency tracking, benign input with no signals.
All 61 tests pass (35 existing + 26 new).