-
Notifications
You must be signed in to change notification settings - Fork 103
Fix for "this.authorizerMetrics" is null issue in Kafka 4.1.0
#283
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
Conversation
mimaison
left a comment
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.
Thanks for the PR, I left a few comments.
How much effort would it take to stop using non-public Kafka APIs?
| private void initPluginMetricsIfNeeded() { | ||
| Class<?> monitorableClass = null; | ||
| try { | ||
| // Check if StandardAuthorizer implements Monitorable, which can only be true if running on Kafka 4.1.0+ |
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.
The comment is a bit misleading. This block checks if the Monitorable class is present, ie, we're running >=4.1
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.
Do you have a suggestion how to rephrase?
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.
What about // Check if Monitorable is present. This indicates if we're running on Kafka 4.1.0+?
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.
Fixed.
| pluginMetrics = method.invoke(null, delegate, metrics, "authorizer.class.name", "role", determineRole()); | ||
| } | ||
| } catch (Throwable e) { | ||
| log.warn("Failed to initialise PluginMetrics on StandardAuthorizer", e); |
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.
Isn't it fatal if we reach this point?
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.
Yes, it will fail later during StandardAuthorizer.authorize() calls with 'this.authorizerMetrics is null' rather than at bootup in KeycloakAuthorizer.configure(). It a choice here whether to fail fast at boot or later on. I can change it to fail fast.
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.
I don't know the project enough to advise where it's best to fail. In theory failing fast is often preferred but obviously it depends, I trust you to make the right call. But if it's fatal, maybe log it as fatal or error rather than warn?
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.
Modified so it fails fast.
Can you be more specific here? We wrap |
I don't know enough about this component to tell. We can discuss this after this is resolved. |
…horizer using reflection Signed-off-by: Marko Strukelj <[email protected]>
Signed-off-by: Marko Strukelj <[email protected]>
Signed-off-by: Marko Strukelj <[email protected]>
1bca209 to
f194b97
Compare
mimaison
left a comment
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.
LGTM
scholzj
left a comment
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.
Thanks @mstruk
…mzi#283) Signed-off-by: Marko Strukelj <[email protected]>
|
Until Strimzi |
This PR fixes the issue when using
KeycloakAuthorizerin Kafka 4.1.0 when delegation toStandardAuthorizeris enabled (strimzi.authorization.delegate.to.kafka.acl=true).Whenever the authorization decision is delegated to
StandardAuthorizerthe following exception happens:Kafka 4.1.0 added new metrics pluggability mechanism and updated
StandardAuthorizerto implementMonitorableinterface and expect aPluginMetricsobject to be provided by instantiating server viaMonitorable.withPluginMetrics(PluginMetrics pluginMetrics).For
KeycloakAuthorizerto be deployable to Kafka 4.0.0 whereMonitorableinterface is not present, and to also properly work on Kafka 4.1.0 whereMonitorable.withPluginMetrics()is expected to be called onStandardAuthorizerthe only way to address this without having multiple versions ofKeycloakAuthorizeris to use reflection.It is not possible for
KeycloakAuthorizerto implementMonitorableand still be compatible with Kafka 4.0.0, thus thePluginMetricsinstance that we set onStandardAuthorizerwhen running in Kafka 4.1.0 is not passed in and backed by theMetricsobject ofBrokerServerorControllerServerbut by a separate internally managedMetricsobject used by all the Strimzi OAuth pluggable classes.