graphql-engine icon indicating copy to clipboard operation
graphql-engine copied to clipboard

JWT secret constantly being refreshed when using Firebase

Open aaka3207 opened this issue 4 years ago • 16 comments

Version Information

Server Version: CLI Version (for CLI related issue): ^2.2.0

Environment

Docker-Compose- WSL Ubuntu

What is the expected behaviour?

Token is refreshed on the usual basis

Keywords

What is the current behaviour?

I'm using Firebase as my auth provider. I bumped my version in docker to 2.3.0 from 2.1.1 and now the engine is constantly refreshing the token. The API itself seems to still be working, but I've noticed points where it intermittently fails in between the gaps of not having a fresh token.

How to reproduce the issue?

1.Create Firebase account, and auth provider 2. Use the following configuration for HASURA_JWT_SECRET:

HASURA_GRAPHQL_JWT_SECRET: '{"jwk_url":"https://www.googleapis.com/service_accounts/v1/jwk/[email protected]","audience":"<project-name>","issuer":"https://securetoken.google.com/<project-name>", "allowed_skew": 3600}'

Screenshots or Screencast

image

Please provide any traces or logs that could help here.

Any possible solutions?

Can you identify the location in the source code where the problem exists?

If the bug is confirmed, would you be willing to submit a PR?

aaka3207 avatar Mar 09 '22 18:03 aaka3207

Yes, already discussed in issue #5781 and #8236. It's not a bug but I strongly believe it is not how it should behave.

Twister42 avatar Mar 10 '22 10:03 Twister42

why this has to be logged constantly? our server logs are full with this message and GCP charges for this (not a big deal, just saying)

efstathiosntonas avatar Mar 11 '22 08:03 efstathiosntonas

This is a recent regression, will be fixed very soon.

tirumaraiselvan avatar Mar 11 '22 08:03 tirumaraiselvan

This has been fixed in https://github.com/hasura/graphql-engine/commit/69501b26572dc60bab48fcbb85a5cc405861f1e0 and will ship in the next release. 🙂

daniel-chambers avatar Mar 15 '22 08:03 daniel-chambers

@daniel-chambers was this released in one of the beta releases already or in a major release? I'm on v2.4.0-beta.3 and it's still happening.

aaka3207 avatar Mar 23 '22 16:03 aaka3207

Still happening on v2.4.0 with this config:

      HASURA_GRAPHQL_JWT_SECRET:
        '{ "type":"RS256", "jwk_url":
        "https://www.googleapis.com/service_accounts/v1/jwk/[email protected]",
        "audience": "${FIREBASE_PROJECT_ID}", "issuer":
        "https://securetoken.google.com/${FIREBASE_PROJECT_ID}" }'

I get this every 1 second on logs:

XXX-backend-graphql-engine-1  | {"type":"jwk-refresh-log","timestamp":"2022-03-31T05:30:03.257+0000","level":"info","detail":{"error":null,"message":"refreshing JWK from endpoint: https://www.googleapis.com/service_accounts/v1/jwk/[email protected]"}}

efstathiosntonas avatar Mar 31 '22 05:03 efstathiosntonas

@aaka3207 @efstathiosntonas This is part of https://github.com/hasura/graphql-engine/releases/tag/v2.5.0-beta.1

tirumaraiselvan avatar Mar 31 '22 06:03 tirumaraiselvan

@tirumaraiselvan stupid me, should have read changelog on both releases. Thanks

efstathiosntonas avatar Mar 31 '22 06:03 efstathiosntonas

Hey @efstathiosntonas, I wanted to get in touch with you regarding some of your comments on our repo. Could you let me know how I could DM you?

a-chocolate-bear avatar Apr 01 '22 13:04 a-chocolate-bear

Hi @a-chocolate-bear, what repo are you talking about? This particular one?

efstathiosntonas avatar Apr 01 '22 13:04 efstathiosntonas

Hi Efstathios,

Actually, we'd like to send you some Hasura stickers for all your support. Could you send me an email address I could reach out to you on?

On Fri, Apr 1, 2022 at 7:18 PM Efstathios Ntonas @.***> wrote:

Hi @a-chocolate-bear https://github.com/a-chocolate-bear, what repo are you talking about? This particular one?

— Reply to this email directly, view it on GitHub https://github.com/hasura/graphql-engine/issues/8299#issuecomment-1085923940, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKUXVPJH7B5XHTDAYNEUZ5DVC35EJANCNFSM5QKKVKRQ . You are receiving this because you were mentioned.Message ID: @.***>

--

Harsha Madhavan Hasura https://hasura.io/: Make your data instantly accessible over GraphQL Twitter https://twitter.com/HasuraHQ | LinkedIn https://www.linkedin.com/company/hasura +91-098400-20391

a-chocolate-bear avatar Apr 01 '22 14:04 a-chocolate-bear

I am seeing this in v2.6.2 as well. Is this another regression?

ghost avatar May 17 '22 15:05 ghost

I see the same behavior with Keycloak and v2.7.0

