-
Notifications
You must be signed in to change notification settings - Fork 70
logging for auth errors in kafka client binding #1664
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,6 +67,7 @@ public abstract class KafkaClientSaslHandshaker | |
| private static final int ERROR_NONE = 0; | ||
| private static final int ERROR_CLUSTER_AUTHORIZATION_FAILED = 31; | ||
| private static final int ERROR_UNSUPPORTED_VERSION = 35; | ||
| private static final int ERROR_TOPIC_AUTHORIZATION_FAILED = 29; | ||
|
|
||
| private static final String CLIENT_KEY = "Client Key"; | ||
| private static final String SERVER_KEY = "Server Key"; | ||
|
|
@@ -434,11 +435,24 @@ protected final void onDecodeResponseErrorCode( | |
| int apiKey, | ||
| int apiVersion, | ||
| int errorCode) | ||
| { | ||
| onDecodeResponseErrorCode(traceId, bindingId, apiKey, apiVersion, errorCode, null); | ||
| } | ||
|
|
||
| protected final void onDecodeResponseErrorCode( | ||
| long traceId, | ||
| long bindingId, | ||
| int apiKey, | ||
| int apiVersion, | ||
| int errorCode, | ||
| String topic) | ||
|
Comment on lines
+447
to
+448
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of adding the extra parameter on the existing method and changing all the call sites to pass |
||
| { | ||
| switch (errorCode) | ||
| { | ||
| case ERROR_CLUSTER_AUTHORIZATION_FAILED -> event.clusterAuthorizationFailed(traceId, bindingId, apiKey, apiVersion); | ||
| case ERROR_UNSUPPORTED_VERSION -> event.apiVersionRejected(traceId, bindingId, apiKey, apiVersion); | ||
| case ERROR_TOPIC_AUTHORIZATION_FAILED -> event.topicAuthorizationFailed(traceId, bindingId, apiKey, | ||
| apiVersion, topic); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -710,7 +724,8 @@ private int decodeSaslPlainAuthenticate( | |
| final int errorCode = authenticateResponse.errorCode(); | ||
| if (errorCode != ERROR_NONE) | ||
| { | ||
| event.authorizationFailed(traceId, client.originId, client.sasl.username); | ||
| event.saslAuthenticationFailed(traceId, client.originId, client.sasl.username, | ||
| authenticateResponse.errorMessage().asString()); | ||
| } | ||
|
|
||
| progress = authenticateResponse.limit(); | ||
|
|
@@ -748,7 +763,8 @@ private int decodeSaslScramAuthenticateFirst( | |
| final int errorCode = authenticateResponse.errorCode(); | ||
| if (errorCode != ERROR_NONE) | ||
| { | ||
| event.authorizationFailed(traceId, client.originId, client.sasl.username); | ||
| event.saslAuthenticationFailed(traceId, client.originId, client.sasl.username, | ||
| authenticateResponse.errorMessage().asString()); | ||
| } | ||
|
|
||
| progress = authenticateResponse.limit(); | ||
|
|
@@ -777,6 +793,7 @@ private int decodeSaslScramAuthenticateFirst( | |
| } | ||
| else | ||
| { | ||
| event.saslAuthenticationFailed(traceId, client.originId, client.sasl.username); | ||
| client.onDecodeSaslResponse(traceId); | ||
| client.onDecodeSaslAuthenticateResponse(traceId, authorization, ERROR_SASL_AUTHENTICATION_FAILED); | ||
| } | ||
|
|
@@ -826,6 +843,7 @@ private int decodeSaslScramAuthenticateFinal( | |
| if (!Arrays.equals(Base64.getDecoder().decode(serverFinalMessage), | ||
| serverSignature)) | ||
| { | ||
| event.saslAuthenticationFailed(traceId, client.originId, client.sasl.username); | ||
| client.onDecodeSaslResponse(traceId); | ||
| client.onDecodeSaslAuthenticateResponse(traceId, authorization, ERROR_SASL_AUTHENTICATION_FAILED); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| # | ||
| # Copyright 2021-2024 Aklivity Inc. | ||
| # | ||
| # Aklivity licenses this file to you under the Apache License, | ||
| # version 2.0 (the "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at: | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
| # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
| # License for the specific language governing permissions and limitations | ||
| # under the License. | ||
| # | ||
|
|
||
| --- | ||
| name: test | ||
| telemetry: | ||
| exporters: | ||
| exporter0: | ||
| type: test | ||
| options: | ||
| events: | ||
| - qname: engine:events | ||
| id: engine.started | ||
| name: ENGINE_STARTED | ||
| message: Engine Started. | ||
| - qname: test:app0 | ||
| id: binding.kafka.sasl.authentication.failed | ||
| name: BINDING_KAFKA_SASL_AUTHENTICATION_FAILED | ||
| message: "SASL authentication failed for identity (username): Authentication failed." | ||
| - qname: engine:events | ||
| id: engine.stopped | ||
| name: ENGINE_STOPPED | ||
| message: Engine Stopped. | ||
| bindings: | ||
| app0: | ||
| type: kafka | ||
| kind: client | ||
| options: | ||
| servers: | ||
| - localhost:9092 | ||
| sasl: | ||
| mechanism: plain | ||
| username: username | ||
| password: password | ||
| routes: | ||
| - exit: net0 |
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.
If
erroris not required, then create an overload method same name but withouterrorparameter and call this passingnullforerror.