Repository navigation
feat: add slack_installations table migration - #14
Conversation
Create slack_installations table for Slack Marketplace distribution with: - UUID PK, unique slack_team_id, FKs to accounts - RLS policies restricting CRUD to org members - updated_at trigger using existing trigger_set_updated_at() Co-Authored-By: Paperclip <noreply@paperclip.ing>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughA new SQL migration creates the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
Updates to Preview Branch (feature/slack-installations-table) ↗︎
Tasks are run on every commit but only new migration files are pushed.
View logs for this Workflow Run ↗︎. |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@supabase/migrations/20260327000000_create_slack_installations.sql`:
- Line 7: The slack_installations table currently stores sensitive bot_token in
plain text and exposes it via the SELECT RLS policy; remove bot_token from the
public row-level-accessible table and move it to a restricted secrets store (or
a new table like slack_installation_secrets) that is only accessible by
backend/service roles or via an encrypted column with much stricter
RLS/privileges. Update the migration diff to drop the bot_token column from
slack_installations, add a new secrets table (e.g., slack_installation_secrets
with installation_id, encrypted_token, and strict RLS allowing only service_role
or a back-end policy), and change the existing SELECT policy that uses
account_organization_ids so it only returns non-sensitive metadata
(workspace_name, installed_at, installation_id) from slack_installations. Also
ensure any code referencing bot_token is updated to fetch the token from the new
secrets store or secret accessor.
- Line 8: The INSERT and UPDATE RLS policies for the slack_installations table
must enforce that the installed_by column equals the authenticated user to
prevent spoofing: update the INSERT policy's WITH CHECK clause to include "and
installed_by = auth.uid()", and add a WITH CHECK clause to the UPDATE policy (or
extend its existing USING/conditions) ensuring "installed_by = auth.uid()";
target the policies defined for the slack_installations table so the database
rejects any INSERT/UPDATE where installed_by does not match auth.uid().
- Around line 25-27: The RLS predicates currently compare
slack_installations.organization_id to account_id from account_organization_ids;
change those predicates to select organization_id instead of account_id (i.e.,
ensure the subquery uses select organization_id from account_organization_ids
where account_id = auth.uid()) so each policy (the ones referencing
organization_id in the slack_installations table) correctly checks membership;
update all four policy blocks that use the subquery so they reference
organization_id from account_organization_ids and leave auth.uid() comparison to
account_id as-is.
🪄 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: defaults
Review profile: CHILL
Plan: Pro
Run ID: bfe28e36-a680-42d5-84ce-d0b08a47bfb3
📒 Files selected for processing (1)
supabase/migrations/20260327000000_create_slack_installations.sql
| slack_team_id text unique not null, | ||
| slack_team_name text not null, | ||
| organization_id uuid not null references public.accounts(id) on delete cascade, | ||
| bot_token text not null, |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Locate bot_token storage and select policy exposure in migrations
rg -n -C3 '\bbot_token\b|create policy "Org members can view their installations"|for select|slack_installations' \
supabase/migrationsRepository: recoupable/database
Length of output: 5529
🏁 Script executed:
cat -n supabase/migrations/20260327000000_create_slack_installations.sqlRepository: recoupable/database
Length of output: 2716
🏁 Script executed:
# Check if there's any column-level RLS or encryption/masking on bot_token
rg -n 'column.*bot_token|mask.*bot_token|encrypt.*bot_token|grant.*bot_token' supabase/Repository: recoupable/database
Length of output: 45
🏁 Script executed:
# Find and examine the account_organization_ids table/view definition
rg -n 'account_organization_ids' supabase/migrations/ -A 5 -B 2Repository: recoupable/database
Length of output: 13171
Move Slack bot credentials to a restricted secrets store.
The bot_token column (Line 7) is stored in plain text and accessible via the SELECT policy to all organization members (Line 21–29). The RLS policy grants access to entire rows without column-level filtering, making credentials retrievable by any account linked to the organization via account_organization_ids.
Recommend storing bot tokens in a secrets management system (e.g., Vault, encrypted secrets table with tighter scoping) and expose only non-sensitive metadata (workspace name, installation date) through the main table.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@supabase/migrations/20260327000000_create_slack_installations.sql` at line 7,
The slack_installations table currently stores sensitive bot_token in plain text
and exposes it via the SELECT RLS policy; remove bot_token from the public
row-level-accessible table and move it to a restricted secrets store (or a new
table like slack_installation_secrets) that is only accessible by
backend/service roles or via an encrypted column with much stricter
RLS/privileges. Update the migration diff to drop the bot_token column from
slack_installations, add a new secrets table (e.g., slack_installation_secrets
with installation_id, encrypted_token, and strict RLS allowing only service_role
or a back-end policy), and change the existing SELECT policy that uses
account_organization_ids so it only returns non-sensitive metadata
(workspace_name, installed_at, installation_id) from slack_installations. Also
ensure any code referencing bot_token is updated to fetch the token from the new
secrets store or secret accessor.
| slack_team_name text not null, | ||
| organization_id uuid not null references public.accounts(id) on delete cascade, | ||
| bot_token text not null, | ||
| installed_by uuid not null references public.accounts(id), |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Verify whether installed_by is constrained in RLS policies
rg -n -C3 'installed_by|create policy "Org members can insert installations"|create policy "Org members can update installations"|with check|for insert|for update' \
supabase/migrations/20260327000000_create_slack_installations.sqlRepository: recoupable/database
Length of output: 1013
🏁 Script executed:
cat -n supabase/migrations/20260327000000_create_slack_installations.sqlRepository: recoupable/database
Length of output: 2716
Prevent installed_by spoofing in INSERT and UPDATE policies.
The INSERT policy (line 35–40) and UPDATE policy (line 46–51) do not constrain the installed_by column. Any org member can insert or update installations while setting installed_by to any account ID, spoofing the audit trail.
Add and installed_by = auth.uid() to:
- The INSERT policy's
with checkclause - A new
with checkclause in the UPDATE policy (currently missing)
🔧 Proposed fix
create policy "Org members can insert installations"
on public.slack_installations
for insert
with check (
organization_id in (
select account_id from public.account_organization_ids
where account_id = auth.uid()
- )
+ )
+ and installed_by = auth.uid()
);
create policy "Org members can update installations"
on public.slack_installations
for update
using (
organization_id in (
select account_id from public.account_organization_ids
where account_id = auth.uid()
)
+ )
+ with check (
+ organization_id in (
+ select account_id from public.account_organization_ids
+ where account_id = auth.uid()
+ )
+ and installed_by = auth.uid()
);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@supabase/migrations/20260327000000_create_slack_installations.sql` at line 8,
The INSERT and UPDATE RLS policies for the slack_installations table must
enforce that the installed_by column equals the authenticated user to prevent
spoofing: update the INSERT policy's WITH CHECK clause to include "and
installed_by = auth.uid()", and add a WITH CHECK clause to the UPDATE policy (or
extend its existing USING/conditions) ensuring "installed_by = auth.uid()";
target the policies defined for the slack_installations table so the database
rejects any INSERT/UPDATE where installed_by does not match auth.uid().
Code Review — database#14SummaryAdds a migration to create the CI Status
Branch Status
CLEAN Code Assessment
Issues Found🚫 Blocking: RLS policies have incorrect column referenceAll four RLS policies use: This selects Fix: Select This affects all 4 policies (select, insert, update, delete).
|
RLS policies were selecting account_id instead of organization_id from account_organization_ids, which meant the policies compared organization_id to auth.uid() rather than checking org membership correctly. Co-Authored-By: Paperclip <noreply@paperclip.ing>
Fix pushed — RLS policy column reference correctedAddressed the blocking review feedback:
Commit: |
Re-Review — database#14 ✅ ApprovedRLS policy fix verified — all 4 policies now correctly select CI Status
Branch Status
Remaining Suggestions (non-blocking)
Verdict:
|
The slack_installations migration (PR #14) was merged prematurely. This migration drops the table, RLS policies, index, and trigger. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The slack_installations migration (PR #14) was merged prematurely. This migration drops the table, RLS policies, index, and trigger. Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
slack_installationstable for Slack Marketplace distributiongen_random_uuid(), uniqueslack_team_idaccountsfororganization_id(cascade delete) andinstalled_byorganization_idfor fast org lookupsaccount_organization_idstrigger_set_updated_at()for auto-updatingupdated_atTable Schema
Test plan
Relates to: REC-20 / REC-19 (Slack Marketplace Distribution)
🤖 Generated with Claude Code
Summary by CodeRabbit