feat: add hybrid jwt verification#4721
feat: add hybrid jwt verification#4721kallebysantos wants to merge 2 commits intosupabase:developfrom
Conversation
Allows verify new JWTs as well legacy
Pull Request Test Coverage Report for Build 20992742862Details
💛 - Coveralls |
|
@kallebysantos const JWT_SECRET = Deno.env.get('SUPABASE_INTERNAL_JWT_SECRET')!;
const HOST_PORT = Deno.env.get('SUPABASE_INTERNAL_HOST_PORT')!;
const DEBUG = Deno.env.get('SUPABASE_INTERNAL_DEBUG') === 'true';
const FUNCTIONS_CONFIG_STRING = Deno.env.get(
'SUPABASE_INTERNAL_FUNCTIONS_CONFIG'
)!;
async function verifyLegacyJWT(
jwt: string
): Promise<JWTVerifyResult<JWTPayload> | undefined> {
// const JWT_SECRET = Deno.env.get('SUPABASE_INTERNAL_JWT_SECRET')!;
logger.debug('JWT secret: ' + JWT_SECRET);
logger.debug('Host port: ' + HOST_PORT);
logger.debug('Debug: ' + DEBUG);
logger.debug('Functions config string: ' + FUNCTIONS_CONFIG_STRING);
const encoder = new TextEncoder();
const secretKey = encoder.encode(JWT_SECRET);
try {
return await jwtVerify(jwt, secretKey);
} catch (e) {
logger.error('Symmetric Legacy JWT verification error', e);
return undefined;
}
}
|
|
Hi @joelpramos 💚 |
|
hi @kallebysantos:
|
|
Hey @joelpramos 💚 Since you're using self-hosted, the I'm not really sure, but new JWK are not available for self-hosting yet, so you "can't" replicate this hybrid replication — At least without extra manual steps. cc @aantti can give you more details about Self-Host situation of new Asymmetric Keys. |
It's WIP :) Hoping to add it soon. |
|
@aantti @kallebysantos at least locally the new solution works totally fine for users but not for service_user (e.g., functions triggered from Cron). I am also having some issues in the deployed instance with functions triggered from cron jobs but haven't triaged yet the root cause and missing some logs. fwiw other than the fact the variable wasn't available, this hybrid solution you posted @kallebysantos works for me i.e. seems like the service_role from the cron user is using the old auth method. Is that something on both your radars? |
|
Hey @joelpramos
Yes,
I don't think so, user's tokens is now being issued as new JWT (Asymmetric JWK) and the purpose of this PR is to handle both kinds of tokens, using legacy as fallback. |

What kind of change does this PR introduce?
Bug fix, feature
What is the current behavior?
Since API keys did change, users can't call functions without manually disabling
verify_jwt.What is the new behavior?
JWKs are now default exposed #4688, so It allows to verify both new asymmetric tokens as well legacy ones.
This way it applies a temporary fix while migrating API keys.