-
Notifications
You must be signed in to change notification settings - Fork 14.4k
KAFKA-18847: Refactor OAuth layer to improve reusability 1/N #19622
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
base: trunk
Are you sure you want to change the base?
KAFKA-18847: Refactor OAuth layer to improve reusability 1/N #19622
Conversation
Rename AccessTokenRetriever and AccessTokenValidator to JwtRetriever and JwtValidator, respectively. Also converting the factory pattern classes AccessTokenRetrieverFactory and AccessTokenValidatorFactory into delegate/wrapper classes DefaultJwtRetriever and DefaultJwtValidator, respectively. These are all internal changes, no configuration, user APIs, RPCs, etc. were changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @kirktrue ! No major concerns, some comments for consideration
...c/main/java/org/apache/kafka/common/security/oauthbearer/internals/secured/JwtValidator.java
Show resolved
Hide resolved
...n/java/org/apache/kafka/common/security/oauthbearer/OAuthBearerValidatorCallbackHandler.java
Outdated
Show resolved
Hide resolved
.../java/org/apache/kafka/common/security/oauthbearer/internals/secured/BrokerJwtValidator.java
Outdated
Show resolved
Hide resolved
.../java/org/apache/kafka/common/security/oauthbearer/internals/secured/ClientJwtValidator.java
Show resolved
Hide resolved
.../java/org/apache/kafka/common/security/oauthbearer/internals/secured/ClientJwtValidator.java
Outdated
Show resolved
Hide resolved
...java/org/apache/kafka/common/security/oauthbearer/internals/secured/DefaultJwtValidator.java
Show resolved
Hide resolved
...in/java/org/apache/kafka/common/security/oauthbearer/internals/secured/FileJwtRetriever.java
Outdated
Show resolved
Hide resolved
...in/java/org/apache/kafka/common/security/oauthbearer/internals/secured/HttpJwtRetriever.java
Outdated
Show resolved
Hide resolved
...in/java/org/apache/kafka/common/security/oauthbearer/internals/secured/HttpJwtRetriever.java
Outdated
Show resolved
Hide resolved
.../org/apache/kafka/common/security/oauthbearer/internals/secured/JwtValidatorFactoryTest.java
Outdated
Show resolved
Hide resolved
… close() methods from BrokerJwtValidator and ClientJwtValidator
…od instead of the clumsier validateBoolean() method
Thanks for the review, @lianetm! I've fixed the issues you've mentioned and tested locally, but I'll watch the result of the CI job. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @kirktrue for this patch, a little comments
...ache/kafka/common/security/oauthbearer/internals/secured/VerificationKeyResolverFactory.java
Outdated
Show resolved
Hide resolved
...va/org/apache/kafka/common/security/oauthbearer/OAuthBearerValidatorCallbackHandlerTest.java
Outdated
Show resolved
Hide resolved
List<String> l = cu.get(SASL_OAUTHBEARER_EXPECTED_AUDIENCE); | ||
|
||
if (l != null) | ||
expectedAudiences = Set.copyOf(l); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we could update the variable name l
to something more descriptive for better readability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😆 Yes, I'll update it. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated. Thanks!
…arer/internals/secured/VerificationKeyResolverFactory.java Co-authored-by: Ken Huang <s7133700@gmail.com>
…arer/OAuthBearerValidatorCallbackHandlerTest.java Co-authored-by: Ken Huang <s7133700@gmail.com>
Fixed missing import from hastily taking GitHub PR suggestion
…wtValidator.init()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates @kirktrue ! One important bit I just noticed, lmk
public void init(AccessTokenRetriever accessTokenRetriever, AccessTokenValidator accessTokenValidator) { | ||
this.accessTokenRetriever = accessTokenRetriever; | ||
this.accessTokenValidator = accessTokenValidator; | ||
public void init(JwtRetriever jwtRetriever, JwtValidator jwtValidator) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uhm the OAuthBearerLoginCallbackHandler
class is part of the public API, so changing params in this public
method would be a breaking change not accounted for in the KIP, right?
It's a tricky situation because the class of the params is not public API (AccessTokenRetriever
).
This init is only used internally, and I expect is not intended to be called directly ever (only indirectly from the public API configure
). So I would say that having this init
public is what's wrong in the first place?
Anyways, fact is that it is public API at the moment (https://kafka.apache.org/40/javadoc/org/apache/kafka/common/security/oauthbearer/OAuthBearerLoginCallbackHandler.html), so we need to amend the KIP I would expect, to remove this init overload from the public API (move to package-private). Since it's based on non-public param types it's probably safe to assume no one should be really using it (but not sure if I'm missing something here). Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I would say that having this init public is what's wrong in the first place?
This method is only public
by virtue of the awkwardness of the unit tests. I'd prefer to make the init()
method package protected
, or just remove it altogether. The existence of init()
was not mentioned in the previous KIP
(KIP-768), so my thought is that it can be changed without updating the KIP.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we originally added these classes, the methods were package-protected for testing purposes:
Initial PR
Later, when the packages were reorganized, the methods were made public:
Follow-up PR
I agree that since these methods are only used in tests and invoked exclusively for testing, it’s reasonable to update or delete them.
…dler and OAuthBearerValidatorCallbackHandler
@@ -36,32 +39,27 @@ | |||
import static org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginCallbackHandler.CLIENT_SECRET_CONFIG; | |||
import static org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginCallbackHandler.SCOPE_CONFIG; | |||
|
|||
public class AccessTokenRetrieverFactory { | |||
public class DefaultJwtRetriever implements JwtRetriever { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add Javadoc?
@@ -177,57 +178,41 @@ public class OAuthBearerLoginCallbackHandler implements AuthenticateCallbackHand | |||
|
|||
private static final String EXTENSION_PREFIX = "extension_"; | |||
|
|||
private Map<String, Object> moduleOptions; | |||
protected Map<String, Object> moduleOptions; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we avoid protected in these public classes. maybe we can add package-private getters/etc.. for testing
Rename
AccessTokenRetriever
andAccessTokenValidator
toJwtRetriever
andJwtValidator
, respectively. Also converting thefactory pattern classes
AccessTokenRetrieverFactory
andAccessTokenValidatorFactory
into delegate/wrapper classesDefaultJwtRetriever
andDefaultJwtValidator
, respectively.These are all internal changes, no configuration, user APIs, RPCs, etc.
were changed.