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

Always wait for completion during SASL/GSSAPI authentication #1248

Merged
merged 4 commits into from
Oct 10, 2017

Conversation

dpkp
Copy link
Owner

@dpkp dpkp commented Oct 8, 2017

SASL/GSSAPI authentication may require several rounds of token exchange with the broker. We need to continue the process until the gssapi context is marked complete or until an exception is raised. Network I/O errors are caught and can be retried; otherwise all other exceptions, including GSSAPI errors, will be raised directly to the user.

Fixes #1189

@dpkp
Copy link
Owner Author

dpkp commented Oct 8, 2017

kafka/conn.py Outdated

# pass the received token back to gssapi, strip the first 4 bytes
# dpkp note: what are the first four bytes here?
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yea it seems like it's the size there:

Client flow:
If sasl.mechanism is not GSSAPI, send a Kafka handshake request packet with the mechanism name to the server. Otherwise go to Step 3.
Request Format: | Kafka RequestHeader | Kafka SaslHandshakeRequest |
Wait for response from the server. If the error code in the response is non-zero, indicating failure, report the error and fail authentication.
Perform SASL authentication with the configured client mechanism. SASL authentication packets do not contain a Kafka RequestHeader.
Client token Format: | Size (int32) | SASL client authentication token |
Server flow:
Wait for first authentication packet from client
If this packet is a not valid Kafka handshake request, go to Step 4 and process this packet as the first GSSAPI client token
If the client mechanism in the Kafka handshake request received in Step 2 is enabled in the broker, send a response with error code zero and start authentication using the specified mechanism. Otherwise, send an error response including the list of enabled mechanisms and fail authentication.
Response Format: | Kafka ResponseHeader | Kafka SaslHandshakeResponse |
Perform SASL authentication with the selected mechanism. If mechanism exchange was skipped, process the initial packet that was received from the client first. SASL authentication packets are expected without a Kafka RequestHeader until SASL authentication exchange completes. SASL server authentication packets are sent back without a Kafka response header.
Server token Format: | Size (int32) | SASL server authentication token |

Source https://cwiki.apache.org/confluence/display/KAFKA/KIP-43%3A+Kafka+SASL+enhancements

@@ -533,7 +533,9 @@ def _try_authenticate_gssapi(self, future):
# establishes a security context, or it needs further token exchange.
# The gssapi will be able to identify the needed next step.
# The connection is closed on failure.
response = self._sock.recv(2000)
header = self._sock.recv(4)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Socket can return less than 4 bytes

Copy link
Owner Author

Choose a reason for hiding this comment

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

yes, yes it can.

Copy link
Owner Author

Choose a reason for hiding this comment

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

I think it will be easier to address this issue in #1249

@dpkp dpkp merged commit 5c17cf0 into master Oct 10, 2017
@tvoinarovskyi tvoinarovskyi deleted the gssapi_authentication_complete branch October 10, 2017 18:35
88manpreet pushed a commit to Yelp/kafka-python that referenced this pull request Jul 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants