forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for SCRAM authentication for kafka metricbeat module,
fixes elastic#19648
- Loading branch information
Showing
6 changed files
with
63 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package kafka | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/Shopify/sarama" | ||
) | ||
|
||
type SaslConfig struct { | ||
SaslMechanism string `config:"mechanism"` | ||
//SaslUsername string `config:"username"` //maybe use ssl.username ssl.password instead in future? | ||
//SaslPassword string `config:"password"` | ||
} | ||
|
||
const ( | ||
saslTypePlaintext = sarama.SASLTypePlaintext | ||
saslTypeSCRAMSHA256 = sarama.SASLTypeSCRAMSHA256 | ||
saslTypeSCRAMSHA512 = sarama.SASLTypeSCRAMSHA512 | ||
) | ||
|
||
func (c *SaslConfig) ConfigureSarama(config *sarama.Config) error { | ||
switch strings.ToUpper(c.SaslMechanism) { // try not to force users to use all upper case | ||
case "": | ||
// SASL is not enabled | ||
return nil | ||
case saslTypePlaintext: | ||
config.Net.SASL.Mechanism = sarama.SASLMechanism(sarama.SASLTypePlaintext) | ||
case saslTypeSCRAMSHA256: | ||
config.Net.SASL.Handshake = true | ||
config.Net.SASL.Mechanism = sarama.SASLMechanism(sarama.SASLTypeSCRAMSHA256) | ||
config.Net.SASL.SCRAMClientGeneratorFunc = func() sarama.SCRAMClient { | ||
return &XDGSCRAMClient{HashGeneratorFcn: SHA256} | ||
} | ||
case saslTypeSCRAMSHA512: | ||
config.Net.SASL.Handshake = true | ||
config.Net.SASL.Mechanism = sarama.SASLMechanism(sarama.SASLTypeSCRAMSHA512) | ||
config.Net.SASL.SCRAMClientGeneratorFunc = func() sarama.SCRAMClient { | ||
return &XDGSCRAMClient{HashGeneratorFcn: SHA512} | ||
} | ||
default: | ||
return fmt.Errorf("not valid mechanism '%v', only supported with PLAIN|SCRAM-SHA-512|SCRAM-SHA-256", c.SaslMechanism) | ||
} | ||
|
||
return nil | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters