-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[KAFKA-13848] Clients remain connected after SASL re-authentication f… #12179
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -679,10 +679,11 @@ private long calcCompletionTimesAndReturnSessionLifetimeMs() { | |
| else if (connectionsMaxReauthMs == null) | ||
| retvalSessionLifetimeMs = zeroIfNegative(credentialExpirationMs - authenticationEndMs); | ||
| else | ||
| retvalSessionLifetimeMs = zeroIfNegative( | ||
| Math.min(credentialExpirationMs - authenticationEndMs, connectionsMaxReauthMs)); | ||
| if (retvalSessionLifetimeMs > 0L) | ||
| retvalSessionLifetimeMs = zeroIfNegative(Math.min(credentialExpirationMs - authenticationEndMs, connectionsMaxReauthMs)); | ||
|
|
||
| if (connectionsMaxReauthMs != null) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think I have a different understanding. My mental model was that if either of I think your original change to make setting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @showuon what is your thinking on this?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@SamBarker ,I don't understand this. Which property are you referring to?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, for @SamBarker , I think we can discuss the property change in a separate thread since it's related to tests. For this change: I understand why you did this @acsaki . It's because you think:
I think it's correct, IF the sasl client did close the connection after the That is, no matter the reauth is enabled or not, we set the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, the debug line in L698 confused me a little. When The point I'm confused here is
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rondagostino @rajinisivaram , do you have any comments? Thanks.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @showuon this is what I've also found rather confusing. I agree that after the token expires the connection should be closed sooner or later which isn't going to happen when sessionExpirationTimeNanos is not set. While there is the Authenticator interface where comments suggest that #serverSessionExpirationTimeNanos should be left as null when re-authentication is "disabled". Does it make sense for reauth to be disabled? Or rather there are some clients or SASL mechanisms where we don't expect reauthentication to ever happen?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Is this javadoc what you mean? From the javadoc, I don't see it said we should return null for re-auth disabled. I think it's OK to return the value when re-auth disabled.
Yes, it is. You can check this for reference. Thanks. |
||
| sessionExpirationTimeNanos = authenticationEndNanos + 1000 * 1000 * retvalSessionLifetimeMs; | ||
| } | ||
| } | ||
| if (credentialExpirationMs != null) { | ||
| if (sessionExpirationTimeNanos != null) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -781,14 +781,13 @@ public void testConnectDisconnectDuringInSinglePoll() throws Exception { | |
| when(kafkaChannel.selectionKey()).thenReturn(selectionKey); | ||
| when(selectionKey.channel()).thenReturn(SocketChannel.open()); | ||
| when(selectionKey.readyOps()).thenReturn(SelectionKey.OP_CONNECT); | ||
| when(selectionKey.attachment()).thenReturn(kafkaChannel); | ||
|
|
||
| selectionKey.attach(kafkaChannel); | ||
| Set<SelectionKey> selectionKeys = Utils.mkSet(selectionKey); | ||
| selector.pollSelectionKeys(selectionKeys, false, System.nanoTime()); | ||
|
|
||
| assertFalse(selector.connected().contains(kafkaChannel.id())); | ||
| assertTrue(selector.disconnected().containsKey(kafkaChannel.id())); | ||
| assertNull(selectionKey.attachment()); | ||
|
Comment on lines
+784
to
-791
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why we did this change? Did we change anything affect this test?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test failed after my change to use mockitoInline to mock statics. The
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the explanation. I agree with the change. Make sense. |
||
|
|
||
| verify(kafkaChannel, atLeastOnce()).ready(); | ||
| verify(kafkaChannel).disconnect(); | ||
|
|
@@ -976,8 +975,11 @@ public void testChannelCloseWhileProcessingReceives() throws Exception { | |
| SelectionKey selectionKey = mock(SelectionKey.class); | ||
| when(channel.selectionKey()).thenReturn(selectionKey); | ||
| when(selectionKey.isValid()).thenReturn(true); | ||
| when(selectionKey.isReadable()).thenReturn(true); | ||
| when(selectionKey.readyOps()).thenReturn(SelectionKey.OP_READ); | ||
| selectionKey.attach(channel); | ||
| when(selectionKey.attachment()) | ||
| .thenReturn(channel) | ||
| .thenReturn(null); | ||
|
Comment on lines
+978
to
+982
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, why this change?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. |
||
| selectionKeys.add(selectionKey); | ||
|
|
||
| NetworkReceive receive = mock(NetworkReceive.class); | ||
|
|
||
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.
Could you explain why we need MockitoInline here? Any method only exists in
mockitoInline?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.
I needed this to mock out ChannelBuilders#createPrincipalBuilder and Sasl#createSaslServer. It's a petty there are these static calls, hard to test them.
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.
ChannelBuildersis our code, we should avoid mocking static methods.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.
@acsaki , as @ijuma suggested, would you file another small PR to update the tests to avoid mocking the static methods? For the
ChannelBuilders#createPrincipalBuilder, it looks like we actually don't need it for these tests, right? (the tests still pass after I removed them)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.
bump, I second we should aim to remove this