Skip to content

fix(platform): allow audit-log chain writes through RLS - #1726

Merged
Israeltheminer merged 1 commit into
mainfrom
fix/audit-log-rls-chain-link
May 19, 2026
Merged

Israeltheminer merged 1 commit into
mainfrom
fix/audit-log-rls-chain-link

Conversation

@Israeltheminer

@Israeltheminer Israeltheminer commented May 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Adds RLS rule for auditLogChainGenesis (org-membership gated read/insert/modify) so the per-org chain-genesis sentinel can be upserted.
  • Relaxes auditLogs.modify from blanket-deny to org-membership gating so createAuditLog can patch the predecessor row's chainSuccessor (the OCC anti-fork mechanism).
  • Audit-log content immutability remains enforced by the chain integrityHash + verifyIntegrity self-check — not by the RLS modify rule, which has no visibility into the patch diff.

Why

mutationWithRLS runs with defaultPolicy: 'deny'. After the audit-chain anti-fork landed (PR #1676 hardening series), createAuditLog started doing two writes that RLS blocked:

  1. Upsert of auditLogChainGenesis — no RLS rule existed, default-denied.
  2. Patch of the predecessor auditLogs row's chainSuccessor field — blocked by the previous `modify: () => false` rule.

Every audit-logged mutation in a user-facing context was failing. User-visible symptom: navigating conversation items threw `Failed to mark conversation as read: [CONVEX M(conversations/mutations:markConversationAsRead)] [...] insert access not allowed`, then after fixing the first hop, `write access not allowed` from the predecessor patch.

Test plan

  • All 70 tests in convex/audit_logs, convex/lib/rls, convex/conversations pass.
  • Verify in the running app: navigate between conversation items → no console error, unread_count clears, audit log row is written.
  • Verify hash chain integrity: run verifyIntegrity against a newly created org's audit log and confirm the chain validates end-to-end with chainSuccessor populated.

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Enhanced audit log access controls to allow organization members to modify logs when appropriate.
    • Improved audit log integrity verification through cryptographic validation.

Review Change Stack

Adds an RLS rule for `auditLogChainGenesis` and relaxes
`auditLogs.modify` from blanket-deny to org-membership gating so
`createAuditLog` can perform its two required writes:

1. Upsert the per-org genesis sentinel row.
2. Patch the predecessor row's `chainSuccessor` to serialize
   concurrent writers via OCC and prevent chain forks.

Both writes are part of the audit-chain anti-fork design but were
blocked by `mutationWithRLS` (defaultPolicy: deny). Every audit-logged
mutation in a user-facing context was failing — most visibly,
`markConversationAsRead` throwing "insert access not allowed" / "write
access not allowed" when navigating conversation items.

Audit-log content immutability remains enforced by the chain hash and
`verifyIntegrity` self-check, not by the RLS modify rule.
@coderabbitai

coderabbitai Bot commented May 19, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: de291630-7f4b-42c4-8cd2-ee1f34fca232

📥 Commits

Reviewing files that changed from the base of the PR and between 282117b and be1086c.

📒 Files selected for processing (1)
  • services/platform/convex/lib/rls/helpers/rls_rules.ts

📝 Walkthrough

Walkthrough

This PR adds a new RLS rule set for the auditLogChainGenesis table allowing authenticated users to read, insert, and modify records based on organization membership. Concurrently, it updates the auditLogs table's modify policy from unconditional denial to allowing modifications by authenticated organization members, with comments clarifying that audit immutability is enforced through audit-hash integrity verification rather than RLS layer blocking.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: allowing audit-log chain writes through RLS, which directly matches the core objective of enabling two previously blocked writes.
Description check ✅ Passed The description covers the summary, detailed reasoning, and test plan sections required by the template, though the test plan has some unchecked items indicating manual verification is still pending.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/audit-log-rls-chain-link

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


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

@Israeltheminer
Israeltheminer merged commit ad6018a into main May 19, 2026
22 checks passed
@Israeltheminer
Israeltheminer deleted the fix/audit-log-rls-chain-link branch May 19, 2026 14:55
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