service_role treated as anon, by GraphiQL
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
Describe the bug
If you try to run queries as the service_role, it ends up mapping to anon, because the query only checks for explicit SELECT allows, and doesn't also check if it's the service user, which only has BYPASSRLS, and no specific table grants.
I'm surprised this hasn't been reported or fixed, in the right repo yet (prob in studio or main, even if the issue is here). I'll try to follow this quickly with a PR, but it's gonna take some testing. Below is a breakdown of what's wrong and how.
To Reproduce
Steps to reproduce the behavior:
- ensure analytics is true on first run or the settings tab breaks (this grabs logflare and vector images, that the maintainers probably always have on).
- run supabase@latest locally
- add some data to a table
- query it as the service_user and it's identical to anon
- same query but impersonated (and proper RLS for SELECT setup), will work.
Expected behavior
GraphiQL should return data from any and all tables, show full public schema introspection.
Screenshots
I'll try to come back with these, along with the solution.
Versions:
- PostgreSQL: 15.8
- pg_graphql: 1.5.11
- pg_graphql commit ref: ea2ab60
nodejs deps:
@supabase/[email protected]
@supabase/[email protected]
@supabase/[email protected]
@supabase/[email protected]
@supabase/[email protected]
@supabase/[email protected]
Additional Info
The pg_graphql extension generates the entire GraphiQL schema view by executing an internal SQL function that scans Postgres catalogs. By default, the code inside the extension determines whether a table should be exposed to the GraphiQL panel by checking if the active role has explicit table-level SELECT grants. This is how the pg_graphql C/SQL compiler filters table visibility:
WHERE has_table_privilege(current_setting('role'), table_id, 'SELECT')
Why service_role Treats You as Unauthenticated
- When you Impersonate a User the GraphiQL panel sets current_setting('role') to 'authenticated'. In Supabase's default template, the authenticated role possesses explicit
SELECTprivileges on the public schema. Therefore, the function returnstrue, andpg_graphqlcompiles the schema docs cleanly. - When you switch to
service_role,current_setting('role')switches to 'service_role'. - Because the
service_roleis a specialized system token built to bypass Row Level Security (RLS), it doesn't have standard, explicit relational tableSELECTgrants applied to individual tables by default. It reads data during runtime purely because itsBYPASSRLSsuperuser attribute overrides access limits during raw execution.
Because has_table_privilege('service_role', table_id, 'SELECT') checks for explicit relational grants rather than bypass attributes, it evaluates to false. The extension concludes that the service_role string has no visible entities, returns an entirely empty schema map, and causes GraphiQL to drop you into an unauthenticated fallback state.
- Lingua principale
- Rust
- Stelle
- 3.4k
- Fork
- 142
- Merge medio
- 5h 26m
- PR unite (30g)
- 3
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di supabase/pg_graphql
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
supabase/pg_graphql#646 ·
-
`graphql.resolve` crashes backend process on invalid `BigInt` filter value (`signal 6`, Postgres enters recovery)Forse di nuovo libera @olirice l’ha presa 172 giorni fa e non c’è nessuna pull request aperta. Apertatriage-required
supabase/pg_graphql#641 · 1 commento · 1 assegnatario ·
-
specifiedByURL field on __Type is declared in the schema but not handled by the resolverForse di nuovo libera @olirice l’ha presa 187 giorni fa e non c’è nessuna pull request aperta. Apertatriage-required
supabase/pg_graphql#629 · 1 assegnatario ·
-
Inconsistent handling of optional filter variables for `SETOF SQL` functions gives "Encountered Absent value" errorForse di nuovo libera @olirice l’ha presa 325 giorni fa e non c’è nessuna pull request aperta. Apertatriage-required
supabase/pg_graphql#617 · 1 commento · 1 assegnatario ·
-
Documentation lists Aggregate, but feature not released in pg_graphqlForse di nuovo libera @olirice l’ha presa 428 giorni fa e non c’è nessuna pull request aperta. Apertaquestion
supabase/pg_graphql#602 · 12 commenti · 1 reazione · 1 assegnatario ·
Tutte le issue di supabase/pg_graphql
Issue simili
-
example
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
rust-lang-nursery/rust-cookbook#954 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 70/100
OpenZeppelin/openzeppelin-relayer#967 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
I maintainer di solito rispondono entro 1 giorno
-
DecisionOutcome::label() / n_dosed(): engine-side mapping so downstream needs no wildcard armAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
src/runs.rs:1987: a missing --source-run-id now answers 400 "Source run ... does not exist", not 404Apertanightly-audit
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
antithesishq/snouty#602 ·
I maintainer di solito rispondono entro 1 giorno