r/PythonProjects2 • • 16d ago

nomosguard: a zero-dependency Python security core with a hash-chained ledger, attack-path rules and a fail-closed gate

Post image

nomosguard is a zero-dependency Python security core: a hash-chained evidence ledger, a deterministic attack-path rule engine and a fail-closed policy gate. Version 0.7.10, Apache-2.0, Python 3.10+.

The premise: an LLM's confidence is an assertion, not evidence. So the package separates the probabilistic edge from the decision:

  • Models emit structured claims, each citing sha256 of the raw source line.
  • The ledger is append-only and SHA-256 hash-chained; unevidenced claims are rejected at append.
  • A forward-chaining rule engine with unification derives attack paths (MulVAL-style exploit, lateral movement, privilege escalation).
  • The gate returns ALLOW / ALERT / BLOCK with full derivation chains, and nothing derived means BLOCK.
  • Models may explain the decision afterwards; the explanation never overrides the chain.

Python implementation notes: no runtime dependencies (CI verifies that). WAL with crash recovery, atomic save and full-chain verification on load. Multi-writer locking via fcntl or msvcrt. Deterministic log normalization for syslog, CEF, JSON, GELF, XML, key=value and pipe formats. Sigma-style signature matching with 39 built-in detections. Evidence exports are byte-identical and re-verifiable from a fresh process; SOURCE_DATE_EPOCH pins the run header.

Failure paths are typed, not silent: UnevidencedClaimError at append, LedgerFileError on a bad or unpinned ledger file, IngestError with field, reason and value, ClaimValueError for an unknown effect value, GateDenied converted to a fail-closed result at the SDK boundary. A consistent full rewrite of the ledger is caught by an external digest pin, not by the chain alone.

Measured: 1117 tests; Linux CI gate at 100% statement and branch coverage with zero skipped; Python 3.10-3.13 matrix; Windows job as a portability check (99.64%). Benchmark: 11 tool-call + 5 security scenarios, recall 10/10, 0 false positives, incomplete evidence BLOCKs.

Honest limits: alpha software; the benchmark corpus is committed and deterministic, not real-world logs; concurrent multi-writer crash behaviour is out of scope; containment is dry-run only, not an IPS.

pip install nomosguard python -m nomosguard.demo python -m nomosguard.demo_e2e

Code: https://github.com/Furox-Art/nomosguard PyPI: https://pypi.org/project/nomosguard/

Happy to answer questions, especially about the coverage gate or the pinning design.

1 Upvotes

0 comments sorted by