Skip to content

feat(platform): restrict audit-log reads to org admins - #1852

Merged
yannickmonney merged 1 commit into
mainfrom
feat/audit-log-read-authz
Jun 10, 2026
Merged

yannickmonney merged 1 commit into
mainfrom
feat/audit-log-read-authz

Conversation

@yannickmonney

@yannickmonney yannickmonney commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

What / why

Closes the last open gap from #1505 (audit-log hardening): the read side. The hash chain, nightly integrity cron + alerting, append-only test, retention, and admin-gated export already shipped (#1805, #1820) — but the four public queries in convex/audit_logs/queries.ts gated only on org membership, so any member/editor/developer could read the full org audit trail by calling the API directly, contradicting the admin-only UI gate (orgSettings) and the docs ("Admins and Owners read this").

  • Admin-gate the public read queries — listAuditLogs, listAuditLogsPaginated, getActivitySummary now throw for non-admin/owner roles via an exported assertAuditLogReadAccess helper (same pattern as verifyIntegrity and governance listTrashedRows), unit-tested across all roles in read_access.test.ts.
  • Delete getResourceAuditTrail (public query) — zero consumers anywhere in the repo. The helpers.ts function of the same name stays; the GDPR erasure flow uses it internally.
  • Tighten the RLS matrix (access_control.ts, defense-in-depth): auditLogs read is now admin-only. Developer/editor drop to WRITE_ONLY (write must stay — the RLS insert rule authorizes audit-row inserts); member drops to NONE (member audit rows already bypass RLS via internal_mutations.createAuditLog, see prompts/mutations.ts). The modify rule is untouched so the chain-link chainSuccessor patch keeps working.
  • Mirror the client CASL ability matrix (lib/permissions/ability.ts): cannot('read', 'auditLogs') for developer and member, removed from the editor read-only list. Consistency-only — no UI consumer checks this subject today.
  • Write paths unchanged: chain-linked inserts, retention deletes with signed checkpoints, and the signed PII scrub all keep working (locked in by the existing append_only.test.ts).
  • Fix the stale crons.ts comment claiming the integrity cron alerts on unsigned PII scrubs (it deliberately does not).
  • Docs: one sentence in docs/{en,de,fr}/platform/admin/governance/audit-logs.md documenting that a failed integrity check also raises a critical in-app notification to admins and fans out to Slack.

Decision-gate recommendations baked in

  • In-app + Slack is the monitored-control alert channel (no email) — matches the epic precedent on Bug: Login rate limiting locks account silently — user receives no progressive warning during failed attempts #1566 ("no email transport, front with an IdP"); the platform has no email infrastructure. An email sink stays a follow-up.
  • Read scope is strictly admin/owner-only — matches the issue, the docs wording, and the orgSettings UI gate (not admin+developer). The scoped skills change-history endpoint stays admin-OR-developer, unchanged.
  • getResourceAuditTrail deleted rather than gated — it had no consumer.

Verification

Performed:

  • bun run check at repo root — all 40 tasks green (366 platform test files / 71,917 tests).
  • Targeted: vitest run convex/audit_logs convex/lib/rls/helpers lib/permissions — 9 files, 84 tests pass.
  • bun run --filter @tale/docs lint and bun run --filter @tale/docs test — locale parity green.

Manual verification required

  • On a live deployment: sign in as a member or editor and call api.audit_logs.queries.listAuditLogsPaginated from the browser console → expect "Only admins can read audit logs"; as admin → rows return; the audit-logs settings page is unaffected (already behind the admin-only governance route).

Pre-PR checklist

  • Ran bun run check (format, lint, typecheck, all tests).
  • No hand-rolled skeletons or magic h-[…] on skeletons — N/A (no UI rendering change).
  • Updated services/platform/messages/{en,de,fr}.json — N/A (no new user-facing strings; the gate error is an API-level error, consistent with the existing verifyIntegrity gate).
  • Updated /docs/{en,de,fr}/ for every user-visible change (audit-logs page, alerting sentence, all three locales).
  • Every touched docs page has a real opening and closing (pre-existing page, prose intact; docs tests green).
  • Ran bun run --filter @tale/docs lint and bun run --filter @tale/docs test.
  • Updated README.md / README.de.md / README.fr.md — N/A.

Part of #1803. Closes the read-side authz items of #1505 (requirement 4 and the RLS confirmation); together with the already-merged #1805/#1820 this completes the issue's acceptance criteria — Part of #1505.

Summary by CodeRabbit

  • New Features

    • Audit log integrity verification failures now trigger critical in-app notifications to organization admins and optional Slack alerts when configured.
    • Audit log access is now restricted to organization admins and owners only.
  • Documentation

    • Updated audit logs documentation to reflect new failure notification behavior.

Close out the read-side authz gap from #1505: the public audit-log
queries gated only on org membership, so any member could call them
directly even though the UI and docs treat the log as admin-only.

