From 43e8f5d33d2982c82d2471485f4f9513958723c7 Mon Sep 17 00:00:00 2001 From: chandresh-pancholi Date: Thu, 19 Dec 2019 02:46:11 +0530 Subject: [PATCH 1/2] Configure Jager Collector to work with Kafka With Basic Authentication #1966 Signed-off-by: chandresh-pancholi --- pkg/kafka/auth/config.go | 14 +++++++++++--- pkg/kafka/auth/options.go | 19 +++++++++++++++++++ pkg/kafka/auth/plaintext.go | 31 +++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 pkg/kafka/auth/plaintext.go diff --git a/pkg/kafka/auth/config.go b/pkg/kafka/auth/config.go index 130155b1384..fbc5c7d7062 100644 --- a/pkg/kafka/auth/config.go +++ b/pkg/kafka/auth/config.go @@ -23,9 +23,10 @@ import ( ) const ( - none = "none" - kerberos = "kerberos" - tls = "tls" + none = "none" + kerberos = "kerberos" + tls = "tls" + plaintext = "plaintext" ) var authTypes = []string{ @@ -39,6 +40,7 @@ type AuthenticationConfig struct { Authentication string Kerberos KerberosConfig TLS TLSConfig + PlainText PlainTextConfig } //SetConfiguration set configure authentication into sarama config structure @@ -55,6 +57,9 @@ func (config *AuthenticationConfig) SetConfiguration(saramaConfig *sarama.Config return nil case tls: return setTLSConfiguration(&config.TLS, saramaConfig) + case plaintext: + setPlainTextConfiguration(&config.PlainText, saramaConfig) + return nil default: return errors.Errorf("Unknown/Unsupported authentication method %s to kafka cluster.", config.Authentication) } @@ -74,4 +79,7 @@ func (config *AuthenticationConfig) InitFromViper(configPrefix string, v *viper. config.TLS.CaPath = v.GetString(configPrefix + tlsPrefix + suffixTLSCA) config.TLS.CertPath = v.GetString(configPrefix + tlsPrefix + suffixTLSCert) config.TLS.KeyPath = v.GetString(configPrefix + tlsPrefix + suffixTLSKey) + + config.PlainText.UserName = v.GetString(configPrefix + plainTextPrefix + suffixPlainTextUserName) + config.PlainText.Password = v.GetString(configPrefix + plainTextPrefix + suffixPlainTextPassword) } diff --git a/pkg/kafka/auth/options.go b/pkg/kafka/auth/options.go index 43a2e98b9b5..cc77a3f0464 100644 --- a/pkg/kafka/auth/options.go +++ b/pkg/kafka/auth/options.go @@ -50,6 +50,13 @@ const ( defaultCAPath = "" defaultCertPath = "" defaultKeyPath = "" + + plainTextPrefix = ".plaintext" + suffixPlainTextUserName = ".username" + suffixPlainTextPassword = ".password" + + defaultPlainTextUserName = "" + defaultPlainTextPassword = "" ) func addKerberosFlags(configPrefix string, flagSet *flag.FlagSet) { @@ -99,6 +106,17 @@ func addTLSFlags(configPrefix string, flagSet *flag.FlagSet) { "Path to the TLS Key for the Kafka connection") } +func addPlainTextFlag(configPrefix string, flagSet *flag.FlagSet) { + flagSet.String( + configPrefix+plainTextPrefix+suffixPlainTextUserName, + defaultPlainTextUserName, + "The plaintext Username for SASL/PLAIN authentication") + flagSet.String( + configPrefix+plainTextPrefix+suffixPlainTextPassword, + defaultPlainTextPassword, + "The plaintext Password for SASL/PLAIN authentication") +} + // AddFlags add configuration flags to a flagSet. func AddFlags(configPrefix string, flagSet *flag.FlagSet) { flagSet.String( @@ -108,4 +126,5 @@ func AddFlags(configPrefix string, flagSet *flag.FlagSet) { ) addKerberosFlags(configPrefix, flagSet) addTLSFlags(configPrefix, flagSet) + addPlainTextFlag(configPrefix, flagSet) } diff --git a/pkg/kafka/auth/plaintext.go b/pkg/kafka/auth/plaintext.go new file mode 100644 index 00000000000..a72641bcff6 --- /dev/null +++ b/pkg/kafka/auth/plaintext.go @@ -0,0 +1,31 @@ +// Copyright (c) 2019 The Jaeger Authors. +// +// Licensed 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. + +package auth + +import ( + "github.com/Shopify/sarama" +) + +// PlainTextConfig describes the configuration properties needed for SASL/PLAIN with kafka +type PlainTextConfig struct { + UserName string + Password string +} + +func setPlainTextConfiguration(config *PlainTextConfig, saramaConfig *sarama.Config) { + saramaConfig.Net.SASL.Enable = true + saramaConfig.Net.SASL.User = config.UserName + saramaConfig.Net.SASL.Password = config.Password +} From 65312923093aa10aa74c1c85a3b17f10ab2dcd3b Mon Sep 17 00:00:00 2001 From: chandresh-pancholi Date: Mon, 23 Dec 2019 13:52:04 +0530 Subject: [PATCH 2/2] Changing method name from addPlainTextFlag to addPlainTextFlags #1966 Signed-off-by: chandresh-pancholi --- pkg/kafka/auth/options.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/kafka/auth/options.go b/pkg/kafka/auth/options.go index cc77a3f0464..40145ba3f92 100644 --- a/pkg/kafka/auth/options.go +++ b/pkg/kafka/auth/options.go @@ -106,7 +106,7 @@ func addTLSFlags(configPrefix string, flagSet *flag.FlagSet) { "Path to the TLS Key for the Kafka connection") } -func addPlainTextFlag(configPrefix string, flagSet *flag.FlagSet) { +func addPlainTextFlags(configPrefix string, flagSet *flag.FlagSet) { flagSet.String( configPrefix+plainTextPrefix+suffixPlainTextUserName, defaultPlainTextUserName, @@ -126,5 +126,5 @@ func AddFlags(configPrefix string, flagSet *flag.FlagSet) { ) addKerberosFlags(configPrefix, flagSet) addTLSFlags(configPrefix, flagSet) - addPlainTextFlag(configPrefix, flagSet) + addPlainTextFlags(configPrefix, flagSet) }