Skip to content

Commit 360c38b

Browse files
chlundeobjectiser
authored andcommittedJun 19, 2020
Avoid logging clear text passwords in kafka producer
Signed-off-by: Carl Henrik Lunde <[email protected]> Signed-off-by: Gary Brown <[email protected]>
1 parent 3bedc5a commit 360c38b

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed
 

‎pkg/kafka/auth/kerberos.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type KerberosConfig struct {
2424
Realm string `mapstructure:"realm"`
2525
UseKeyTab bool `mapstructure:"use_keytab"`
2626
Username string `mapstructure:"username"`
27-
Password string `mapstructure:"password"`
27+
Password string `mapstructure:"password" json:"-"`
2828
ConfigPath string `mapstructure:"config_file"`
2929
KeyTabPath string `mapstructure:"keytab_file"`
3030
}

‎pkg/kafka/auth/plaintext.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
// PlainTextConfig describes the configuration properties needed for SASL/PLAIN with kafka
2222
type PlainTextConfig struct {
2323
UserName string `mapstructure:"username"`
24-
Password string `mapstructure:"password"`
24+
Password string `mapstructure:"password" json:"-"`
2525
}
2626

2727
func setPlainTextConfiguration(config *PlainTextConfig, saramaConfig *sarama.Config) {

‎plugin/storage/kafka/factory_test.go

+54
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package kafka
1616

1717
import (
18+
"bytes"
1819
"errors"
1920
"testing"
2021

@@ -24,6 +25,7 @@ import (
2425
"github.com/stretchr/testify/require"
2526
"github.com/uber/jaeger-lib/metrics"
2627
"go.uber.org/zap"
28+
"go.uber.org/zap/zapcore"
2729

2830
"github.com/jaegertracing/jaeger/pkg/config"
2931
kafkaConfig "github.com/jaegertracing/jaeger/pkg/kafka/producer"
@@ -105,6 +107,58 @@ func TestKafkaFactoryMarshallerErr(t *testing.T) {
105107
assert.Error(t, f.Initialize(metrics.NullFactory, zap.NewNop()))
106108
}
107109

110+
func TestKafkaFactoryDoesNotLogPassword(t *testing.T) {
111+
tests := []struct {
112+
name string
113+
flags []string
114+
}{
115+
{
116+
name: "plaintext",
117+
flags: []string{
118+
"--kafka.producer.authentication=plaintext",
119+
"--kafka.producer.plaintext.username=username",
120+
"--kafka.producer.plaintext.password=SECRET",
121+
"--kafka.producer.brokers=localhost:9092",
122+
},
123+
},
124+
{
125+
name: "kerberos",
126+
flags: []string{
127+
"--kafka.producer.authentication=kerberos",
128+
"--kafka.producer.kerberos.username=username",
129+
"--kafka.producer.kerberos.password=SECRET",
130+
"--kafka.producer.brokers=localhost:9092",
131+
},
132+
},
133+
}
134+
135+
for _, test := range tests {
136+
t.Run(test.name, func(t *testing.T) {
137+
138+
f := NewFactory()
139+
v, command := config.Viperize(f.AddFlags)
140+
err := command.ParseFlags(test.flags)
141+
require.NoError(t, err)
142+
143+
f.InitFromViper(v)
144+
145+
parsedConfig := f.Builder.(*kafkaConfig.Configuration)
146+
f.Builder = &mockProducerBuilder{t: t, Configuration: *parsedConfig}
147+
logbuf := &bytes.Buffer{}
148+
logger := zap.New(zapcore.NewCore(
149+
zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig()),
150+
zapcore.AddSync(logbuf),
151+
zap.NewAtomicLevel(),
152+
))
153+
err = f.Initialize(metrics.NullFactory, logger)
154+
require.NoError(t, err)
155+
logger.Sync()
156+
157+
require.NotContains(t, logbuf.String(), "SECRET", "log output must not contain password in clear text")
158+
})
159+
}
160+
}
161+
108162
func TestInitFromOptions(t *testing.T) {
109163
f := NewFactory()
110164
o := Options{Topic: "testTopic", Config: kafkaConfig.Configuration{Brokers: []string{"host"}}}

0 commit comments

Comments
 (0)