- Gate listAuditLogs, listAuditLogsPaginated and getActivitySummary
  behind an exported assertAuditLogReadAccess helper (admin/owner only).
- Delete the unconsumed getResourceAuditTrail public query; the
  internal helper stays for the GDPR erasure flow.
- Tighten the RLS matrix: auditLogs read drops to admin-only;
  developer/editor keep write (audit-row inserts), member drops to none
  (member audit rows already route through internal mutations).
- Mirror the change in the client CASL ability matrix.
- Fix the stale crons.ts comment claiming the integrity cron alerts on
  unsigned PII scrubs.
- Document the in-app + Slack alert on a failed integrity check in
  en/de/fr.

Writes are untouched: chain-link patches, retention deletes and the
signed PII scrub keep working.
@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR hardens audit log access control by restricting read access to admin and owner roles across three enforcement layers. Query handlers now call assertAuditLogReadAccess to reject non-admin members before returning audit log data. The RLS permission matrix is updated to grant auditLogs write-only access for developer and editor, and no access for member. Ability-based authorization adds explicit denial rules for non-admin reads. Documentation is updated to describe integrity-check failure notifications and Slack alerting behavior.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related issues

Possibly related PRs

  • tale-project/tale#1726: Both PRs modify authorization for the auditLogs table at the RLS layer; this PR restricts read access to admin/owner while the related PR addresses write access for audit-chain updates.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: restricting audit-log reads to organization admins, which is the core objective of this PR.
Description check ✅ Passed The description is comprehensive and complete, covering all template requirements: a detailed summary with issue links, full pre-merge checklist completion with evidence, test plan with manual verification steps, and clear decision rationale.
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 feat/audit-log-read-authz

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@services/platform/convex/audit_logs/queries.ts`:
- Around line 18-21: The throw in assertAuditLogReadAccess currently uses a
hard-coded English message; change it to use a translation key or standardized
error code instead (e.g., throw new Error('ERR_AUDIT_LOG_READ_ACCESS') or use
the project's translation helper like t('errors.audit_logs.read_access')), so
update the throw in assertAuditLogReadAccess (and any tests that assert the
message) to reference the key/code rather than the English literal while keeping
the isAdmin(member.role) check intact.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: d7c47462-a956-44ea-889e-ab813c528fe8

📥 Commits

Reviewing files that changed from the base of the PR and between 5d6a2c3 and 322222c.

📒 Files selected for processing (10)
  • 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/queries.ts
  • services/platform/convex/audit_logs/read_access.test.ts
  • services/platform/convex/crons.ts
  • services/platform/convex/lib/rls/helpers/access_control.test.ts
  • services/platform/convex/lib/rls/helpers/access_control.ts
  • services/platform/lib/permissions/ability.test.ts
  • services/platform/lib/permissions/ability.ts

Comment on lines +18 to +21
export function assertAuditLogReadAccess(member: OrganizationMember): void {
if (!isAdmin(member.role)) {
throw new Error('Only admins can read audit logs');
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Replace hard-coded English auth error with a translation key / error code.

Line 20 throws an English literal (Only admins can read audit logs). This violates the translation-layer rule and hard-codes locale into the API contract.

Suggested change
+export const AUDIT_LOG_READ_ACCESS_DENIED = 'auditLogs.readAccessDenied';
+
 export function assertAuditLogReadAccess(member: OrganizationMember): void {
   if (!isAdmin(member.role)) {
-    throw new Error('Only admins can read audit logs');
+    throw new Error(AUDIT_LOG_READ_ACCESS_DENIED);
   }
 }

As per coding guidelines: "Every user-facing string goes through the translation layer — never compare against an English literal in code, tests, stories, or comments."

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export function assertAuditLogReadAccess(member: OrganizationMember): void {
if (!isAdmin(member.role)) {
throw new Error('Only admins can read audit logs');
}
export const AUDIT_LOG_READ_ACCESS_DENIED = 'auditLogs.readAccessDenied';
export function assertAuditLogReadAccess(member: OrganizationMember): void {
if (!isAdmin(member.role)) {
throw new Error(AUDIT_LOG_READ_ACCESS_DENIED);
}
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@services/platform/convex/audit_logs/queries.ts` around lines 18 - 21, The
throw in assertAuditLogReadAccess currently uses a hard-coded English message;
change it to use a translation key or standardized error code instead (e.g.,
throw new Error('ERR_AUDIT_LOG_READ_ACCESS') or use the project's translation
helper like t('errors.audit_logs.read_access')), so update the throw in
assertAuditLogReadAccess (and any tests that assert the message) to reference
the key/code rather than the English literal while keeping the
isAdmin(member.role) check intact.

Source: Coding guidelines

@yannickmonney
yannickmonney merged commit 067b875 into main Jun 10, 2026
29 checks passed
@yannickmonney
yannickmonney deleted the feat/audit-log-read-authz branch June 10, 2026 23:33
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