hasura / hasura/graphql-engine

(Cloud) HASURA_GRAPHQL_JWT_SECRET "claims_map" field works intermittently

Open
#9,405 0 comments 0 reactions 0 assignees View on GitHub
k/bug
Dominant language
TypeScript
Stars
32.1k
Forks
3k
PR merge metrics
PR metrics pending

Description

### Version Information

Server Version: v2.17.0-cloud.1

### Environment
Cloud

### What is the current behaviour?

When I try to configure Hasura with Firebase Auth using `claims_map` in `HASURA_GRAPHQL_JWT_SECRET` env variable, Hasura Cloud sometimes authenticate request doing the correct mapping and sometimes not (near half of the time, like one yes, one no, one yes, one no, etc).

### What is the expected behavior?

100% of request with JWT tokens need to be authenticated, and the claims needs to be mapped correctly.

### How to reproduce the issue?

1. Create a Firebase app as explained [here](https://hasura.io/learn/graphql/hasura-authentication/integrations/firebase/)
2. Configure `HASURA_GRAPHQL_JWT_SECRET` env variable in Hasura Cloud Console as follows:
```json
{
"audience": "",
"jwk_url": "https://www.googleapis.com/service_accounts/v1/jwk/securetoken@system.gserviceaccount.com",
"claims_format": "json",
"claims_map": {
"x-hasura-allowed-roles": [
"user"
],
"x-hasura-default-role": "user",
"x-hasura-user-id": {
"path": "$.sub",
}
},
"type": "RS256",
"issuer": "https://securetoken.google.com/"
}
```
3. Make request with valid Firebase auth tokens as `Authentication` header ( `Authentication:Bearer eyJhbGciOiJ...`).
4. See correct and incorrect request responses.

### Please provide any traces or logs that could help here.

trying to make a simple query operation with Authorization header:

Sucessful result:
```json
{
"data": {
"project": [
....
]
}
}
```
But half of the time, it responds this:
```json
{
"errors": [
{
"extensions": {
"code": "access-denied",
"path": "$"
},
"message": "x-hasura-admin-secret/x-hasura-access-key required, but not found"
}
]
}
```
#### HTTPie request examples

Fail request:
```
POST /v1/graphql HTTP/1.1
Accept: application/json, */*;q=0.5
Accept-Encoding: gzip, deflate, br
Authorization: Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6ImQwNWI0MDljNmYyMmM0MDNlMWY5MWY5ODY3YWM0OTJhOTA2MTk1NTgiLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiJodHRwczovL3NlY3VyZXRva2VuLmdvb2dsZS5jb20vc3Itc21pdGgiLCJhdWQiOiJzci1zbWl0aCIsImF1dGhfdGltZSI6MTY3NDg0NDU0NCwidXNlcl9pZCI6Ilc5S2FyQzVTSEJPNnN3N2VyZ0pJSmdVY0x5NDMiLCJzdWIiOiJXOUthckM1U0hCTzZzdzdlcmdKSUpnVWNMeTQzIiwiaWF0IjoxNjc0ODQ4MjEzLCJleHAiOjE2NzQ4NTE4MTMsImVtYWlsIjoibWVAc3l0YS5jbyIsImVtYWlsX3ZlcmlmaWVkIjpmYWxzZSwiZmlyZWJhc2UiOnsiaWRlbnRpdGllcyI6eyJlbWFpbCI6WyJtZUBzeXRhLmNvIl19LCJzaWduX2luX3Byb3ZpZGVyIjoicGFzc3dvcmQifX0.eCuLOxtZ6EMopmLjwJ0aw2yqLOPZEMDjxRh1HCzP_G37G7LWaDqjWuFYKthTf3uP2K4raEbImaLBOvXjQ3WR5AwpcvD0SKPhZJtdt1CfhGn7d8zuTSznuQFGDrNjiXrItV_7gdz7FLHS6_sR0jUsVesVCL6V_Kn0ped89Wz30GjKrgO-Ry1pCEB-VCFhNzRLsrv-xcKEleXL5nHXTP3EITBDMwNmqIhyv8V9N9DM84uCabn-V1Rh8i5Lt4D_R67t6coRh7teqLznkboxb4VRTdoUTHWIp7M7cKfuN0sA7CwXDtsCpLvpEDfG0ex1gB9s-5STHK5Jv0Qw2stzV0zQkw
Connection: keep-alive
Content-Length: 94
Host: api-sr-smith.hasura.app
User-Agent: HTTPie/3.2.1
content-type: application/json

{
"operationName": "MyQuery",
"query": "query MyQuery { project { data }}",
"variables": null
}

HTTP/1.1 200 OK
CF-Cache-Status: DYNAMIC
CF-RAY: 79044ec5dcb209e6-MIA
Connection: keep-alive
Content-Encoding: gzip
Content-Security-Policy: upgrade-insecure-requests
Content-Type: application/json; charset=utf-8
Date: Fri, 27 Jan 2023 20:41:11 GMT
Referrer-Policy: strict-origin-when-cross-origin
Server: cloudflare
Strict-Transport-Security: max-age=31536000; includeSubDomains
Transfer-Encoding: chunked
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 0

{
"errors": [
{
"extensions": {
"code": "access-denied",
"path": "$"
},
"message": "x-hasura-admin-secret/x-hasura-access-key required, but not found"
}
]
}
```

success request
```
POST /v1/graphql HTTP/1.1
Accept: application/json, */*;q=0.5
Accept-Encoding: gzip, deflate, br
Authorization: Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6ImQwNWI0MDljNmYyMmM0MDNlMWY5MWY5ODY3YWM0OTJhOTA2MTk1NTgiLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiJodHRwczovL3NlY3VyZXRva2VuLmdvb2dsZS5jb20vc3Itc21pdGgiLCJhdWQiOiJzci1zbWl0aCIsImF1dGhfdGltZSI6MTY3NDg0NDU0NCwidXNlcl9pZCI6Ilc5S2FyQzVTSEJPNnN3N2VyZ0pJSmdVY0x5NDMiLCJzdWIiOiJXOUthckM1U0hCTzZzdzdlcmdKSUpnVWNMeTQzIiwiaWF0IjoxNjc0ODUyMTM4LCJleHAiOjE2NzQ4NTU3MzgsImVtYWlsIjoibWVAc3l0YS5jbyIsImVtYWlsX3ZlcmlmaWVkIjpmYWxzZSwiZmlyZWJhc2UiOnsiaWRlbnRpdGllcyI6eyJlbWFpbCI6WyJtZUBzeXRhLmNvIl19LCJzaWduX2luX3Byb3ZpZGVyIjoicGFzc3dvcmQifX0.prWg2kYOfYnPnTEYhz42n6CPOFc5WaV9jqe73Zk1tWQWtHtwJ7KOsjCsLpYmYA6CpmQ69v_UwsgNyZtau4hITTyz7TaWrD40qvtxBgbTzK0KP6WjfRwGz6p_1VakeqlXVBAIoGa6iM1fsSLM7RecDq-FCwTXsX6yoBHkRvUsMOQGr8O4N2BMMonnWkIMS0MBWeJPk7wP6F71knJaMYh-dVChCw9mHWA0FczAM9AAEsy9ptbg3UZ6B8dKYkmcn5e1AVn5_xYqF2A5lgfQC6llrPGe7Vieqjp-1pu-EFPYTprdRm2I-ZbPAXK5fixPhKxy2w2zUMYHECe2IUCpq2c70g
Connection: keep-alive
Content-Length: 94
Host: api-sr-smith.hasura.app
User-Agent: HTTPie/3.2.1
content-type: application/json

{
"operationName": "MyQuery",
"query": "query MyQuery { project { data }}",
"variables": null
}

HTTP/1.1 200 OK
CF-Cache-Status: DYNAMIC
CF-RAY: 7904510f79c13346-MIA
Connection: keep-alive
Content-Encoding: gzip
Content-Security-Policy: upgrade-insecure-requests
Content-Type: application/json; charset=utf-8
Date: Fri, 27 Jan 2023 20:42:45 GMT
Referrer-Policy: strict-origin-when-cross-origin
Server: cloudflare
Strict-Transport-Security: max-age=31536000; includeSubDomains
Transfer-Encoding: chunked
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 0
x-request-id: 6c72f012f0cf1c0101145cb061fd80b9

{
"data": {
"project": [
{...}
]
}
}
```

### Screenshots or Screencast

This is the operation page that shows fail and success requests (same query with same headers, paramerters, etc).
![Screenshot from 2023-01-27 15-34-02](https://user-images.githubusercontent.com/2219914/215191659-56bb8e64-be62-4f90-8a2b-98997fad592f.png)

Detail of one success operation:
![Screenshot from 2023-01-27 15-35-05](https://user-images.githubusercontent.com/2219914/215191847-6d5a9e47-3502-4868-a88c-a69d8d019aca.png)

Detail of one fail operation: (you can see that no `SESSION VARIABLES` are mapped)
![Screenshot from 2023-01-27 15-35-12](https://user-images.githubusercontent.com/2219914/215191971-9a10aa1a-b76f-4606-a3f3-183973b79642.png)

### Any possible solutions/workarounds you're aware of?

First I think that is problem of one of the IPs mapped to my domain (load balancer CNAME). but when I see the IP of the requests that fail, the IP is indifferent.
### Keywords

claims, claims_map, env, HASURA_GRAPHQL_JWT_SECRET, cloud, jwt, firebase

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the Firebase configuration and repeated GraphQL requests described in the issue, comparing successful and failed responses and session-variable mapping. Done means every request with a valid Firebase JWT is authenticated and the claims are mapped consistently.

Written by the indexing model from the issue text.

Assessment

Domain
api, authentication
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.