Skip to content

Fix oauth2 and jwt authentificaor interference#13662

Merged
Praveen2112 merged 1 commit intotrinodb:masterfrom
s2lomon:fix-oauth2-jwt-interference
Sep 21, 2022
Merged

Fix oauth2 and jwt authentificaor interference#13662
Praveen2112 merged 1 commit intotrinodb:masterfrom
s2lomon:fix-oauth2-jwt-interference

Conversation

@s2lomon
Copy link
Copy Markdown
Member

@s2lomon s2lomon commented Aug 12, 2022

Description

Beore this fix, when oauth2 with refresh token is enabled
along with jwt authenticator, user couldn't log in
by using standard jwt token. After the fix, every attempt of sending
token that can't be consumed by oauth2 authenticator will result in
standard AuthenticationError, that plays along the contract of Authentificators

Is this change a fix, improvement, new feature, refactoring, or other?

Fixes #13575

Is this a change to the core query engine, a connector, client library, or the SPI interfaces? (be specific)

OAuth2 Authentification - core

How would you describe this change to a non-technical end user or system administrator?

Brings back possibility of using both OAuth2 and jwt at the same time.

Related issues, pull requests, and links

Documentation

(x) No documentation is needed.
( ) Sufficient documentation is included in this PR.
( ) Documentation PR is available with #prnumber.
( ) Documentation issue #issuenumber is filed, and can be handled later.

Release notes

( ) No release notes entries required.
(x) Release notes entries required with the following suggested text:

# Section
* OAuth Token Refresh will no longer cause JWT authentication failure  ({issue}`13575`)

@cla-bot cla-bot bot added the cla-signed label Aug 12, 2022
@s2lomon s2lomon force-pushed the fix-oauth2-jwt-interference branch from 699e01d to 621112a Compare August 12, 2022 23:14
Copy link
Copy Markdown
Contributor

@andrewdibiasio6 andrewdibiasio6 Aug 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to just catch java.lang.IllegalArgumentException for now?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we narrow down the catching ? What if the token fails because it is damaged or expired ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok so this catch is so wide on purpose. Right now there are plenty of reasons why token deserialization might fail. We might be having invalid token (on purpose - like in this bug scenario), token might have expired - meaning that both access token and refresh token are either expired or soon to be expired, encryption keys might have been rolled out (after restart) etc. All of the above suggests that we need to discard the token, but we should not request any specific handling of these errors. Rather I think we should just discard this token and issue another challenge to the client - so business as usual. I could narrow catching to IllegalArgumentException (with allowing the possibility that some other valid case might not be handled atm), but then I would like to add this to official contract of the TokenPairSerializer interface as a throws. Catching implementation specific exceptions is not a best design decision.

Copy link
Copy Markdown
Contributor

@andrewdibiasio6 andrewdibiasio6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for the fix.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we narrow down the catching ? What if the token fails because it is damaged or expired ?

Copy link
Copy Markdown
Member

@kokosing kokosing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a typo in the commit message.

user couldn't log in by using standard jwt token.

Can you please explain why in the commit message too?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: s/LOG/log

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping :)

@lukasz-walkiewicz
Copy link
Copy Markdown
Member

Looks good but test is definitely needed. Please take a look at: io.trino.server.security.TestResourceSecurity#testJwtAndOAuth2AuthenticatorsSeparation

@s2lomon s2lomon force-pushed the fix-oauth2-jwt-interference branch 2 times, most recently from 11eb861 to 83b5471 Compare August 30, 2022 09:39
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

separate commit

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping :)

@s2lomon s2lomon force-pushed the fix-oauth2-jwt-interference branch from 83b5471 to 734cc1e Compare September 6, 2022 13:00
@kokosing
Copy link
Copy Markdown
Member

@s2lomon the build is red

@s2lomon s2lomon force-pushed the fix-oauth2-jwt-interference branch from 734cc1e to 67eb882 Compare September 20, 2022 09:01
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can test with the config that causes the issue i.e http-server.authentication.type=oauth2,JWT ?

Before this fix, when oauth2 with refresh token is enabled
along with jwt authenticator, user couldn't log in
by using standard jwt token.

It was occuring due to incorect handling of tokens
that are in different format than the one issued
by the OAuth2 implementation to store refresh tokens.
After the fix in such case OAuth2 will just issue another
challenge to the client.
@s2lomon s2lomon force-pushed the fix-oauth2-jwt-interference branch from 67eb882 to 7604166 Compare September 20, 2022 13:29
@Praveen2112 Praveen2112 merged commit ee753bf into trinodb:master Sep 21, 2022
@github-actions github-actions bot added this to the 397 milestone Sep 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

OAuth Token Refresh will cause JWT authentication to fail

5 participants