-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-9577: SaslClientAuthenticator incorrectly negotiates SASL_HANDSHAKE version #8142
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -677,7 +677,7 @@ public void testUnauthenticatedApiVersionsRequestOverSslHandshakeVersion1() thro | |
| * {@link SaslServerAuthenticator} of the server prior to client authentication. | ||
| */ | ||
| @Test | ||
| public void testApiVersionsRequestWithUnsupportedVersion() throws Exception { | ||
| public void testApiVersionsRequestWithServerUnsupportedVersion() throws Exception { | ||
|
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. Rename as this only tested part of the version support. |
||
| short handshakeVersion = ApiKeys.SASL_HANDSHAKE.latestVersion(); | ||
| SecurityProtocol securityProtocol = SecurityProtocol.SASL_PLAINTEXT; | ||
| configureMechanisms("PLAIN", Arrays.asList("PLAIN")); | ||
|
|
@@ -714,6 +714,25 @@ public void testApiVersionsRequestWithUnsupportedVersion() throws Exception { | |
| authenticateUsingSaslPlainAndCheckConnection(node, handshakeVersion > 0); | ||
| } | ||
|
|
||
| /** | ||
| * Tests correct negotiation of handshake and authenticate api versions by having the server | ||
| * return a higher version than supported on the client. | ||
| * Note, that due to KAFKA-9577 this will require a workaround to effectively bump | ||
| * SASL_HANDSHAKE in the future. | ||
| */ | ||
| @Test | ||
| public void testSaslUnsupportedClientVersions() throws Exception { | ||
| configureMechanisms("SCRAM-SHA-512", Arrays.asList("SCRAM-SHA-512")); | ||
|
|
||
| server = startServerApiVersionsUnsupportedByClient(SecurityProtocol.SASL_SSL, "SCRAM-SHA-512"); | ||
| updateScramCredentialCache(TestJaasConfig.USERNAME, TestJaasConfig.PASSWORD); | ||
|
|
||
| String node = "0"; | ||
|
|
||
| createClientConnection(SecurityProtocol.SASL_SSL, "SCRAM-SHA-512", node, true); | ||
| NetworkTestUtils.checkClientConnection(selector, "0", 100, 10); | ||
| } | ||
|
|
||
| /** | ||
| * Tests that invalid ApiVersionRequest is handled by the server correctly and | ||
| * returns an INVALID_REQUEST error. | ||
|
|
@@ -748,6 +767,16 @@ public void testInvalidApiVersionsRequest() throws Exception { | |
| authenticateUsingSaslPlainAndCheckConnection(node, handshakeVersion > 0); | ||
| } | ||
|
|
||
|
|
||
| @Test | ||
| public void testForBrokenSaslHandshakeVersionBump() { | ||
|
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. Block anyone from bumping the schema without realizing. |
||
| assertEquals("It is not possible to easily bump SASL_HANDSHAKE schema" | ||
| + " due to improper version negotiation in clients < 2.5." | ||
| + " Please see https://issues.apache.org/jira/browse/KAFKA-9577", | ||
| ApiKeys.SASL_HANDSHAKE.latestVersion(), | ||
| 1); | ||
| } | ||
|
|
||
| /** | ||
| * Tests that valid ApiVersionRequest is handled by the server correctly and | ||
| * returns an NONE error. | ||
|
|
@@ -1730,6 +1759,47 @@ private void createClientConnection(SecurityProtocol securityProtocol, String sa | |
| createClientConnectionWithoutSaslAuthenticateHeader(securityProtocol, saslMechanism, node); | ||
| } | ||
|
|
||
| private NioEchoServer startServerApiVersionsUnsupportedByClient(final SecurityProtocol securityProtocol, String saslMechanism) throws Exception { | ||
| final ListenerName listenerName = ListenerName.forSecurityProtocol(securityProtocol); | ||
| final Map<String, ?> configs = Collections.emptyMap(); | ||
| final JaasContext jaasContext = JaasContext.loadServerContext(listenerName, saslMechanism, configs); | ||
| final Map<String, JaasContext> jaasContexts = Collections.singletonMap(saslMechanism, jaasContext); | ||
|
|
||
| boolean isScram = ScramMechanism.isScram(saslMechanism); | ||
| if (isScram) | ||
| ScramCredentialUtils.createCache(credentialCache, Arrays.asList(saslMechanism)); | ||
| SaslChannelBuilder serverChannelBuilder = new SaslChannelBuilder(Mode.SERVER, jaasContexts, | ||
| securityProtocol, listenerName, false, saslMechanism, true, | ||
| credentialCache, null, time, new LogContext()) { | ||
|
|
||
| @Override | ||
| protected SaslServerAuthenticator buildServerAuthenticator(Map<String, ?> configs, | ||
| Map<String, AuthenticateCallbackHandler> callbackHandlers, | ||
| String id, | ||
| TransportLayer transportLayer, | ||
| Map<String, Subject> subjects, | ||
| Map<String, Long> connectionsMaxReauthMsByMechanism, | ||
| ChannelMetadataRegistry metadataRegistry) { | ||
| return new SaslServerAuthenticator(configs, callbackHandlers, id, subjects, null, listenerName, | ||
| securityProtocol, transportLayer, connectionsMaxReauthMsByMechanism, metadataRegistry, time) { | ||
|
|
||
| @Override | ||
| protected ApiVersionsResponse apiVersionsResponse() { | ||
| ApiVersionsResponseKeyCollection versionCollection = new ApiVersionsResponseKeyCollection(2); | ||
| versionCollection.add(new ApiVersionsResponseKey().setApiKey(ApiKeys.SASL_HANDSHAKE.id).setMinVersion((short) 0).setMaxVersion((short) 100)); | ||
| versionCollection.add(new ApiVersionsResponseKey().setApiKey(ApiKeys.SASL_AUTHENTICATE.id).setMinVersion((short) 0).setMaxVersion((short) 100)); | ||
| return new ApiVersionsResponse(new ApiVersionsResponseData().setApiKeys(versionCollection)); | ||
| } | ||
| }; | ||
| } | ||
| }; | ||
| serverChannelBuilder.configure(saslServerConfigs); | ||
| server = new NioEchoServer(listenerName, securityProtocol, new TestSecurityConfig(saslServerConfigs), | ||
| "localhost", serverChannelBuilder, credentialCache, time); | ||
| server.start(); | ||
| return server; | ||
| } | ||
|
|
||
| private NioEchoServer startServerWithoutSaslAuthenticateHeader(final SecurityProtocol securityProtocol, String saslMechanism) | ||
| throws Exception { | ||
| final ListenerName listenerName = ListenerName.forSecurityProtocol(securityProtocol); | ||
|
|
@@ -1821,7 +1891,7 @@ protected SaslHandshakeRequest createSaslHandshakeRequest(short version) { | |
| return buildSaslHandshakeRequest(saslMechanism, (short) 0); | ||
| } | ||
| @Override | ||
| protected void saslAuthenticateVersion(ApiVersionsResponse apiVersionsResponse) { | ||
| protected void setSaslAuthenticateAndHandshakeVersions(ApiVersionsResponse apiVersionsResponse) { | ||
| // Don't set version so that headers are disabled | ||
| } | ||
| }; | ||
|
|
||
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.
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.
Rollback version with comment