fix: telemetry-ingest uses anon key instead of service role key

Cherry-pick PR #750 by @Gonzih. The service role key bypasses RLS and
grants unrestricted database access — anon key + RLS is the right model
for a public telemetry endpoint.

Co-Authored-By: Gonzih <gonzih@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Garry Tan
2026-04-04 21:18:27 -07:00
parent 1c2e56ddd2
commit 4d6ffa8457
+7 -1
View File
@@ -43,9 +43,15 @@ Deno.serve(async (req) => {
return new Response(`Batch too large (max ${MAX_BATCH_SIZE})`, { status: 400 });
}
// Use the anon key, not the service role key.
// The service role key bypasses Row Level Security (RLS) and grants full
// unrestricted database access — wildly over-privileged for a public
// telemetry endpoint that only needs INSERT on two tables.
// The anon key + properly configured RLS INSERT policies is correct.
// See: https://supabase.com/docs/guides/database/postgres/row-level-security
const supabase = createClient(
Deno.env.get("SUPABASE_URL") ?? "",
Deno.env.get("SUPABASE_SERVICE_ROLE_KEY") ?? ""
Deno.env.get("SUPABASE_ANON_KEY") ?? ""
);
// Validate and transform events