fix: telemetry-ingest edge function uses service role key instead of anon key#750
Open
Gonzih wants to merge 1 commit intogarrytan:mainfrom
Open
fix: telemetry-ingest edge function uses service role key instead of anon key#750Gonzih wants to merge 1 commit intogarrytan:mainfrom
Gonzih wants to merge 1 commit intogarrytan:mainfrom
Conversation
The service role key bypasses Row Level Security entirely and grants unrestricted access to all Supabase tables and admin operations. Using it in a public-facing edge function called by all gstack users is a significant unnecessary privilege escalation. The anon key with INSERT-only RLS policies is the correct approach: - telemetry_events: anon can INSERT (migration 001/002) - installations: anon can INSERT (migration 001/002) - No SELECT, UPDATE, DELETE for anon - The service role key should never touch the public network path RLS INSERT policies are already in place (migration 001_telemetry.sql + 002_tighten_rls.sql). Switching to SUPABASE_ANON_KEY is safe. Closes garrytan#675
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Problem
`supabase/functions/telemetry-ingest/index.ts` uses `SUPABASE_SERVICE_ROLE_KEY`:
```typescript
const supabase = createClient(
Deno.env.get("SUPABASE_URL") ?? "",
Deno.env.get("SUPABASE_SERVICE_ROLE_KEY") ?? "" // ← wrong
);
```
The service role key bypasses all Row Level Security and has full unrestricted database access including admin operations. This is a public-facing edge function called by every gstack user for telemetry. Using the service role here means any exploit in the JSON parsing or validation logic has full database access as a blast radius.
Issue #675.
The Fix
Use `SUPABASE_ANON_KEY` instead. The RLS INSERT policies for the `anon` role are already in place (`001_telemetry.sql` + `002_tighten_rls.sql`). Anon can INSERT into `telemetry_events` and `installations` — that's all this function needs.
The service role key should never be on the network path to user-facing endpoints.
sent from mStack