How rishvaiyer/canarynorth works
Purpose and Entry Points
CanaryNorth is a Node.js trust/policy proxy for AI-generated actions. It evaluates scoped capability requests, blocks unsafe or unauthorized work, and emits hash-chained signed receipts plus optional artifact/evidence packages. The HTTP service starts at server.mjs; the synthetic browser demo is served from public/index.html and its client logic in public/app.js. The PenTel teaching console is a separate static UI rooted at public/pen-console/index.html.
HTTP Proxy and Request Boundary
server.mjs owns the API surface: bootstrap data, authorization, receipt/evidence reads, artifact export/verification, signing-key publication, health, and read-only MCP audit. It is the principal enforcement boundary between browser/model-supplied request metadata and protected capability credentials: callers reference opaque cap_* identifiers rather than provider keys. Production requests require bearer authentication plus tenant/workspace, principal, audience, policy-version, and one-time-nonce context; demo mode deliberately relaxes this for synthetic use.
Authorization and Policy Evaluation
Policy enforcement is concentrated in src/policy.mjs, with approval-aware flows in src/approvals.mjs and agentic/control evaluators in src/agentic-defense.mjs. Authorization evaluates capability scope, action/resource allowlists, expiry, request binding, and deny-by-default rules before an action can be allowed. Deterministic content/metadata signals quarantine suspicious prompt-injection, credential, DLP, or unsafe-export-shaped inputs, but structural capability and scope checks remain the actual boundary. Approval-required synthetic actions create short-lived approval state and re-evaluate policy/nonce conditions when resolved.
Receipts, Signing, and Artifact Provenance
Each authorization decision becomes a tamper-evident receipt through src/signing.mjs, linked to its predecessor and persisted through the storage abstraction. HMAC compatibility remains available; optional Ed25519 enables independently verifiable receipt and manifest signatures, with the public key exposed by the server. src/artifacts.mjs binds an allowed receipt to a synthetic artifact, hashes the artifact, produces a signed sidecar manifest, and verifies returned packages. Offline verification tooling is in scripts/verify-receipt.mjs.
Evidence and Release Assurance
src/evidence.mjs manages the redaction-aware synthetic evidence ledger and encrypted evidence-package creation. Packages use local/operator-managed key material rather than exposing wrapping keys to clients. src/release-evidence.mjs evaluates a fixed replay suite at fixtures/release-replays.v1.json, compares reviewed and candidate policy outcomes, and records release evidence; scripts/verify-release.mjs supports the release gate. This distinguishes policy-regression assurance from claims of scanner, malware, or trained-ML coverage.
Durable Ledger Infrastructure
src/storage.mjs provides interchangeable receipt persistence modes: in-memory for demos, append-only JSONL for durable mounted storage, and PostgreSQL for production-style deployments. PostgreSQL initializes receipt and nonce tables and serializes receipt-chain writes; nonce persistence supports replay prevention across requests. Deployment is designed for a Node service plus PostgreSQL, including Railway-oriented boundaries in .github/workflows/deployment-boundaries.yml. Production fails closed without sufficiently strong signing and auth secrets.
Client Visualization and Learning Surfaces
The primary demo consumes bootstrap, authorization, receipt, evidence, and artifact APIs from public/app.js; public/graph.mjs renders the guided teaching graph. Supporting educational routes include public/learn.html, public/threat-lab.html, and public/pen-entry.html. The richer PenTel interface has distinct dashboard, attack-console, coverage, safety-lab, and documentation modules under public/pen-console/, but remains a static synthetic interaction layer rather than an external-tool integration.
Main entry points: server.mjs Proxy HTTP service · policy.mjs Policy evaluator · signing.mjs Receipt chain signer · release-evidence.mjs Release replay evaluator
Components 18
Client & Learning Surfaces
- Browser demo · Synthetic capability-request interface.
public/app.js - Guided teaching graph
public/graph.mjs - Learning routes
public/learn.html - PenTel console · Synthetic security interaction layer.
public/pen-console/index.html
HTTP Enforcement
- Proxy HTTP service · API and protected capability boundary.
server.mjs - Production request context · Bearer identity, tenant scope, policy version, and nonce.
server.mjs
Policy & Decisions
- Policy evaluator · Deny-by-default capability, scope, binding, and expiry checks.
src/policy.mjs - Suspicion signals · Quarantines injection, credential, DLP, and unsafe-export-shaped inputs.
src/agentic-defense.mjs - Approval workflow · Short-lived approvals re-check policy and nonce conditions.
src/approvals.mjs
Provenance & Evidence
- Receipt chain signer · Creates predecessor-linked signed decisions.
src/signing.mjs - Artifact provenance · Binds allowed receipts to hashed, signed artifact manifests.
src/artifacts.mjs - Evidence ledger & packages · Redaction-aware ledger with encrypted packages.
src/evidence.mjs
Durability & Release Assurance
- Ledger storage abstraction · Memory, append-only JSONL, or PostgreSQL persistence.
src/storage.mjs - PostgreSQL ledger · Receipt and nonce tables serialize chain writes and prevent replay.
src/storage.mjs - Release replay evaluator · Compares reviewed and candidate policy outcomes.
src/release-evidence.mjs - Reviewed replay suite
fixtures/release-replays.v1.json - Offline receipt verifier
scripts/verify-receipt.mjs - Release gate verifier
scripts/verify-release.mjs
Connections 21
- Browser demo → Proxy HTTP service: calls APIs
- Guided teaching graph → Browser demo: renders guidance for
- Learning routes → PenTel console: links to
- PenTel console → Proxy HTTP service: synthetic interactions
- Proxy HTTP service → Production request context: validates
- Production request context → Policy evaluator: scoped request
- Proxy HTTP service → Policy evaluator: authorizes capability
- Suspicion signals → Policy evaluator: quarantine signals
- Policy evaluator → Approval workflow: approval-required action
- Approval workflow → Policy evaluator: re-evaluates resolution
- Policy evaluator → Receipt chain signer: decision
- Receipt chain signer → Ledger storage abstraction: persists chained receipt
- Ledger storage abstraction → PostgreSQL ledger: production mode
- Receipt chain signer → Artifact provenance: allowed receipt
- Receipt chain signer → Evidence ledger & packages: decision record
- Proxy HTTP service → Artifact provenance: export and verify API
- Proxy HTTP service → Evidence ledger & packages: evidence API
- Offline receipt verifier → Receipt chain signer: verifies signatures and chain
- Reviewed replay suite → Release replay evaluator: replay cases
- Release replay evaluator → Evidence ledger & packages: records release evidence
- Release gate verifier → Release replay evaluator: release gate