KAFKA-7462: Make token optional for OAuthBearerLoginModule - #5733
Conversation
|
@rondagostino Can you review, please? Thank you! |
|
@rajinisivaram Before I review, is it possible simply to mark the LoginModule as OPTIONAL in the case where it is one of multiple login modules on the broker side but it is not used for inter-broker communication? The Javadoc (https://docs.oracle.com/javase/7/docs/api/javax/security/auth/spi/LoginModule.html#commit()) says a return of false means the module is ignored, and I confirmed in the debugger that it is in fact the case (see, for example, https://github.com/frohoff/jdk8u-dev-jdk/blob/master/src/share/classes/javax/security/auth/login/LoginContext.java#L779). See also https://docs.oracle.com/javase/7/docs/api/javax/security/auth/login/Configuration.html where it says:
|
|
@rajinisivaram Ah, wait, I think I see the issue. If we want to add a listener, then it may be the only LoginModule listed. Is that correct? In the meantime, I will review. |
|
@rondagostino We need one login module that succeeds. With the |
rondagostino
left a comment
There was a problem hiding this comment.
LGTM aside from the minor comments.
| @@ -93,7 +93,7 @@ public String errorUri() { | |||
| * the mandatory token to set | |||
There was a problem hiding this comment.
Javadoc should say "optional" now instead of "mandatory"
| public class OAuthBearerLoginModule implements LoginModule { | ||
|
|
||
| private enum LoginState { | ||
| NOT_LOGGED_IN, |
There was a problem hiding this comment.
Would be good to comment that this implies logged-out or aborted since the state is null at the beginning (when we aren't logged in, either, but we don't set the state to NOT_LOGGED_IN). Either comment or rename to LOGGED_OUT_OR_ABORTED?
There was a problem hiding this comment.
Added comment.
| identifyExtensions(); | ||
| } else { | ||
| log.info("Logged in without a token, this login cannot be used to establish client connections"); | ||
| } |
There was a problem hiding this comment.
nit: style seems to be to not include braces when there is only one if or else statement
| log.info("Done logging out my extensions"); | ||
| } else { | ||
| log.info("No extensions to logout for this login"); | ||
| } |
| log.info("Done committing my token; committed token count is now {}", committedTokenCount()); | ||
| } else { | ||
| log.info("No tokens to commit, this login cannot be used to establish client connections"); | ||
| } |
| extensionsRequiringCommit = null; | ||
| if (extensionsRequiringCommit != null) { | ||
| if (myCommittedToken == null) | ||
| throw new IllegalStateException("Extensions being committed without a token"); |
There was a problem hiding this comment.
Is the myCommittedToken == null check unnecessary here since it can never be the case when there are extensions? I think we make sure of this since we only call identifyExtensions() when there is a token.
|
@rondagostino Thanks for the review, have addressed the comments. |
|
retest this please |
junrao
left a comment
There was a problem hiding this comment.
@rajinisivaram : Thanks for the patch. LGTM
| if (callback.token() != null) | ||
| throw new IllegalArgumentException("Callback had a token already"); | ||
| if (moduleOptions.isEmpty()) { | ||
| log.info("Token not provided, this login cannot be used to establish client connections"); |
There was a problem hiding this comment.
Does this get logged on the broker side? Will that be too noisy?
There was a problem hiding this comment.
@junrao Thanks for the review, I have changed all the new log entries to debug. We also have https://issues.apache.org/jira/browse/KAFKA-7478 to reduce the level of some of the existing log entries.
|
Merging to trunk and 2.1. |
OAuthBearerLoginModule is used both on the server-side and client-side (similar to login modules for other mechanisms). OAUTHBEARER tokens are client credentials used only on the client-side to authenticate with servers, but the current implementation requires tokens to be provided on the server-side even if OAUTHBEARER is not used for inter-broker communication. This commit makes tokens optional for server-side login context to allow brokers to be configured without a token when OAUTHBEARER is not used for inter-broker communication. Reviewers: Ron Dagostino <rndgstn@gmail.com>, Jun Rao <junrao@gmail.com>
OAuthBearerLoginModule is used both on the server-side and client-side (similar to login modules for other mechanisms). OAUTHBEARER tokens are client credentials used only on the client-side to authenticate with servers, but the current implementation requires tokens to be provided on the server-side even if OAUTHBEARER is not used for inter-broker communication. This commit makes tokens optional for server-side login context to allow brokers to be configured without a token when OAUTHBEARER is not used for inter-broker communication. Reviewers: Ron Dagostino <rndgstn@gmail.com>, Jun Rao <junrao@gmail.com>
|
@kirktrue, @rajinisivaram Hi! |
|
@AntonSmolkov would you mind filing a new Jira to track? Thanks! |
OAuthBearerLoginModule is used both on the server-side and client-side (similar to login modules for other mechanisms). OAUTHBEARER tokens are client credentials used only on the client-side to authenticate with servers, but the current implementation requires tokens to be provided on the server-side even if OAUTHBEARER is not used for inter-broker communication. Tokens should be optional for server-side login context to allow brokers to be configured without a token when OAUTHBEARER is not used for inter-broker communication.
Committer Checklist (excluded from commit message)