Skip to content

Commit cb294fd

Browse files
authored
fix: enrichment logs queries (supabase#37247)
Update JWT payload extraction in service flow queries Replaces hardcoded nulls with actual JWT payload fields for expires_at, signature_prefix, subject, and other attributes. Removes unused invalid key check and standardizes variable naming for JWT apikey joins. Improves accuracy and consistency of extracted JWT data in service flow queries.
1 parent 2afd0c9 commit cb294fd

File tree

1 file changed

+20
-22
lines changed
  • apps/studio/components/interfaces/UnifiedLogs/Queries/ServiceFlowQueries

1 file changed

+20
-22
lines changed

apps/studio/components/interfaces/UnifiedLogs/Queries/ServiceFlowQueries/ServiceFlow.sql.ts

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ const getBaseEdgeServiceFlowQuery = (logId: string, serviceType: EdgeServiceType
8787
apikey_payload.issuer = 'supabase' AND
8888
apikey_payload.role IN ('anon', 'service_role')
8989
THEN apikey_payload.role
90-
WHEN sb_apikey.invalid IS NOT NULL THEN '<invalid>'
9190
WHEN apikey_payload IS NOT NULL THEN '<unrecognized>'
9291
ELSE NULL
9392
END as jwt_key_role,
@@ -120,21 +119,21 @@ const getBaseEdgeServiceFlowQuery = (logId: string, serviceType: EdgeServiceType
120119
-- JWT data
121120
apikey_payload.role as jwt_apikey_role,
122121
apikey_payload.algorithm as jwt_apikey_algorithm,
123-
null as jwt_apikey_expires_at,
122+
apikey_payload.expires_at as jwt_apikey_expires_at,
124123
apikey_payload.issuer as jwt_apikey_issuer,
125-
null as jwt_apikey_signature_prefix,
124+
apikey_payload.signature_prefix as jwt_apikey_signature_prefix,
126125
null as jwt_apikey_key_id,
127126
null as jwt_apikey_session_id,
128-
null as jwt_apikey_subject,
127+
apikey_payload.subject as jwt_apikey_subject,
129128
130129
authorization_payload.role as jwt_auth_role,
131130
authorization_payload.algorithm as jwt_auth_algorithm,
132-
null as jwt_auth_expires_at,
131+
authorization_payload.expires_at as jwt_auth_expires_at,
133132
authorization_payload.issuer as jwt_auth_issuer,
134-
null as jwt_auth_signature_prefix,
135-
null as jwt_auth_key_id,
136-
null as jwt_auth_session_id,
137-
null as jwt_auth_subject,
133+
authorization_payload.signature_prefix as jwt_auth_signature_prefix,
134+
authorization_payload.key_id as jwt_auth_key_id,
135+
authorization_payload.session_id as jwt_auth_session_id,
136+
authorization_payload.subject as jwt_auth_subject,
138137
139138
-- Storage specific data (included for all but only populated for storage)
140139
edge_logs_response_headers.sb_gateway_mode as storage_edge_gateway_mode,
@@ -153,8 +152,8 @@ const getBaseEdgeServiceFlowQuery = (logId: string, serviceType: EdgeServiceType
153152
left join unnest(edge_logs_request.cf) as edge_logs_cf
154153
left join unnest(edge_logs_request.sb) as sb
155154
left join unnest(sb.jwt) as jwt
156-
left join unnest(COALESCE(jwt.apikey, [])) as sb_apikey
157-
left join unnest(COALESCE(sb_apikey.payload, [])) as apikey_payload
155+
left join unnest(COALESCE(jwt.apikey, [])) as apikey
156+
left join unnest(COALESCE(apikey.payload, [])) as apikey_payload
158157
left join unnest(COALESCE(jwt.authorization, [])) as auth
159158
left join unnest(COALESCE(auth.payload, [])) as authorization_payload
160159
left join unnest(COALESCE(sb.apikey, [])) as sb_apikey_outer
@@ -246,7 +245,6 @@ export const getEdgeFunctionServiceFlowQuery = (logId: string): string => {
246245
apikey_payload.issuer = 'supabase' AND
247246
apikey_payload.role IN ('anon', 'service_role')
248247
THEN apikey_payload.role
249-
WHEN sb_apikey.invalid IS NOT NULL THEN '<invalid>'
250248
WHEN apikey_payload IS NOT NULL THEN '<unrecognized>'
251249
ELSE NULL
252250
END as jwt_key_role,
@@ -273,21 +271,21 @@ export const getEdgeFunctionServiceFlowQuery = (logId: string): string => {
273271
-- JWT data
274272
apikey_payload.role as jwt_apikey_role,
275273
apikey_payload.algorithm as jwt_apikey_algorithm,
276-
null as jwt_apikey_expires_at,
274+
apikey_payload.expires_at as jwt_apikey_expires_at,
277275
apikey_payload.issuer as jwt_apikey_issuer,
278-
null as jwt_apikey_signature_prefix,
276+
apikey_payload.signature_prefix as jwt_apikey_signature_prefix,
279277
null as jwt_apikey_key_id,
280278
null as jwt_apikey_session_id,
281-
null as jwt_apikey_subject,
279+
apikey_payload.subject as jwt_apikey_subject,
282280
283281
authorization_payload.role as jwt_auth_role,
284282
authorization_payload.algorithm as jwt_auth_algorithm,
285-
null as jwt_auth_expires_at,
283+
authorization_payload.expires_at as jwt_auth_expires_at,
286284
authorization_payload.issuer as jwt_auth_issuer,
287-
null as jwt_auth_signature_prefix,
288-
null as jwt_auth_key_id,
289-
null as jwt_auth_session_id,
290-
null as jwt_auth_subject,
285+
authorization_payload.signature_prefix as jwt_auth_signature_prefix,
286+
authorization_payload.key_id as jwt_auth_key_id,
287+
authorization_payload.session_id as jwt_auth_session_id,
288+
authorization_payload.subject as jwt_auth_subject,
291289
292290
-- Function logs aggregation
293291
function_logs_agg.function_log_count as function_log_count,
@@ -305,8 +303,8 @@ export const getEdgeFunctionServiceFlowQuery = (logId: string): string => {
305303
left join unnest(fel_request.headers) as fel_request_headers
306304
left join unnest(fel_request.sb) as sb
307305
left join unnest(sb.jwt) as jwt
308-
left join unnest(COALESCE(jwt.apikey, [])) as sb_apikey
309-
left join unnest(COALESCE(sb_apikey.payload, [])) as apikey_payload
306+
left join unnest(COALESCE(jwt.apikey, [])) as apikey
307+
left join unnest(COALESCE(apikey.payload, [])) as apikey_payload
310308
left join unnest(COALESCE(jwt.authorization, [])) as auth
311309
left join unnest(COALESCE(auth.payload, [])) as authorization_payload
312310
left join unnest(COALESCE(sb.apikey, [])) as sb_apikey_outer

0 commit comments

Comments
 (0)