Skip to content
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

KAFKA-18339: Remove raw unversioned direct SASL protocol (KIP-896) #18295

Merged
merged 4 commits into from
Dec 27, 2024

Conversation

ijuma
Copy link
Member

@ijuma ijuma commented Dec 22, 2024

Clients that support SASL but don't implement KIP-43 (eg Kafka producer/consumer 0.9.0.x) will
fail to connect after this change.

Added unit tests and also manually tested with the console producer 0.9.0.

While testing, I noticed that the logged message when a 0.9.0 Java client is used without sasl is
slightly misleading - fixed that too.

Committer Checklist (excluded from commit message)

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation (including upgrade notes)

@github-actions github-actions bot added triage PRs from the community clients small Small PRs core Kafka Broker and removed small Small PRs labels Dec 22, 2024
// Raise an error prior to parsing if the api cannot be handled at this layer. This avoids
// unnecessary exposure to some of the more complex schema types.
if (apiKey != ApiKeys.API_VERSIONS && apiKey != ApiKeys.SASL_HANDSHAKE)
throw new IllegalSaslStateException("Unexpected Kafka request of type " + apiKey + " during SASL handshake.");
throw new InvalidRequestException("Unexpected Kafka request of type " + apiKey + " during SASL handshake.");
Copy link
Member Author

@ijuma ijuma Dec 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rajinisivaram Do you know why we send IllegalSaslStateException here and InvalidRequestException for every other error? We seem to have special handling for Sasl related exceptions, but it doesn't seem to make sense in this case since we can't properly propagate an error if we get the wrong request type.

Copy link
Contributor

@omkreddy omkreddy Dec 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change looks good to me for this case.
looks like we defined IllegalSaslStateException to indicate unexpected Kafka requests/state prior to SASL authentication.
https://github.com/apache/kafka/pull/3928/files#diff-fe3c04719e4a85673b22592a8bc286b427b960efc357b7331d77f0fabbed994e

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RIght, I think this distinction was perhaps useful when we had the pre KIP-43 fallback, but not anymore.

// InvalidRequestException is thrown if the request is not in Kafka format or if the API key is invalid.
// If it's the initial request, this could be an ancient client (see method documentation for more details),
// a client configured with the wrong security protocol or a non kafka-client altogether (eg http client).
throw new InvalidRequestException("Invalid request, potential reasons: kafka client configured with the " +
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please take a look at the error message and check if it makes sense. This will only be captured in the broker, but still good to try and make it as informative as possible.

@ijuma ijuma force-pushed the kafka-18339-remove-raw-unversioned-sasl branch from 061cbb0 to 12d120c Compare December 24, 2024 02:19
@ijuma
Copy link
Member Author

ijuma commented Dec 24, 2024

@rajinisivaram @omkreddy Any of you has cycles to review this small change?

@github-actions github-actions bot removed the triage PRs from the community label Dec 25, 2024
Copy link
Contributor

@omkreddy omkreddy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ijuma Thanks for the PR. LGTM

@ijuma ijuma force-pushed the kafka-18339-remove-raw-unversioned-sasl branch from 12d120c to b381c07 Compare December 27, 2024 15:49
@ijuma
Copy link
Member Author

ijuma commented Dec 27, 2024

@rajinisivaram I'll go ahead and merge this so client developers can test their clients with all KIP-896 changes. Please take a look when you have a chance and I'm happy to submit a follow up to address any feedback.

@ijuma ijuma merged commit 875da35 into apache:trunk Dec 27, 2024
9 checks passed
@ijuma ijuma deleted the kafka-18339-remove-raw-unversioned-sasl branch December 27, 2024 18:23
ijuma added a commit that referenced this pull request Dec 27, 2024
…18295)

Clients that support SASL but don't implement KIP-43 (eg Kafka producer/consumer 0.9.0.x) will
fail to connect after this change.

Added unit tests and also manually tested with the console producer 0.9.0.

While testing, I noticed that the logged message when a 0.9.0 Java client is used without sasl is
slightly misleading - fixed that too.

Reviewers: Manikumar Reddy <[email protected]>
Copy link
Member

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ijuma sorry for late reviews. two minor comments PTAL

throw new InvalidRequestException(s"Received request api key ${header.apiKey} with version ${header.apiVersion} which is not enabled")
} else {
throw new UnsupportedVersionException(s"Received request api key ${header.apiKey} with version ${header.apiVersion} which is not supported")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pardon me, this changes the returned exception from INVALID_REQUEST to UNSUPPORTED_VERSION as isApiVersionDeprecated always returns false for now. Is it expected?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I added a commit at the end that changed this incorrectly:

b381c07

Thanks for catching that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Submitted the fix: #18340

@@ -1107,8 +1107,10 @@ private[kafka] class Processor(
val header = RequestHeader.parse(buffer)
if (apiVersionManager.isApiEnabled(header.apiKey, header.apiVersion)) {
header
} else {
} else if (header.isApiVersionDeprecated()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add the deprecated versions back to the JSON files? This would enable us to provide more informative error messages to clients, helping them understand why certain APIs are marked as "unsupported" (deprecated, removed, or disabled).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need that, see the response to your other comment. Does that make sense?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does that make sense?

yes, that makes sense :)

ijuma added a commit to ijuma/kafka that referenced this pull request Dec 28, 2024
A minor refactoring just before merging apache#18295 introduced a regression
and no test failed. Throw the correct exception and add test to verify
it. Also refactor the code slightly to make that possible.
ijuma added a commit that referenced this pull request Dec 29, 2024
A minor refactoring just before merging #18295 introduced a regression and no test failed. Throw the correct exception and add test to verify it. Also refactor the code slightly to make that possible.

Thanks to Chia-Ping for catching the issue.

Reviewers: Chia-Ping Tsai <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clients core Kafka Broker
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants