Skip to content

feat(audit): export both chains and verify them offline - #786

Merged
vladimirrott merged 3 commits into
lacs-project:mainfrom
QinXi-ai:feat/620-offline-audit-export
Nov 15, 2026
Merged

vladimirrott merged 3 commits into
lacs-project:mainfrom
QinXi-ai:feat/620-offline-audit-export

Conversation

@QinXi-ai

@QinXi-ai QinXi-ai commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

audit export now includes both transaction and event rows in a versioned JSON document. audit verify --from audit.json --pubkey audit-key.pub verifies that file offline, without opening a database or loading the private key.

Exports made with --since or --limit are marked partial and refused by offline verification with exit code 2. A complete export uses the existing signature and binding checks; changed or missing bound events return exit code 1.

Related Issue

Fixes #620.

Validation

  • Full workspace nextest: 2,119 passed, 8 skipped.
  • Clippy with all workspace features and targets, with warnings denied; formatting and evidence claim checks passed.
  • Five CLI tests cover offline verification after deleting the database and private key, event tampering, a missing bound event, partial exports, malformed documents and the required public key.
  • Live PostgreSQL: migrates_legacy_schema_and_enforces_store_contract passed, including verification of both exported chains with the public key.

Notes for Reviewers

This changes the published export format from an array to { "version": 1, "chain": [...], "events": [...], "partial": false }. Consumers of the old array should read .chain. Please include this breaking output change in the release changelog and minor version bump.

Row encodings are unchanged. Offline verification checks signatures and bindings; detecting removal of an otherwise valid tail still requires an independent checkpoint. The format and workflow are documented in docs/cli.md and docs/the-audit-chain.md.

@QinXi-ai

Copy link
Copy Markdown
Contributor Author

The Rust, PostgreSQL and container checks passed. docs-and-hygiene failed on the two existing Glama links in README.md: both returned Status: 0 on the runner and both return HTTP 200 when I check them now.

Could you rerun that job? GitHub requires repository admin access to rerun it from my account.

vladimirrott
vladimirrott previously approved these changes Nov 12, 2026

@vladimirrott vladimirrott left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at 08f15fbd34dcf0cdd6d107445732fe86b95e7be1. Approving.

Your round-trip test deletes the database and the private key before verifying, and points SYSKNIFE_DATABASE_PATH at a directory that does not exist and then asserts it was never created. That proves --from opens nothing, which is the property an auditor needs. You also took the simpler option for partial exports (refuse with exit 2) and documented it in both places.

Your tests and four mutants, in a container at this head, running cargo test -p sysknife-cli --offline --locked --test audit_export and --test cli_smoke audit_export:

== pristine
running 5 tests ... test result: ok. 5 passed; 0 failed
running 3 tests ... test result: ok. 3 passed; 0 failed
== M1 export drops events                 (events, -> events: Vec::new(),)
test exported_chains_verify_without_a_database_or_private_key ... FAILED
test offline_verification_rejects_changed_and_missing_events ... FAILED
== M2 partial flag ignored by --from      (if document.partial { -> if false {)
test offline_verification_refuses_partial_exports ... FAILED
== M3 export never marks partial
test offline_verification_refuses_partial_exports ... FAILED
test audit_export_emits_the_stored_rows_as_parseable_json ... FAILED
== M4 version check off
test offline_verification_refuses_unknown_versions_and_missing_fields ... FAILED
== pristine again
restored
test result: ok. 5 passed; 0 failed
test result: ok. 3 passed; 0 failed

M1 is the check the issue asked for: with the event half gone, the intact export stops verifying. I did not run the Postgres contract test locally; the postgres-contract job passed on this head.

The red docs-and-hygiene check is not yours. It failed on the Glama badge link in README.md, a file this branch does not touch:

[✖] https://glama.ai/mcp/servers/lacs-project/sysknife → Status: 0
##[error]dead link(s) in README.md after 3 attempts

Two notes, neither blocking. README.md:424 still describes export as "stored signed chain rows as JSON"; I can fix that wording when I write the CHANGELOG entry and the minor bump you asked for. And #784, #785 and #786 all move tests/evidence/workspace-tests.json from 2108, so two of them will conflict on that line after the first merges. Merging main and re-running UPDATE_TEST_BASELINE=1 scripts/test_baseline.sh fixes it.

@vladimirrott vladimirrott left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving again at 1a6cae0.

Thanks for the merge. Beyond git's own merge of 08f15fb and main, your merge commit changes one file, the evidence file:

$ for n in 784:6d6c13af 785:06c3c184 786:08f15fbd; do echo "== ${n%%:*}"; t=$(git merge-tree --write-tree origin/main ${n#*:} 2>/dev/null | head -1); git diff --stat $t p${n%%:*}; done
== 786
 tests/evidence/workspace-tests.json | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

It reads 2119: 2114 on main plus the five #[test] attributes this branch adds.

The partial-export guard from my earlier review still bites at this head:

$ timeout 2400 maintainer-merge verify 786 1a6cae0222344436d2a47ace71c32342b4070dc6 offline_verification_refuses_partial_exports 's/        if document.partial {/        if false {/' > verify-786.log 2>&1; echo "verify_rc=$?" >> verify-786.log
  running 'offline_verification_refuses_partial_exports' unmutated
  rust suite: evidence of 1 executed unit(s), passing unmutated
  applying the mutation and re-running
  receipt recorded for #786 at 1a6cae02 (observed: clean pass, mutated fail)
verify_rc=0

The red security-audit comes from main: cargo audit fails on RUSTSEC-2026-0538 against quinn-udp 0.5.14 in Cargo.lock, and main's own run at b83fda8 fails the same way. cargo update -p quinn-udp --precise 0.5.16 clears it, and that lockfile change is mine to land. You don't need to do anything for it. After it lands, this branch needs an update and a fresh run before it can merge.

As on #784 and #785: all three branches count from 2114, so the two that land after the first will conflict on that line again. I'm sorry for the extra round. Merging main and running UPDATE_TEST_BASELINE=1 scripts/test_baseline.sh resolves it, and I approve again when that file is the only change.

@vladimirrott
vladimirrott merged commit 59ae3af into lacs-project:main Nov 15, 2026
15 checks passed
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.

audit export drops the event chain, so an exported audit log cannot be verified anywhere

2 participants