Skip to content

Commit

Permalink
fix: return underlying sasl error message
Browse files Browse the repository at this point in the history
The SASL Authentication response message from Kafka has an additional
field which can contain a description of why the authentication failed.
Currently we drop this in Sarama and just return a generic message based
on the kError code.
  • Loading branch information
dnwe committed Feb 25, 2022
1 parent 0ad6651 commit f7a62e9
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -1167,7 +1167,7 @@ func (b *Broker) sendAndReceiveSASLHandshake(saslType SASLMechanism, version int
return res.Err
}

DebugLogger.Print("Successful SASL handshake. Available mechanisms: ", res.EnabledMechanisms)
DebugLogger.Print("Completed pre-auth SASL handshake. Available mechanisms: ", res.EnabledMechanisms)
return nil
}

Expand Down Expand Up @@ -1268,7 +1268,9 @@ func (b *Broker) sendAndReceiveV1SASLPlainAuth() error {

// With v1 sasl we get an error message set in the response we can return
if err != nil {
Logger.Printf("Error returned from broker during SASL flow %s: %s\n", b.addr, err.Error())
Logger.Printf(
"Error returned from broker %s during SASL authentication: %v\n",
b.addr, err.Error())
return err
}

Expand Down Expand Up @@ -1579,7 +1581,11 @@ func (b *Broker) receiveSASLServerResponse(res *SaslAuthenticateResponse, correl
}

if !errors.Is(res.Err, ErrNoError) {
return bytesRead, res.Err
var err error = res.Err
if res.ErrorMessage != nil {
err = Wrap(res.Err, errors.New(*res.ErrorMessage))
}
return bytesRead, err
}

return bytesRead, nil
Expand Down

0 comments on commit f7a62e9

Please sign in to comment.