Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Update to 2.9.1] ID token signed with an unsupported algorithm #394

Closed
ZPascal opened this issue Dec 3, 2023 · 18 comments
Closed

[Update to 2.9.1] ID token signed with an unsupported algorithm #394

ZPascal opened this issue Dec 3, 2023 · 18 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@ZPascal
Copy link

ZPascal commented Dec 3, 2023

[Update to 2.9.1] ID token signed with an unsupported algorithm

Summary

Hi @p53, after the update to 2.9.1, I'm facing an issue with the ID token and the proxy mentioned that the signature algorithm is not supported. I'm running Keycloak with default settings and I've already tried to adjust the client settings and signature algorithm on the Keycloak side to a listed algorithm (error message). After changing the algorithm the issue persists. The corresponding error occurs after the update from Gatekeeper version 2.9.0 to 2.9.1. Do you have changed something related to the signature algorithm?

Environment

  • OS: Debian 10 Buster
  • Kernel: Linux 4.19.0-24-amd64
  • Go: 1.20
  • Server: Keycloak 23.0.1 (behind an Apache2 reverse proxy)
  • Gatekeeper: 2.9.1

Expected Results

The calls should work as expected and deliver the same result as with version 2.9.0 of the gatekeeper.

Actual Results

refresh token failed verification {"error": "invalid token signature\noidc: id token signed with unsupported algorithm, expected [\"PS384\" \"ES384\" \"RS384\" \"ES256\" \"RS256\" \"ES512\" \"PS256\" \"PS512\" \"RS512\"] got \"HS256\""}
@p53
Copy link

p53 commented Dec 4, 2023 via email

@p53
Copy link

p53 commented Dec 4, 2023

@ZPascal fixed issue, please try 2.9.2-rc1

@p53 p53 added the bug Something isn't working label Dec 4, 2023
@p53 p53 added this to the 2.9.2 milestone Dec 4, 2023
@bogbert
Copy link

bogbert commented Dec 6, 2023

I still have the problem with the 2.9.2

@ZPascal
Copy link
Author

ZPascal commented Dec 6, 2023

I've tested the pre-release and can confirm that the solution does not work.

@p53
Copy link

p53 commented Dec 7, 2023

@ZPascal @bogbert could you please provide cmd line options which are you using and also some logs would be useful, you can post me also private msg on Discord, if you don't want to publish it here

@p53
Copy link

p53 commented Dec 7, 2023

ok, tried now, i see, hmm interesting why it wasn't catched by e2e tests, will have to look more closely on this, seems keycloak is using HS256 algorithm for refresh token signature not RS256 and it cannot be changed, probably they wanted this as another layer of security keycloak/keycloak#19893, but as i can see discovery endpoint returns also HS256 among supported algorithms, need to check more deeply what is happening

@p53
Copy link

p53 commented Dec 7, 2023

ok seems like module used for token verification doesn't support HS256

@p53
Copy link

p53 commented Dec 7, 2023

also see why it wasn't catched by e2e, refresh tokens were not enabled, i thought that they are, will add that option there

@bogbert
Copy link

bogbert commented Dec 7, 2023

I found an interesting post: https://keycloak.discourse.group/t/rs256-for-refresh-tokens/6849
According to mbonn's reply, Gatekeeper doesn't have to check the refresh token signature. This signature is produced by Keycloak and is only meant to be checked by Keycloak itself, that's why they can use HS256 (an algorithm with a symmetric key), and that's why libraries such as go-oidc don't support HS256.

@p53
Copy link

p53 commented Dec 7, 2023

@bogbert yes i know that keycloak will be checking it, i wanted to make it more secure ;), some other libs support also HS256 but in this case we will probably have to leave it like it is or make it separate feature as this would require to have also keycloak key for verifying hmac signature on refresh token and adding new library which i am a little bit afraid of because of quality of libs. Refresh tokens are already encrypted so this is some "replacement" for verifying validity of token

@p53
Copy link

p53 commented Dec 8, 2023

@bogbert @p53 you can try 2.9.3-rc1, i checked manually and also added e2e, looks fine

@ZPascal
Copy link
Author

ZPascal commented Dec 8, 2023

@p53 I've tested 2.9.3-rc1 and can confirm that it works on my side as expected. Thank you.

@bogbert
Copy link

bogbert commented Dec 8, 2023

It doesn't work for me, I have tls errors:

2023-12-08T10:15:45.135+0100    info    issuing access token for user   {"sub": "<user id>", "expires": "2023-12-08T10:16:45+01:00", "duration": "59.864084981s"}
2023-12-08T10:15:45.179+0100    error   Get "https://<fqdn>/auth/realms/<realm>/protocol/openid-connect/userinfo": tls: failed to verify certificate: x509: certificate is not valid for any names, but wanted tomatch <fqdn>

maybe skip-openid-provider-tls-verify: true is ignored

@p53
Copy link

p53 commented Dec 8, 2023

@bogbert this seems to be different issue, didn't touch these things, do you have idp session check on? Are you sure you don't have duplicate skip-openid-provider-tls-verify option once true and once false, can you post me config?

@bogbert
Copy link

bogbert commented Dec 8, 2023

@bogbert this seems to be different issue, didn't touch these things, do you have idp session check on?

No I don't use this option.
skip-openid-provider-tls-verify is present only once, and it's set to true
BTW, everything is working fine with 2.9.0, same settings
I'll send you my config by mail

@p53
Copy link

p53 commented Dec 8, 2023

@bogbert ok see where is the problem, idp session check is now on by default...but seems problem is in underlying library, Userinfo which calls is provider method, we correctly set provider options and insecure skip verify to true but this method ignores any settings in provider, quite unexpected, will need to check on library code if this was intentional for some reason or it is just bug, actually we already create new contexts with proper settings in code because of this, it should at least take provider settings as defaults and in case settings are provided in context take those, will have to probably make some comments in code for future

@p53
Copy link

p53 commented Dec 8, 2023

@bogbert you can try 2.9.3-rc2, that should do the trick, i didn't have time to setup/test it manually, will add tests later when i have time, also created issue coreos/go-oidc#402

@bogbert
Copy link

bogbert commented Dec 8, 2023

It's working with 2.9.3-rc2, thank you.

@p53 p53 modified the milestones: 2.9.2, 2.9.3 Dec 8, 2023
@p53 p53 self-assigned this Dec 11, 2023
@p53 p53 closed this as completed Dec 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

No branches or pull requests

3 participants