You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "philipnee (via GitHub)" <gi...@apache.org> on 2024/07/30 03:38:30 UTC
[PR] KAFKA-17188: Ensure login and callback handler are closed upon encountering LoginException [kafka]
philipnee opened a new pull request, #16724:
URL: https://github.com/apache/kafka/pull/16724
Adding a try-catch in the LoginManager constructor to ensure `Login` and `AuthenticateCallbackHandler` are closed when login.login() throws an exception.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-17188: Ensure login and callback handler are closed upon encountering LoginException [kafka]
Posted by "rajinisivaram (via GitHub)" <gi...@apache.org>.
rajinisivaram merged PR #16724:
URL: https://github.com/apache/kafka/pull/16724
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-17188: Ensure login and callback handler are closed upon encountering LoginException [kafka]
Posted by "philipnee (via GitHub)" <gi...@apache.org>.
philipnee commented on code in PR #16724:
URL: https://github.com/apache/kafka/pull/16724#discussion_r1696234213
##########
clients/src/main/java/org/apache/kafka/common/security/authenticator/LoginManager.java:
##########
@@ -168,6 +172,11 @@ public String toString() {
", refCount=" + refCount + ')';
}
+ private void closeResources() {
+ if (login != null) login.close();
Review Comment:
Should we `closeQuietly` for both resources?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-17188: Ensure login and callback handler are closed upon encountering LoginException [kafka]
Posted by "frankvicky (via GitHub)" <gi...@apache.org>.
frankvicky commented on code in PR #16724:
URL: https://github.com/apache/kafka/pull/16724#discussion_r1697183779
##########
clients/src/test/java/org/apache/kafka/common/security/authenticator/LoginManagerTest.java:
##########
@@ -153,6 +163,32 @@ public void testLoginManagerWithDifferentConfigs() throws Exception {
verifyLoginManagerRelease(staticLogin2, 2, staticContext, configs2);
}
+ @Test
+ public void testLoginException() throws Exception {
+ Map<String, Object> config = new HashMap<>();
+ config.put("sasl.jaas.config", dynamicPlainContext);
Review Comment:
I think we could use `SaslConfigs.SASL_JAAS_CONFIG` here instead of this plain string literal.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-17188: Ensure login and callback handler are closed upon encountering LoginException [kafka]
Posted by "rajinisivaram (via GitHub)" <gi...@apache.org>.
rajinisivaram commented on PR #16724:
URL: https://github.com/apache/kafka/pull/16724#issuecomment-2259879248
@philipnee Thanks for the PR. Test failures not related, merging to trunk.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-17188: Ensure login and callback handler are closed upon encountering LoginException [kafka]
Posted by "philipnee (via GitHub)" <gi...@apache.org>.
philipnee commented on code in PR #16724:
URL: https://github.com/apache/kafka/pull/16724#discussion_r1697480402
##########
clients/src/main/java/org/apache/kafka/common/security/authenticator/LoginManager.java:
##########
@@ -55,13 +59,17 @@ public class LoginManager {
private int refCount;
private LoginManager(JaasContext jaasContext, String saslMechanism, Map<String, ?> configs,
- LoginMetadata<?> loginMetadata) throws LoginException {
+ LoginMetadata<?> loginMetadata) throws LoginException {
this.loginMetadata = loginMetadata;
this.login = Utils.newInstance(loginMetadata.loginClass);
loginCallbackHandler = Utils.newInstance(loginMetadata.loginCallbackClass);
loginCallbackHandler.configure(configs, saslMechanism, jaasContext.configurationEntries());
login.configure(configs, jaasContext.name(), jaasContext.configuration(), loginCallbackHandler);
- login.login();
+ try (AutoCloseable loginResources = this::closeResources) {
Review Comment:
I was wondering about that, i think that's a sounded suggestion.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-17188: Ensure login and callback handler are closed upon encountering LoginException [kafka]
Posted by "philipnee (via GitHub)" <gi...@apache.org>.
philipnee commented on PR #16724:
URL: https://github.com/apache/kafka/pull/16724#issuecomment-2257402065
Hello @rajinisivaram - Here is the PR for the issue for not closing the login and handler upon LoginException. If you get time, would you be kindly reviewing this? Thanks!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-17188: Ensure login and callback handler are closed upon encountering LoginException [kafka]
Posted by "frankvicky (via GitHub)" <gi...@apache.org>.
frankvicky commented on code in PR #16724:
URL: https://github.com/apache/kafka/pull/16724#discussion_r1697183779
##########
clients/src/test/java/org/apache/kafka/common/security/authenticator/LoginManagerTest.java:
##########
@@ -153,6 +163,32 @@ public void testLoginManagerWithDifferentConfigs() throws Exception {
verifyLoginManagerRelease(staticLogin2, 2, staticContext, configs2);
}
+ @Test
+ public void testLoginException() throws Exception {
+ Map<String, Object> config = new HashMap<>();
+ config.put("sasl.jaas.config", dynamicPlainContext);
Review Comment:
I think we could use `SaslConfigs.SASL_JAAS_CONFIG` here instead of this plain string literal.
I have seen the following config key also use the const from `SaslConfigs`, so it would be nice to align with them.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-17188: Ensure login and callback handler are closed upon encountering LoginException [kafka]
Posted by "rajinisivaram (via GitHub)" <gi...@apache.org>.
rajinisivaram commented on code in PR #16724:
URL: https://github.com/apache/kafka/pull/16724#discussion_r1697348597
##########
clients/src/main/java/org/apache/kafka/common/security/authenticator/LoginManager.java:
##########
@@ -55,13 +59,17 @@ public class LoginManager {
private int refCount;
private LoginManager(JaasContext jaasContext, String saslMechanism, Map<String, ?> configs,
- LoginMetadata<?> loginMetadata) throws LoginException {
+ LoginMetadata<?> loginMetadata) throws LoginException {
this.loginMetadata = loginMetadata;
this.login = Utils.newInstance(loginMetadata.loginClass);
loginCallbackHandler = Utils.newInstance(loginMetadata.loginCallbackClass);
loginCallbackHandler.configure(configs, saslMechanism, jaasContext.configurationEntries());
login.configure(configs, jaasContext.name(), jaasContext.configuration(), loginCallbackHandler);
- login.login();
+ try (AutoCloseable loginResources = this::closeResources) {
Review Comment:
Should we move `login.configure` and `loginCallbackHandler.configure` into the try-catch block so that we cleanup if either fails?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-17188: Ensure login and callback handler are closed upon encountering LoginException [kafka]
Posted by "philipnee (via GitHub)" <gi...@apache.org>.
philipnee commented on code in PR #16724:
URL: https://github.com/apache/kafka/pull/16724#discussion_r1697218491
##########
clients/src/test/java/org/apache/kafka/common/security/authenticator/LoginManagerTest.java:
##########
@@ -153,6 +163,32 @@ public void testLoginManagerWithDifferentConfigs() throws Exception {
verifyLoginManagerRelease(staticLogin2, 2, staticContext, configs2);
}
+ @Test
+ public void testLoginException() throws Exception {
+ Map<String, Object> config = new HashMap<>();
+ config.put("sasl.jaas.config", dynamicPlainContext);
Review Comment:
Good point, thanks a lot for the pointer.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org