This repository has been archived by the owner on Jan 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 137
Support OAUTHBEARER mechanism for KoP #400
Merged
BewareMyPower
merged 8 commits into
streamnative:master
from
BewareMyPower:bewaremypower/add-oauthbearer-mechanism
Mar 12, 2021
Merged
Support OAUTHBEARER mechanism for KoP #400
BewareMyPower
merged 8 commits into
streamnative:master
from
BewareMyPower:bewaremypower/add-oauthbearer-mechanism
Mar 12, 2021
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BewareMyPower
changed the title
Support OAUTHBEARER mechanism for KoP
[WIP] Support OAUTHBEARER mechanism for KoP
Mar 11, 2021
Mark this PR as WIP first. The failed spotbugs check and Codacy check need to fix. And I'll add a mocked server callback handler to verify if the config |
BewareMyPower
changed the title
[WIP] Support OAUTHBEARER mechanism for KoP
Support OAUTHBEARER mechanism for KoP
Mar 11, 2021
@jiazhai PTAL. BTW, I found Codacy Static Code Analysis has a bug. It check the code from the |
jiazhai
approved these changes
Mar 12, 2021
BewareMyPower
added a commit
that referenced
this pull request
Mar 19, 2021
Based on the framework from #400, this PR adds two callback handlers and their associated configs: - `OauthLoginCallbackHandler` and `ClientConfig`: They are in an independent module and for Kafka client to get access token from a third-party OAuth 2.0 authorization server. It requires issuer URI, credential file's URI and andience, just like what Pulsar client does. - `OauthValidatorCallbackHandler` and `ServerConfig`: It validates the client's access token using Pulsar's `AuthenticationProvider` whose `authMethod` is determined by a config of `ServerConfig`. Since the validate callback handler is created by `SaslServer`, we cannot pass construct params to it. So this PR makes `AuthenticationService` static so that the callback handler could access it. Also this PR exposed the role (or authorization id) for the implementation of authorization in future. Unit tests are added for `ServerConfig` and `ClientConfig` and an integration test is added for OAuth 2.0 authentication with the new added callback handlers in this PR.
jiazhai
pushed a commit
that referenced
this pull request
Mar 24, 2021
#400 makes KoP support OAUTHBEARER mechanism. Also it introduced two new configs `kopOauth2AuthenticateCallbackHandler` and `kopOauth2ConfigFile`, which are the OAuth 2.0 server callback handler and its config file. However, after that, if KoP enables PLAIN mechanism, `kopOauth2ConfigFile` must be configured too, because `SaslAuthenticator` tries to load the callback handler and its config file no matter what the configured mechanism are. If user didn't configure them, NPE would be thrown like ``` java.lang.NullPointerException: null at java.util.Properties$LineReader.readLine(Properties.java:434) ~[?:1.8.0_261] at java.util.Properties.load0(Properties.java:353) ~[?:1.8.0_261] at java.util.Properties.load(Properties.java:341) ~[?:1.8.0_261] at io.streamnative.pulsar.handlers.kop.KafkaServiceConfiguration.getKopOauth2Properties(KafkaServiceConfiguration.java:353) ~[?:?] at io.streamnative.pulsar.handlers.kop.security.SaslAuthenticator.createOauth2CallbackHandler(SaslAuthenticator.java:174) ~[?:?] at io.streamnative.pulsar.handlers.kop.security.SaslAuthenticator.<init>(SaslAuthenticator.java:108) ~[?:?] ``` The existed tests didn't expose this bug because if `kopOauth2ConfigFile` was not configured, it would try to read `kop-oauth2.properties` from the resource directory and the file exists here. So this PR only loads the OAuth 2.0 server callback handler if the mechanism contain `OAUTHBEARER`. In addition, this PR removes the default file path of `kopOauth2ConfigFile`.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR introduces OAUTHBEARER mechanism to KoP.
Two config items are added. One is the server callback handler to validate OAUTHBEARER token, the other is the properties configuration file that contains the server callback handler's configs. The default server callback handler is the same as Kafka, which validates unsecured JSON Web Tokens.
In addition, the authenticator is refactored that now it uses different
SaslServer
for different mechanisms to perform authentication.Related tests are added to verify these configs and the default server callback handler:
KafkaServerConfiguration#testGetKopOauth2Configs
: unit test forgetKopOauth2Properties
method.SaslOAuthBearerTest
: testOAUTHBEARER
SASL mechanism with Kafka's default server callback handler.CustomOAuthBearerCallbackHandlerTest
: test customAuthenticateCallbackHandler
.