Skip to content

added gssapi support (Kerberos) for SASL #1152

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 6 commits into from
Jul 20, 2017
Merged

added gssapi support (Kerberos) for SASL #1152

merged 6 commits into from
Jul 20, 2017

Conversation

Harald-Berghoff
Copy link
Contributor

this is the first version, please have a look on it

kafka/conn.py Outdated
@@ -21,6 +21,7 @@
from kafka.protocol.metadata import MetadataRequest
from kafka.protocol.types import Int32
from kafka.version import __version__
from mechanize import _response
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, i have not willingly added this line

@Harald-Berghoff
Copy link
Contributor Author

Harald-Berghoff commented Jul 17, 2017

the tests fails for the unknown GSSError type, which comes with the gssapi module and is added with the line from gssapi import raw. any hint how to fix this now?

edit:
got it, and will change it now

Copy link
Owner

@dpkp dpkp left a comment

Choose a reason for hiding this comment

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

Looks good -- thanks for working on this! I added a few comments inline. I haven't got a kerberos setup easily available for direct testing, but if it works for you then I'm happy to merge so others can try it out.

kafka/conn.py Outdated
except ImportError:
#no gssapi available, will disable gssapi mechanism
disable_gssapi = True
class GSSError(Exception):
Copy link
Owner

Choose a reason for hiding this comment

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

let's drop this class back one indent level and not leave it undefined if the gssapi import succeeds

Copy link
Owner

Choose a reason for hiding this comment

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

looking at this again, I might do something like

try:
    from gssapi.raw.misc import GSSError
except ImportError:
    GSSError = None

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK

try:
self._sock.setblocking(True)
# Send output token
msg = output_token
Copy link
Owner

Choose a reason for hiding this comment

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

will this be bytes on python3 ? if not, should encode('utf-8')

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it is a binary token that is exchanged. I'll check the type for python3, but i think encoding will harm the authentication token.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

return type is bytes

#calculate the output token
try:
output_token = ctx_Context.step(received_token)
except GSSError as e:
Copy link
Owner

Choose a reason for hiding this comment

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

won't this raise a NameError unless GSSError has been imported directly?

Copy link
Owner

Choose a reason for hiding this comment

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

Alternately I'd be ok with except Exception as e here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To avoid the NameError i added the lines below in case of ImportError

class GSSError(Exception):
        pass

kafka/conn.py Outdated
@@ -167,9 +182,13 @@ class BrokerConnection(object):
'metric_group_prefix': '',
'sasl_mechanism': 'PLAIN',
'sasl_plain_username': None,
'sasl_plain_password': None
'sasl_plain_password': None,
'sasl_servicename_kafka':'kafka'
Copy link
Owner

Choose a reason for hiding this comment

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

is this the same as sasl.kerberos.service.name in the java client? If so, let's reuse that config name (but with underscores)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this is exactly the same as sasl.kerberos.service.name in the java client, i'll change the name accordingly

kafka/conn.py Outdated
disable_gssapi = False
try:
import gssapi
from gssapi import raw
Copy link
Owner

Choose a reason for hiding this comment

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

is raw used? I dont see it in the changes below

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not raw, but it solved the name resolution error of GSSError for me.

kafka/conn.py Outdated
@@ -54,6 +54,21 @@ class SSLWantReadError(Exception):
class SSLWantWriteError(Exception):
pass

# needed for SASL_GSSAPI authentication:
disable_gssapi = False
Copy link
Owner

Choose a reason for hiding this comment

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

mild preference for just setting gssapi = None on ImportError. See kafka/codec.py

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK for me, i'll change it

kafka/conn.py Outdated
}
SASL_MECHANISMS = ('PLAIN',)
if gssapi is None:
SASL_MECHANISMS = ('PLAIN')
Copy link
Owner

Choose a reason for hiding this comment

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

this needs a trailing comma for tuple-ization

kafka/conn.py Outdated
#class GSSError(Exception):
# pass

try:
Copy link
Owner

Choose a reason for hiding this comment

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

cool. you could also combine w/ the above import try. I think we can safely assume that either both imports work, or both will fail.

@Harald-Berghoff
Copy link
Contributor Author

I am a little lost on the issues with the travis ci test?

@dpkp
Copy link
Owner

dpkp commented Jul 20, 2017

Test failure looks unrelated -- we have sporadic fixture issues on travis that I haven't been able to figure out. For now I typically just restart the failed test if it appears related to a kafka broker not starting up properly. I'm sure these could be improved, but it's out of scope for this PR.

@dpkp dpkp merged commit 0c78f70 into dpkp:master Jul 20, 2017
@dpkp
Copy link
Owner

dpkp commented Jul 20, 2017

This is great! Thanks for the PR. I'm sure a lot of folks will appreciate the new feature.

88manpreet pushed a commit to Yelp/kafka-python that referenced this pull request Aug 25, 2017
88manpreet pushed a commit to Yelp/kafka-python that referenced this pull request Aug 25, 2017
88manpreet pushed a commit to Yelp/kafka-python that referenced this pull request Oct 6, 2017
88manpreet pushed a commit to Yelp/kafka-python that referenced this pull request Jul 16, 2018
@gtfd333
Copy link

gtfd333 commented Feb 28, 2019

Thank you

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.

4 participants