feat(policy): ledger-verified effective_enforcement clamp against on-disk tampering#86
Merged
Merged
Conversation
…disk tampering Once the engine honors PolicyDoc.enforcement, hand-editing .doberman/policies.yaml to 'enforcement: off' would silently bypass the apply_enforcement_change gate. effective_enforcement() is the read-side clamp: a soften (monitor/off) is honored only when the append-only ledger holds a matching APPROVED change (state, expiry both ways, non-default revert); anything else — including a hand-deleted expiry that would make a temporary soften permanent — fails closed to 'enforce' with a redacted anomaly. Raise-only; zero I/O on the common 'enforce' path. Closes #81
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.
Slice
What this PR does
Adds
drift.effective_enforcement()— the single sanctioned way to turn the on-diskenforcementfields into the state to act on, closing the gap named in #81: once the engine honorsPolicyDoc.enforcement, hand-editing.doberman/policies.yamltoenforcement: offwould silently bypass the wholeapply_enforcement_changegate.monitor/off) is honored only when the append-only ledger holds a matching APPROVED change: state, expiry (both directions — a hand-deletedexpires_atthat would make a temporary soften permanent is also caught), and any non-default revert target.enforcewith a redacted observer anomaly + log warning (no ledger write: the ledger records gate-approved changes only).monitorrevert clamped up toenforce.enforcepath returns with zero I/O (runs on every mediated action).PolicyDoc.enforcementdocstring now directs consumers to this helper; README roadmap line updated.Closes #81
Tests added (run in CI)
tests/unit/test_enforcement_tamper_check.py(13 tests): approved soften honored · hand-edit without ledger row clamped · denied-attempt rows don't legitimize · state mismatch clamped · garbage value clamped+anomaly ·enforceresolves with zero I/O (nonexistent repo root) · expired soften reverts to verified target ·offrevert clamped up on expiry · future expiry keeps the soften · hand-deleted expiry after a temporary soften clamped · gate-approved expiry clear honored · DB explosion fails closed · exploding observer can't break the clampSecurity checklist
Edge cases covered / Deviations from plan / Risks introduced
expires_atwas set). Made it symmetric so deleting the expiry line by hand can't make an approved temporary soften permanent; ledger encodings"None"/"(absent)"/no-row all normalize to "no expiry approved".enforceuntil the operator re-runs the gated change — protection can only go up.effective_enforcementinto the decision path is the follow-up this clamp unblocks (Wire the mode dial (doberman mode / setup) through log_change so mode changes hit the ledger #79/Redact the free-text reason before it reaches the drift ledger and DriftObservers #80 lineage).