Skip to content

feat(convex): scheduled audit-log integrity check + append-only test - #1805

Merged
yannickmonney merged 2 commits into
mainfrom
feat/audit-log-integrity-cron
Jun 1, 2026
Merged

yannickmonney merged 2 commits into
mainfrom
feat/audit-log-integrity-cron

Conversation

@yannickmonney

Copy link
Copy Markdown
Contributor

What

Closes the open half of #1505: the audit-log hash-chain + checkpoint verification (verifyIntegrity) previously ran only when an admin opened the audit-log page. SOC 2 / ISO 27001 (CC7.2 / A.8.15) expect continuous monitoring. This adds:

  1. A daily integrity cron (02:00 UTC — clear of the 01:00 legal-hold and 04:00 retention sweeps) that re-verifies every org's chain server-side and, on a genuine failure, raises an alert: a structured console.error and a security-category audit row.
  2. An append-only regression test locking in the tamper-detection guarantee.

How

  • Refactor (no behaviour change): the 200-line verification core is extracted from the admin-gated verifyIntegrity query into a reusable verifyAuditChain(ctx, args). The public query keeps its admin gate and delegates; a new no-auth internalQuery (verifyAuditChainForOrg) reuses the same logic for the cron.
  • audit_logs/integrity_check.ts: lists audited orgs from the auditLogChainGenesis table (one row per org that has written audit logs; capped + logged, never silent), verifies each, and writes the alert row on !valid.
  • Alert scoping (correctness): the only failure condition is !result.valid (covers both a hash break and a checkpoint mismatch). truncated is a coverage limit → console.warn, not a failure; unsignedScrubCount is only non-zero on deployments with no signing key (expected legacy state) → never alerted. Each org is verified in its own try/catch so one failure can't abort the sweep.
  • Append-only note: RLS deliberately allows the forward chain-link patch createAuditLog performs, so append-only is enforced by detection (the hash chain), not by an RLS denial. The test asserts detection: a clean chain verifies, an out-of-band field mutation is caught (firstBrokenAt), and a mid-chain deletion breaks the linkage.
  • Docs: the audit-logs admin page (en/de/fr) now notes the scheduled check.

Verification

  • New convex/audit_logs/append_only.test.ts (convex-test) — 3 cases, all green.
  • convex dev deploys the new functions cleanly (validated against the local backend); convex/_generated/api.d.ts regenerated (2-line diff).
  • bun run check ✓ (incl. 71k+ platform tests, docs parity/loanword tests). CodeRabbit findings (per-org try/catch + truncated-not-a-failure) applied.

Known follow-up

Very large chains (> the per-run window) are verified oldest-first and the overflow is logged, not failed. Full paging of such chains via fromTimestamp is a follow-up (the continuation semantics need their own verification).

Pre-PR checklist

  • Ran bun run check — green.
  • No hand-rolled skeletons — N/A (backend).
  • Updated messages/{en,de,fr}.json — N/A (no UI strings).
  • Updated /docs/{en,de,fr}/ — audit-logs admin page notes the scheduled check.
  • Docs lint + test — green (139 tests).
  • Updated README.* — N/A.

Part of #1803
Refs #1505

The hash-chain + checkpoint verification (verifyIntegrity) only ran when
an admin opened the audit-log page. Add continuous monitoring expected by
SOC 2 / ISO 27001: a daily cron (02:00 UTC) re-verifies every org's chain
server-side and raises an alert — a structured console.error plus a
security-category audit row — on any chain break, truncation, checkpoint
mismatch, or unsigned PII scrub.

- Extract the core verification into a reusable verifyAuditChain(ctx,args)
  helper; the admin-gated verifyIntegrity query keeps its gate and delegates.
- New audit_logs/integrity_check.ts: list audited orgs (genesis table),
  a no-auth internalQuery, and the orchestrating internalAction.
- Append-only regression test: the chain detects an out-of-band field
  mutation and a mid-chain deletion (RLS allows the chain-link patch, so
  append-only is enforced by detection, not denial).
- Document the scheduled check in the audit-logs admin page (en/de/fr).

Refs #1505, #1803
@coderabbitai

coderabbitai Bot commented Jun 1, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@yannickmonney, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 27 minutes and 20 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 9bedba10-a247-4fe8-a859-56ade33d65b8

📥 Commits

Reviewing files that changed from the base of the PR and between 7f06536 and b7e6cc5.

⛔ Files ignored due to path filters (1)
  • services/platform/convex/_generated/api.d.ts is excluded by !**/_generated/**
📒 Files selected for processing (7)
  • docs/de/platform/admin/governance/audit-logs.md
  • docs/en/platform/admin/governance/audit-logs.md
  • docs/fr/platform/admin/governance/audit-logs.md
  • services/platform/convex/audit_logs/append_only.test.ts
  • services/platform/convex/audit_logs/integrity_check.ts
  • services/platform/convex/audit_logs/verify_integrity.ts
  • services/platform/convex/crons.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/audit-log-integrity-cron

Warning

Billing warning: we have not been able to collect payment for this subscription for more than 72 hours. Please update the payment method or pay any pending invoices in Billing to avoid service interruption.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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