Skip to content

Commit c1f6fbc

Browse files
committed
add basic sasl_ssl support:
* add security_protocol to authConfig. a single value, SASL_SSL, is supported for now. this allows one to enable TLS support * add sasl_mechanism to authConfig. currently we check for PLAIN.
1 parent e062ed5 commit c1f6fbc

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

common.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,15 @@ func randomString(length int) string {
164164
return fmt.Sprintf("%x", buf)[:length]
165165
}
166166

167+
func parseSaslMechanism(auth authConfig) (sarama.SASLMechanism, error) {
168+
switch strings.ToLower(auth.SASLMechanism) {
169+
case "plain", "":
170+
return sarama.SASLTypePlaintext, nil;
171+
default:
172+
return sarama.SASLTypePlaintext, fmt.Errorf("Unsupported auth sasl mechanism: %#v", auth.SASLMechanism)
173+
}
174+
}
175+
167176
// setupCerts takes the paths to a tls certificate, CA, and certificate key in
168177
// a PEM format and returns a constructed tls.Config object.
169178
func setupCerts(certPath, caPath, keyPath string) (*tls.Config, error) {
@@ -207,6 +216,8 @@ type authConfig struct {
207216
ClientCertKey string `json:"client-certificate-key"`
208217
SASLPlainUser string `json:"sasl_plain_user"`
209218
SASLPlainPassword string `json:"sasl_plain_password"`
219+
SASLMechanism string `json:"sasl_mechanism"`
220+
SecurityProtocol string `json:"security_protocol"`
210221
}
211222

212223
func setupAuth(auth authConfig, saramaCfg *sarama.Config) error {
@@ -230,6 +241,16 @@ func setupSASL(auth authConfig, saramaCfg *sarama.Config) error {
230241
saramaCfg.Net.SASL.Enable = true
231242
saramaCfg.Net.SASL.User = auth.SASLPlainUser
232243
saramaCfg.Net.SASL.Password = auth.SASLPlainPassword
244+
saslMechanism, err := parseSaslMechanism(auth)
245+
246+
if err != nil {
247+
return err;
248+
}
249+
saramaCfg.Net.SASL.Mechanism = saslMechanism;
250+
251+
if (strings.EqualFold(auth.SecurityProtocol, "SASL_SSL")) {
252+
saramaCfg.Net.TLS.Enable = true
253+
}
233254
return nil
234255
}
235256

0 commit comments

Comments
 (0)