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

Correct the SchemaRegistry authentication for SASL_INHERIT #733

Merged
merged 7 commits into from
Mar 17, 2020
6 changes: 4 additions & 2 deletions confluent_kafka/avro/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def __init__(self, config, default_key_schema=None,
for key, value in config.items() if key.startswith("schema.registry")}

if sr_conf.get("basic.auth.credentials.source") == 'SASL_INHERIT':
sr_conf['sasl.mechanisms'] = config.get('sasl.mechanisms', '')
# Fallback to plural 'mechanisms' for backward compatibility
sr_conf['sasl.mechanism'] = config.get('sasl.mechanism', config.get('sasl.mechanisms', ''))
sr_conf['sasl.username'] = config.get('sasl.username', '')
sr_conf['sasl.password'] = config.get('sasl.password', '')

Expand Down Expand Up @@ -110,7 +111,8 @@ def __init__(self, config, schema_registry=None, reader_key_schema=None, reader_
for key, value in config.items() if key.startswith("schema.registry")}

if sr_conf.get("basic.auth.credentials.source") == 'SASL_INHERIT':
sr_conf['sasl.mechanisms'] = config.get('sasl.mechanisms', '')
# Fallback to plural 'mechanisms' for backward compatibility
sr_conf['sasl.mechanism'] = config.get('sasl.mechanism', config.get('sasl.mechanisms', ''))
sr_conf['sasl.username'] = config.get('sasl.username', '')
sr_conf['sasl.password'] = config.get('sasl.password', '')

Expand Down
4 changes: 2 additions & 2 deletions confluent_kafka/avro/cached_schema_registry_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ def _configure_basic_auth(conf):
raise ValueError("schema.registry.basic.auth.credentials.source must be one of {}"
.format(VALID_AUTH_PROVIDERS))
if auth_provider == 'SASL_INHERIT':
if conf.pop('sasl.mechanism', '').upper() is ['GSSAPI']:
raise ValueError("SASL_INHERIT does not support SASL mechanisms GSSAPI")
if conf.pop('sasl.mechanism', '').upper() == 'GSSAPI':
Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch!

raise ValueError("SASL_INHERIT does not support SASL mechanism GSSAPI")
auth = (conf.pop('sasl.username', ''), conf.pop('sasl.password', ''))
elif auth_provider == 'USER_INFO':
auth = tuple(conf.pop('basic.auth.user.info', '').split(':'))
Expand Down
4 changes: 2 additions & 2 deletions examples/confluent_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

p = Producer({
'bootstrap.servers': '<ccloud bootstrap servers>',
'sasl.mechanisms': 'PLAIN',
'sasl.mechanism': 'PLAIN',
'security.protocol': 'SASL_SSL',
'sasl.username': '<ccloud key>',
'sasl.password': '<ccloud secret>'
Expand All @@ -78,7 +78,7 @@ def acked(err, msg):

c = Consumer({
'bootstrap.servers': '<ccloud bootstrap servers>',
'sasl.mechanisms': 'PLAIN',
'sasl.mechanism': 'PLAIN',
'security.protocol': 'SASL_SSL',
'sasl.username': '<ccloud key>',
'sasl.password': '<ccloud secret>',
Expand Down
9 changes: 9 additions & 0 deletions tests/avro/test_cached_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,15 @@ def test_basic_auth_sasl_inherit(self):
})
self.assertTupleEqual(('user_sasl', 'secret_sasl'), self.client._session.auth)

def test_basic_auth_sasl_inherit_invalid(self):
with self.assertRaises(ValueError) as e:
self.client = CachedSchemaRegistryClient({
'url': 'https://user_url:secret_url@127.0.0.1:65534',
'basic.auth.credentials.source': 'SASL_INHERIT',
'sasl.mechanism': 'gssapi' # also test the .upper()
})
self.assertEqual(str(e.exception), "SASL_INHERIT does not support SASL mechanism GSSAPI")

def test_basic_auth_invalid(self):
with self.assertRaises(ValueError):
self.client = CachedSchemaRegistryClient({
Expand Down