-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Add OAuth support for Kafka client in native mode #12732
Conversation
This is a first step toward full OAUTH support for the Kafka extension in native mode. These changes get the communication with Keycloak going and obtain a proper token. However, there's an issue with the Kafka client trying to connect to the broker with that token. I tracked it down to this issue Basically,
call return null in the native mode. I tried to add some classes to the jni configuration, but as with the above reporter that didn't help. Anyone experienced something like this before? Any pointers on where to look next would be helpful. Note that the PR in the current state is usable/mergeable, but it doesn't get us to the end. |
...kafka-client/deployment/src/main/java/io/quarkus/kafka/client/deployment/KafkaProcessor.java
Outdated
Show resolved
Hide resolved
...kafka-client/deployment/src/main/java/io/quarkus/kafka/client/deployment/KafkaProcessor.java
Show resolved
Hide resolved
About |
@dejanb Can |
@cescoffier If you have any pointers on what to try and how to more info please let me know. I can try to provide substitutions for some of these classes and see if that would help. |
@sberyozkin these are used by strimzi oauth client, so this PR is intended to provide a better support for that case. I'd need to give oidc a look, but I assume that the client would need first changed to use it. |
@dejanb I see, so in your PR it is only about getting a token by directly requesting it from Keycloak. So |
@sberyozkin Great. We can take a look of moving strimzi oauth to it later on. |
@dejanb Sorry, missed the notifications. I would go with simple substitutions adding traces to check where it fails. Unfortunately, this is going to be a lot of fails and retries cycles. |
@cescoffier no worries, I was on other stuff as well. I pretty much pin-pointed the problematic places already, I'll try to play with substitutions to come up with a fix. Hopefully, I'll have something to show this week. Thanks for all your help so far. |
Can you link the place you think it fails? |
So what I think is going on is that This subject later on should be available with the call to That's where it fails. Let me know if this helpful or do you need any more info from my side. |
It seems close to the SASL issue we had with kafka a few months ago. |
@cescoffier unfortunately SASL fix wasn't applicable here. I ended up substituting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice trick.
I've done a few suggestions around SubstitutionsUtils.
There is a potential memory leak if there is lots of call to doAs
breaking before the call to getSubject
- the map size could grow unexpectedly.
I guess it's fine here, as we won't have such a scenario.
|
||
import javax.security.auth.Subject; | ||
|
||
public class SubstitutionUtils { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about the name.
Maybe SubjectHolder
?
|
||
public class SubstitutionUtils { | ||
|
||
public static HashMap<AccessControlContext, Subject> subjects = new HashMap<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it be final
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this field be moved to the Subject
class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cescoffier The field has to be kept outside otherwise IIRC you get an error. The only fields allowed in substituted classes are aliases of existing fields.
I'm not an expert on this java security APIs, but a couple of things to bear in mind would be:
- Should be it be concurrent?
- Is there a chance entries could be stored and not removed? Maybe you need some kind of expiration of entries to avoid a leak?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, thanks for reminding me of this @galderz! I always forgot.
Handling expiration might be good as it would avoid the potential growth I mentioned in my review.
@cescoffier thanks, great suggestions. I'll incorporate them in next. |
@cescoffier @galderz Thanks for the feedback. I pushed some more changes. As Galder mentioned, the static field cannot be added to the target class. But I moved the In terms of actual map, I made it synchronized and converted to I can use full blown cache (with expiring entries) here but I'll need to add a dependency on Infinispan/Guava for that. Let me know if you want me to explore that route. |
@dejanb Rather than |
@galderz Makes sense. I pushed an implementation using Caffeine cache. I used some defaults for sizes and expiry times we use on other projects and it seems to me they should work well here as well. Let me know if you have any other suggestions. |
Re-running the CI before merging. |
@dejanb Sorry for the delay. It should be fine to merge it, but I re-run the CI to be sure. |
This errored again with
I've this these error before (a month or so ago) and they were fixed by @loicmathieu or @gsmet. I think a rebase will do and it will re-trigger a clean build. Do you want to take a look? @dejanb |
@cescoffier @machi1990 Done. Hopefully it'll do it. |
@dejanb It's IN! What a great way to start the year! |
@cescoffier awesome ... To many more in this year :) |
No description provided.