Skip to content

fix(action-center): scope the write policies to the admin client - #813

Merged
gkhngyk merged 1 commit into
mainfrom
fix/action-center-write-policies
Sep 15, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
fix/action-center-write-policies

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Summary

The Action Center's write policies granted to every signed-in user what their names said was reserved for the service role.

00081 created five policies called "Service role can insert/delete …", but created them the way an unqualified create policy creates anything: to public, with the predicate true. service_role carries BYPASSRLS and never consulted them. The roles that did are anon and authenticated, both of which hold INSERT and DELETE grants on these tables — so the policies had the opposite effect of their name, letting any signed-in user insert and delete rows on actions, action_tasks and action_events regardless of which organization owned them.

Reads were never affected. The select and update policies are scoped to the caller's organization and are untouched here.

The change

The five commands are closed outright rather than scoped, because nothing legitimate went through them:

  • both writers — the nightly signal-to-action generator and the backfill script — use the admin client, whose role carries BYPASSRLS (verified against the database, not assumed);
  • the web tier only selects and updates.

So closing them is the narrowest fix that keeps current behaviour exactly as it is.

Deny-all policies rather than no policy at all. With RLS enabled a missing policy already denies, but an explicit false shows the next reader a decision where they would otherwise see an omission, and each table keeps one policy per command.

action_tasks reopens to members, scoped to their own organization, in a later migration — when the Tasks tab learns to add and remove tasks.

Related issue

None — found while reading these policies before extending them.

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

Database

00082_action_center_write_policies — already applied to the hosted database. Policy-only; no table, column or data changes.

Self-hosted installs that have run 00081 should apply this one.

How to test

After applying, pg_policies shows false for every insert/delete on the three tables, and the member select/insert/update policies are unchanged:

select tablename, cmd, policyname, coalesce(qual, with_check) as predicate
from pg_policies
where schemaname = 'public'
  and tablename in ('actions', 'action_tasks', 'action_events')
order by tablename, cmd;

Then confirm nothing regressed:

  1. The Action Center pages still load — KPIs, Actions, Signals.
  2. Triage still works: change an action's status, assign it, set a due date, tick a task. Those are updates and stay permitted.
  3. The nightly run still produces actions and their tasks; it writes through the admin client. Verified on the hosted database that the generator's last run and its rows are intact.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • supabase/schema.sql regenerated with bash supabase/build-schema.sh
  • Changes are focused — one concern per PR

🤖 Generated with Claude Code

https://claude.ai/code/session_01SQ2H6mSd9JDpmqonk2VWBj

00081 created five policies named "Service role can insert/delete ...", but
created them the way an unqualified `create policy` creates anything: `to
public`, predicate `true`. service_role bypasses RLS altogether and never
consulted them; the roles that did are anon and authenticated, both of which
hold INSERT and DELETE grants on these tables. The effect was the opposite of
the name — every signed-in user could insert and delete rows on actions,
action_tasks and action_events regardless of which organization owned them.

Reads were never affected: the select and update policies are scoped to the
caller's organization and are untouched here.

The commands are closed outright rather than scoped, because nothing
legitimate went through them. Both writers — the nightly generator and the
backfill script — use the admin client, whose role carries BYPASSRLS, and the
web tier only selects and updates. Deny-all policies rather than no policy at
all: RLS already denies where no policy matches, but an explicit `false` shows
the next reader a decision instead of an omission.

action_tasks reopens to members, scoped to their organization, when the Tasks
tab learns to add and remove tasks.

Applied to the hosted database.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01SQ2H6mSd9JDpmqonk2VWBj
@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Sep 15, 2026
@gkhngyk
gkhngyk merged commit 3df85c1 into main Sep 15, 2026
6 checks passed
@gkhngyk
gkhngyk deleted the fix/action-center-write-policies branch September 15, 2026 10:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-migration Adds or edits a migration — apply it to the hosted database

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant