Skip to content

feat(integration): audit logger + scanner round-trip - 26 tests#20

Open
Pranjal0410 wants to merge 1 commit intoc2siorg:mainfrom
Pranjal0410:feat/integration-audit
Open

feat(integration): audit logger + scanner round-trip - 26 tests#20
Pranjal0410 wants to merge 1 commit intoc2siorg:mainfrom
Pranjal0410:feat/integration-audit

Conversation

@Pranjal0410
Copy link
Copy Markdown
Contributor

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_APPEND for 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 - FirewallWithScanner class.

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/except with SimpleNamespace fallback — no dependency on acf.scanners being installed, works cleanly with mocks.

Why this matters

In Phase 1, the sidecar returns hardcoded ALLOW. But the round-trip proves:

  • Scanner runs and produces structured signals
  • Signals serialise correctly into RiskContext JSON
  • Sidecar receives payload, verifies HMAC, responds
  • Audit log captures the decision with all metadata
  • Sensitive input text never appears in the log

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

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