Files
gstack/supabase/migrations/008_close_anon_writes.sql
T
Garry Tanandcapy-ai[bot] 12cc21872d Telemetry backend only accepts writes through its own endpoint, and tests stop sending to it (GST-3234) (#4537)
The telemetry backend now takes writes only through its validated
endpoint, signed-in Supabase users can read or write nothing, and
gstack's tests can no longer send telemetry to the live project.

Why: a signed-in prober read two views on 2026-11-19, probes wrote about
2,000 junk rows through the open insert policy, and 41% of all skill-run
rows were test-suite traffic.

Nothing changes for users until the migrations and edge functions are
deployed; the deploy order is under Deploy.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Review-Finding: p1/red-team#1 reader=red-team
Review-Finding: supabase/migrations/008_close_anon_writes.sql:9:published-number reader=core
Review-Finding: p2/outside-voice#3 reader=outside-voice
2026-11-19 20:31:31 +00:00

43 lines
2.3 KiB
SQL

-- 008_close_anon_writes.sql
-- Closes the last direct write path. Since v0.11.16.0 every gstack client
-- writes through the edge functions (telemetry-ingest, update-check); only
-- older clients POST straight to the tables with the public key. The policies
-- kept for them in 002 also let anyone write arbitrary rows: probes on
-- 2026-11-16..19 added about 2,000 junk events and 500 fake installs.
--
-- What this drops: clients older than v0.11.16.0 (released 2026-03-24) stop
-- landing. In the 30 days to 2026-11-19 that was 245 events from 23 installs
-- and 163 update checks. Their sync keeps the batch and retries, so nothing
-- breaks on their side; it just never arrives.
--
-- Deploy order: apply 004, 005, 006 and 007; deploy telemetry-ingest and
-- community-pulse (the new ingest writes 004's and 006's columns, and the new
-- pulse calls 006's function); confirm one ingest event lands; then apply
-- this. Run earlier, it refuses every new event. Undo by re-granting anon's
-- table privileges and recreating the policies this file drops (created in
-- 001 and 003).
DROP POLICY IF EXISTS "anon_insert_only" ON telemetry_events;
DROP POLICY IF EXISTS "anon_insert_only" ON installations;
DROP POLICY IF EXISTS "anon_insert_only" ON update_checks;
DROP POLICY IF EXISTS "anon_update_tracking" ON installations;
DROP POLICY IF EXISTS "anon_update_last_seen" ON installations;
REVOKE ALL ON ALL TABLES IN SCHEMA public FROM anon;
REVOKE ALL ON ALL SEQUENCES IN SCHEMA public FROM anon;
REVOKE EXECUTE ON ALL FUNCTIONS IN SCHEMA public FROM anon;
ALTER DEFAULT PRIVILEGES IN SCHEMA public REVOKE ALL ON TABLES FROM anon;
ALTER DEFAULT PRIVILEGES IN SCHEMA public REVOKE ALL ON SEQUENCES FROM anon;
ALTER DEFAULT PRIVILEGES IN SCHEMA public REVOKE EXECUTE ON FUNCTIONS FROM anon;
DO $$
BEGIN
ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA public REVOKE ALL ON TABLES FROM anon;
ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA public REVOKE ALL ON SEQUENCES FROM anon;
ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA public REVOKE EXECUTE ON FUNCTIONS FROM anon;
EXCEPTION
WHEN insufficient_privilege OR undefined_object THEN
RAISE NOTICE 'supabase_admin default privileges unchanged (%): objects it creates later still grant anon', SQLERRM;
END
$$;