mirror of
https://github.com/garrytan/gstack.git
synced 2026-05-06 21:46:40 +02:00
531bb29474
- Keep anon INSERT policies so pre-v0.11.16 clients can still sync telemetry via PostgREST while new clients use edge functions - Add error_message/failed_step columns to migration (reconcile repo with live schema) instead of dropping them - Security fix still lands: SELECT and UPDATE policies are dropped Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
37 lines
1.7 KiB
SQL
37 lines
1.7 KiB
SQL
-- 002_tighten_rls.sql
|
|
-- Lock down read/update access. Keep INSERT policies so old clients can still
|
|
-- write via PostgREST while new clients migrate to edge functions.
|
|
|
|
-- Drop all SELECT policies (anon key should not read telemetry data)
|
|
DROP POLICY IF EXISTS "anon_select" ON telemetry_events;
|
|
DROP POLICY IF EXISTS "anon_select" ON installations;
|
|
DROP POLICY IF EXISTS "anon_select" ON update_checks;
|
|
|
|
-- Drop dangerous UPDATE policy (was unrestricted on all columns)
|
|
DROP POLICY IF EXISTS "anon_update_last_seen" ON installations;
|
|
|
|
-- Keep INSERT policies — old clients (pre-v0.11.16) still POST directly to
|
|
-- PostgREST. These will be dropped in a future migration once adoption of
|
|
-- edge-function-based sync is widespread.
|
|
-- (anon_insert_only ON telemetry_events — kept)
|
|
-- (anon_insert_only ON installations — kept)
|
|
-- (anon_insert_only ON update_checks — kept)
|
|
|
|
-- Explicitly revoke view access (belt-and-suspenders)
|
|
REVOKE SELECT ON crash_clusters FROM anon;
|
|
REVOKE SELECT ON skill_sequences FROM anon;
|
|
|
|
-- Keep error_message and failed_step columns (exist on live schema, may be
|
|
-- used in future). Add them to the migration record so repo matches live.
|
|
ALTER TABLE telemetry_events ADD COLUMN IF NOT EXISTS error_message TEXT;
|
|
ALTER TABLE telemetry_events ADD COLUMN IF NOT EXISTS failed_step TEXT;
|
|
|
|
-- Cache table for community-pulse aggregation (prevents DoS via repeated queries)
|
|
CREATE TABLE IF NOT EXISTS community_pulse_cache (
|
|
id INTEGER PRIMARY KEY DEFAULT 1,
|
|
data JSONB NOT NULL DEFAULT '{}'::jsonb,
|
|
refreshed_at TIMESTAMPTZ DEFAULT now()
|
|
);
|
|
ALTER TABLE community_pulse_cache ENABLE ROW LEVEL SECURITY;
|
|
-- No anon policies — only service_role_key (used by edge functions) can read/write
|