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

Fix nullpointer that occurs when OAuthKafkaPrincipalBuilder is used with Kerberos listener #207

Conversation

akaczano
Copy link
Contributor

@akaczano akaczano commented Oct 17, 2023

As described in #208,

The principal builder extends the DefaultKafkaPrincipalBuilder but it just passes nulls to the two objects, SslPrincipalMapper and KerberosShortNamer in the super class constructor. For the first object, some reflection is used to initialize it anyway, but this is not done for the KerberosShortNamer. The result is that, if this principal builder is used on a broker that has a listener configured for Kerberos authentication, a null pointer exception is thrown here whenever a client tries to authenticate. Since my goal is to add an Oauth listener in-place to an existing Kafka cluster and then begin migrating clients from Kerberos to Oauth, this is a huge problem. As far as I know, there is no way to configure a principal builder for a single listener.

This PR just uses the existing reflection mechanisms to instantiate the KerberosShortNamer in addition to the SslPrincipalMapper, by recreating what Kafka does here and here.

@mstruk
Copy link
Contributor

mstruk commented Oct 17, 2023

The scenario when using OAuth and Kerberos authentication in the same cluster was indeed not accounted for. The use-case of needing this co-existence in order to be able to slowly migrate away from LDAP is legitimate, yet this is the first time I've heard of it :)

I don't see a problem adding this support as long as the existing testsuite tests keep passing.
We don't intend to ever use Kerberos authentication in Strimzi Operator project.

@akaczano akaczano force-pushed the fix-bug-with-principal-builder-on-kerberos-listener branch from 7224705 to 6043de0 Compare October 18, 2023 12:10
@akaczano
Copy link
Contributor Author

@mstruk Thanks for your quick response and willingness to support our use case. As far as I can see, all the test suites are passing. Let me know if there is anything else you need me to do. Any idea when we can expect to see a strimzi-kafka-oauth release with these changes included?

@mstruk
Copy link
Contributor

mstruk commented Oct 23, 2023

@akaczano I suggest you add a test to the testsuite, otherwise it's very likely some future work may inadvertently break your fix.
You could add a test to testsuite/mock-oauth-tests. There is a docker-compose.yml file where you'll need to add an additional listener in Kafka configuration that is configured with Kerberos authentication, and add some LDAP server container to start up in addition to 'mockauth', 'kafka', and 'zookeeper' containers. Your test should then try to produce some messages to that listener.

@mstruk mstruk added this to the 0.15.0 milestone Nov 2, 2023
@mstruk mstruk self-requested a review November 2, 2023 11:23
@akaczano akaczano force-pushed the fix-bug-with-principal-builder-on-kerberos-listener branch 3 times, most recently from 8b53ac1 to cf72476 Compare November 7, 2023 20:02
Copy link
Contributor

@mstruk mstruk left a comment

Choose a reason for hiding this comment

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

Nice work @akaczano . Maybe remove some of the commented lines that are there for debugging purposes, other than that this looks good to me, unless you still plan to add something.

@akaczano
Copy link
Contributor Author

akaczano commented Nov 8, 2023

Thanks for the review @mstruk. I just cleaned up the test file like you mentioned. I do not plan to add anything further.

Copy link
Member

@scholzj scholzj left a comment

Choose a reason for hiding this comment

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

Some nits. But LGTM overall.

@@ -20,6 +20,7 @@ Then, you have to add some entries to your `/etc/hosts` file:
127.0.0.1 hydra-jwt
127.0.0.1 kafka
127.0.0.1 mockoauth
127.0.0.1 kerberos
Copy link
Member

Choose a reason for hiding this comment

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

Should this have the same alignment as the lines above? I guess technically, it does not matter, but would be more readable.

@@ -0,0 +1,10 @@
FROM ubuntu:22.04
Copy link
Member

Choose a reason for hiding this comment

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

@mstruk Are you fine with this being based on Ubuntu? Strimzi IMHO does not use Ubuntu images anywhere else. So I would feel better if this used Red Hat UBI images as all our other projects. But I can live with this if you are fine with it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Now that you pointed this out, if I remember correctly, we had some Travis build issues with Ubuntu images on some architectures.

@akaczano Could you try use:
FROM registry.access.redhat.com/ubi8/ubi

or

FROM registry.access.redhat.com/ubi8/openjdk-17

You may need to install some additional packages.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure; I'll give that a try.

Copy link
Contributor

Choose a reason for hiding this comment

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

I took a look at this and it looks very challenging to set it up on ubi8. Tried a few leads with no luck. The needed package krb5-server doesn't seem to be available in the repo or is behind some kind of subscription wall. The setup is apparently very complicated as it is, and putting it together with any alternative would be just as complicated if not more. I suggest we keep it as is, and exclude the test run on architectures that will cause problems due to unavailability of platform specific container images.

@scholzj
Copy link
Member

scholzj commented Nov 8, 2023

@mstruk Why does it not run the Travis tests? We should not merge it without that.

@mstruk
Copy link
Contributor

mstruk commented Nov 8, 2023

@mstruk Why does it not run the Travis tests? We should not merge it without that.

That's a good question.

@mstruk mstruk self-requested a review November 15, 2023 14:08
Copy link
Contributor

@mstruk mstruk left a comment

Choose a reason for hiding this comment

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

Travis CI has issues with ubuntu docker images. Travis CI is failing but for some reason that's not visible under Checks.

akaczano and others added 8 commits January 26, 2024 12:02
Signed-off-by: Aidan Kaczanowski <[email protected]>
Signed-off-by: Aidan Kaczanowski <[email protected]>
Signed-off-by: Aidan Kaczanowski <[email protected]>
In order to exclude running the testsuite with kerberos tests (also not starting the `kerberos` container) set the env variable `OAUTH_TESTSUITE_TEST_KERBEROS=false`

Signed-off-by: Marko Strukelj <[email protected]>
@mstruk mstruk force-pushed the fix-bug-with-principal-builder-on-kerberos-listener branch from 12d663a to fe0930a Compare January 28, 2024 14:44
@mstruk mstruk merged commit 65679d4 into strimzi:main Jan 28, 2024
5 checks passed
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.

3 participants