Skip to content

Support for multiple keys with same kid, which differ just by algorit… - #15114

Merged
stianst merged 1 commit into
keycloak:mainfrom
mposolda:14794-same-kid-bug
Nov 3, 2022
Merged

stianst merged 1 commit into
keycloak:mainfrom
mposolda:14794-same-kid-bug

Conversation

@mposolda

@mposolda mposolda commented Oct 24, 2022 •

Copy link
Copy Markdown
Contributor

…hm in the JWKS

Closes #14794

@stianst @pedroigor Anyone of you is able to review this one please? During investigation of #14794, I figured that we didn't have proper support for the JWKS with multiple keys of same kid (where those keys with same kid differ by algorithm).

So the issue #14794 is a regression, but it worked before likely just by accident (it looks the right key was accidentally chosen in Keycloak 18 for the particular user's scenario, which stopped working due some refactoring done in Keycloak 19 because of some work done on #11036 )

@mposolda mposolda self-assigned this Oct 24, 2022
@mposolda
mposolda requested review from pedroigor and stianst October 25, 2022 07:05
@martin-scheelke

Copy link
Copy Markdown

@mposolda, the current fix appears to use the combination of "kid" and "alg" to identify a key within a JWKS which is an improvement.
But what if a JWKS has a set of keys with the same "kid" and "alg" but differing "use" and "kty" ?
It appears from the standard that this is valid: https://www.rfc-editor.org/rfc/rfc7517#section-4.4

@mposolda

Copy link
Copy Markdown
Contributor Author

@mposolda, the current fix appears to use the combination of "kid" and "alg" to identify a key within a JWKS which is an improvement. But what if a JWKS has a set of keys with the same "kid" and "alg" but differing "use" and "kty" ? It appears from the standard that this is valid: https://www.rfc-editor.org/rfc/rfc7517#section-4.4

@martin-scheelke Good point and I was also thinking about this before. However:

  • The case with 2 keys with same kid and alg, but different kty should not be possible. As when you have 2 keys with same kid and alg, then they should also have same kty in the case of valid JWKS. For example assume that you have keys with kid abc and algorithm RS256, then the kty should be RSA for both of them.
  • The case with 2 keys with same kid and alg, but different use is possible in theory. However this would be fine as both ClientPublicKeyLoader and OIDCIdentityProviderPublicKeyLoader takes the use into consideration and already filters the keys by use .

@martin-scheelke

Copy link
Copy Markdown

@mposolda, the current fix appears to use the combination of "kid" and "alg" to identify a key within a JWKS which is an improvement. But what if a JWKS has a set of keys with the same "kid" and "alg" but differing "use" and "kty" ? It appears from the standard that this is valid: https://www.rfc-editor.org/rfc/rfc7517#section-4.4

@martin-scheelke Good point and I was also thinking about this before. However:

  • The case with 2 keys with same kid and alg, but different kty should not be possible. As when you have 2 keys with same kid and alg, then they should also have same kty in the case of valid JWKS. For example assume that you have keys with kid abc and algorithm RS256, then the kty should be RSA for both of them.
  • The case with 2 keys with same kid and alg, but different use is possible in theory. However this would be fine as both ClientPublicKeyLoader and OIDCIdentityProviderPublicKeyLoader takes the use into consideration and already filters the keys by use .

@mposolda Sounds ok. The "kid"/"alg" combination will solve our immediate problem anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error when using similar keys with different algorithms in a jwks for identity provider signature validation

3 participants