{"type":"jwk-refresh-log","timestamp":"2022-06-20T05:17:30.951+0000","level":"info","detail":{"error":null,"message":"refreshing JWK from endpoint: http://keycloak.dev-keycloak/realms/app/protocol/openid-connect/certs"}}
{"type":"jwk-refresh-log","timestamp":"2022-06-20T05:17:31.953+0000","level":"info","detail":{"error":null,"message":"refreshing JWK from endpoint: http://keycloak.dev-keycloak/realms/app/protocol/openid-connect/certs"}}
{"type":"jwk-refresh-log","timestamp":"2022-06-20T05:17:32.956+0000","level":"info","detail":{"error":null,"message":"refreshing JWK from endpoint: http://keycloak.dev-keycloak/realms/app/protocol/openid-connect/certs"}}
{"type":"jwk-refresh-log","timestamp":"2022-06-20T05:17:33.958+0000","level":"info","detail":{"error":null,"message":"refreshing JWK from endpoint: http://keycloak.dev-keycloak/realms/app/protocol/openid-connect/certs"}}
{"type":"jwk-refresh-log","timestamp":"2022-06-20T05:17:34.961+0000","level":"info","detail":{"error":null,"message":"refreshing JWK from endpoint: http://keycloak.dev-keycloak/realms/app/protocol/openid-connect/certs"}}
{"type":"jwk-refresh-log","timestamp":"2022-06-20T05:17:35.963+0000","level":"info","detail":{"error":null,"message":"refreshing JWK from endpoint: http://keycloak.dev-keycloak/realms/app/protocol/openid-connect/certs"}}
{"type":"jwk-refresh-log","timestamp":"2022-06-20T05:17:36.965+0000","level":"info","detail":{"error":null,"message":"refreshing JWK from endpoint: http://keycloak.dev-keycloak/realms/app/protocol/openid-connect/certs"}}
{"type":"jwk-refresh-log","timestamp":"2022-06-20T05:17:37.968+0000","level":"info","detail":{"error":null,"message":"refreshing JWK from endpoint: http://keycloak.dev-keycloak/realms/app/protocol/openid-connect/certs"}}
{"type":"jwk-refresh-log","timestamp":"2022-06-20T05:17:38.970+0000","level":"info","detail":{"error":null,"message":"refreshing JWK from endpoint: http://keycloak.dev-keycloak/realms/app/protocol/openid-connect/certs"}}
{"type":"jwk-refresh-log","timestamp":"2022-06-20T05:17:39.973+0000","level":"info","detail":{"error":null,"message":"refreshing JWK from endpoint: http://keycloak.dev-keycloak/realms/app/protocol/openid-connect/certs"}}
{"type":"jwk-refresh-log","timestamp":"2022-06-20T05:17:40.976+0000","level":"info","detail":{"error":null,"message":"refreshing JWK from endpoint: http://keycloak.dev-keycloak/realms/app/protocol/openid-connect/certs"}}
{"type":"jwk-refresh-log","timestamp":"2022-06-20T05:17:41.978+0000","level":"info","detail":{"error":null,"message":"refreshing JWK from endpoint: http://keycloak.dev-keycloak/realms/app/protocol/openid-connect/certs"}}
{"type":"jwk-refresh-log","timestamp":"2022-06-20T05:17:42.981+0000","level":"info","detail":{"error":null,"message":"refreshing JWK from endpoint: http://keycloak.dev-keycloak/realms/app/protocol/openid-connect/certs"}}

alexgorbatchev avatar Jun 20 '22 05:06 alexgorbatchev

@alexgorbatchev We'll take a look. Can you pls provide the response headers from your JWK endpoint: http://keycloak.dev-keycloak/realms/app/protocol/openid-connect/certs

@pfinnerty Can you pls provide the response headers from your JWK endpoint?

tirumaraiselvan avatar Jun 20 '22 05:06 tirumaraiselvan

@tirumaraiselvan

> curl -I http://keycloak.dev-keycloak/realms/app/protocol/openid-connect/certs
HTTP/1.1 200 OK
Referrer-Policy: no-referrer
X-Frame-Options: SAMEORIGIN
Strict-Transport-Security: max-age=31536000; includeSubDomains
Cache-Control: no-cache
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Content-Type: application/json
connection: keep-alive

JWT authorization is working however

{"type":"jwk-refresh-log","timestamp":"2022-06-20T15:02:42.425+0000","level":"info","detail":{"error":null,"message":"refreshing JWK from endpoint: http://keycloak.dev-keycloak/realms/app/protocol/openid-connect/certs"}}
{"type":"http-log","timestamp":"2022-06-20T15:02:42.425+0000","level":"info","detail":{"operation":{"query_execution_time":1.5876e-3,"user_vars":{"x-hasura-role":"hasura-user","x-hasura-user-id":"7f9d2ffc-f7a1-4dbe-80fa-63c69b0a7905"},"request_id":"5f4e047a-caba-457c-9241-fc0d3a204dc7","response_size":541,"request_mode":"single","request_read_time":2.0e-6},"request_id":"5f4e047a-caba-457c-9241-fc0d3a204dc7","http_info":{"status":200,"http_version":"HTTP/1.1","url":"/v1/graphql","ip":"172.23.0.1","method":"POST","content_encoding":"gzip"}}}

alexgorbatchev avatar Jun 20 '22 15:06 alexgorbatchev

@alexgorbatchev Your JWK has a cache policy that says "no-cache" hence Hasura is not caching it and refreshing it every second. This is explained in the docs here: https://hasura.io/docs/latest/graphql/core/auth/authentication/jwt/#rotating-jwks

I think a feature request which disables jwk-refresh logs might be helpful. Added this here: https://github.com/hasura/graphql-engine/issues/8611

tirumaraiselvan avatar Jun 20 '22 15:06 tirumaraiselvan