Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added SASL PLAIN Support & Updated Dockerfile #186

Merged
merged 2 commits into from
Dec 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
FROM golang:1.12.7-alpine3.10 AS builder
FROM golang:1.13.14-alpine3.11 AS builder
RUN mkdir -p /go/src/github.com/mailgun/kafka-pixy
COPY . /go/src/github.com/mailgun/kafka-pixy
WORKDIR /go/src/github.com/mailgun/kafka-pixy
RUN apk add build-base
RUN go mod download
RUN go build -v -o /go/bin/kafka-pixy

FROM alpine:3.10
FROM alpine:3.11
LABEL maintainer="Maxim Vladimirskiy <[email protected]>"
COPY --from=builder /go/bin/kafka-pixy /usr/bin/kafka-pixy
EXPOSE 19091 19092
Expand Down
32 changes: 32 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,24 @@ type Proxy struct {

// How long to wait for a transmit.
WriteTimeout time.Duration `yaml:"write_timeout"`

// SASL support for SASL PLAIN
SASL struct {
// Whether or not to use SASL authentication when connecting to the broker (defaults to false).
Enable bool `yaml:"enable"`

// Whether or not to send the Kafka SASL handshake first if enabled
// (defaults to true). You should only set this to false if you're using
// a non-Kafka SASL proxy.
Handshake bool `yaml:"handshake"`

// User is the authentication identity (authcid) to present for
// SASL/PLAIN
User string `yaml:"user"`

// Password for SASL/PLAIN authentication
Password string `yaml:"password"`
} `yaml:"sasl"`
} `yaml:"net"`

Producer struct {
Expand Down Expand Up @@ -350,6 +368,13 @@ func (p *Proxy) SaramaProducerCfg() *sarama.Config {
saramaCfg.Net.ReadTimeout = p.Net.ReadTimeout
saramaCfg.Net.WriteTimeout = p.Net.WriteTimeout

if p.Net.SASL.Enable {
saramaCfg.Net.SASL.Enable = p.Net.SASL.Enable
saramaCfg.Net.SASL.Handshake = p.Net.SASL.Handshake
saramaCfg.Net.SASL.User = p.Net.SASL.User
saramaCfg.Net.SASL.Password = p.Net.SASL.Password
}

saramaCfg.Producer.MaxMessageBytes = p.Producer.MaxMessageBytes
saramaCfg.Producer.Compression = sarama.CompressionCodec(p.Producer.Compression)
saramaCfg.Producer.Flush.Frequency = p.Producer.FlushFrequency
Expand Down Expand Up @@ -379,6 +404,13 @@ func (p *Proxy) SaramaClientCfg() *sarama.Config {
saramaCfg.Net.ReadTimeout = p.Net.ReadTimeout
saramaCfg.Net.WriteTimeout = p.Net.WriteTimeout

if p.Net.SASL.Enable {
saramaCfg.Net.SASL.Enable = p.Net.SASL.Enable
saramaCfg.Net.SASL.Handshake = p.Net.SASL.Handshake
saramaCfg.Net.SASL.User = p.Net.SASL.User
saramaCfg.Net.SASL.Password = p.Net.SASL.Password
}

if p.Kafka.TLSEnabled {
saramaCfg.Net.TLS.Enable = true
tlsCfg, _ := p.newTLSConfig() // Ok to ignore err since we validated
Expand Down