Authenticated requests rejected by RLS as if unauthenticated — possibly related to recent JWT signing key rotation #47149
Replies: 2 comments
-
|
The useful next split is: is PostgREST receiving the user JWT at all, or is it receiving it and failing to trust the new signing key? Supabase's JWT docs say the Data API uses the JWT from I would add a temporary debug RPC and call it from the same deployed app/client that fails: create or replace function public.debug_request_jwt()
returns jsonb
language sql
stable
as $$
select jsonb_build_object(
'current_user', current_user,
'role_claim', current_setting('request.jwt.claim.role', true),
'sub_claim', current_setting('request.jwt.claim.sub', true),
'auth_uid', auth.uid()
);
$$;
grant execute on function public.debug_request_jwt() to anon, authenticated;Then: const { data, error } = await supabase.rpc('debug_request_jwt')
console.log({ data, error })Interpretation:
One thing also worth trying after rotation is forcing a fresh access token / session refresh or signing out/in. The signing-keys docs say rotation causes Auth to issue new JWT access tokens immediately, while old non-expired tokens should remain accepted; if that contract is broken, the RPC above should make it visible. Docs references: |
Beta Was this translation helpful? Give feedback.
-
|
If you look in the Gateway API log you should be able to see what the user role is in the detail data as decoded from the JWT. Note no one from Github is going to be able to check your project though only support can do that. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
After my project's JWT signing key rotated from Legacy HS256 to ECC (P-256)
(shown in Settings → JWT Keys as rotated ~5 hours before this issue started),
authenticated REST requests to PostgREST are being rejected by Row Level
Security as if no user is logged in — even though the same session token is
confirmed valid by the Auth service.
Steps to reproduce:
the correct user id with no error — confirming the access token is valid.
PostgREST request using the same session is rejected with:
{"code":"42501","message":"new row violates row-level security policy
for table ..."}
Isolation steps already taken:
pg_policiesthat the relevant RLS policies exist exactlyas intended.
set local role authenticated;andset local request.jwt.claims = '...'with the real user's UUID —
select auth.uid()correctly returned thatuser's id, and
current_usercorrectly showedauthenticated.permissive rule —
for insert to authenticated with check (true)— STILLresults in the same rejection from the live application (not the SQL
editor), strongly suggesting that real PostgREST requests from the
deployed app are not being recognized as the
authenticatedrole at all,even though the same token verifies successfully via the Auth service.
This strongly suggests PostgREST/Data API is not correctly validating or
recognizing JWTs signed with the new ECC (P-256) key, possibly due to a
caching or propagation issue following the automatic key rotation.
Could you please check whether the Data API / PostgREST service for this
project is correctly synced to the current JWT signing key? Happy to
provide further logs or a minimal repro if useful.
Beta Was this translation helpful? Give feedback.
All reactions