Skip to content

Commit 553c409

Browse files
committed
Require and verify client certificate if proxy-listener-ca-chain-cert-file is provided
1 parent 28d95ee commit 553c409

File tree

6 files changed

+657
-44
lines changed

6 files changed

+657
-44
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ See:
105105
--kafka-write-timeout duration How long to wait for a transmit (default 30s)
106106
--log-format string Log format text or json (default "text")
107107
--log-level string Log level debug, info, warning, error, fatal or panic (default "info")
108-
--proxy-listener-ca-chain-cert-file string PEM encoded CA's certificate file
108+
--proxy-listener-ca-chain-cert-file string PEM encoded CA's certificate file. If provided, client certificate is required and verified
109109
--proxy-listener-cert-file string PEM encoded file with server certificate
110110
--proxy-listener-keep-alive duration Keep alive period for an active network connection. If zero, keep-alives are disabled (default 1m0s)
111111
--proxy-listener-key-file string PEM encoded file with private key for the server certificate
@@ -316,7 +316,7 @@ spec:
316316
1. additional handshake - protocol: magic, method, data
317317
2. google-id method
318318
* [X] Registry for built-in plugins
319-
* [ ] Client cert check
319+
* [X] Client cert check
320320
* [ ] TLS server parameters like CipherSuites etc. - see ory/graceful/blob/master/http_defaults.go
321321
* [ ] Performance tests and tuning
322322
* [ ] Socket buffer sizing e.g. SO_RCVBUF = 32768, SO_SNDBUF = 131072

cmd/kafka-proxy/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func init() {
8181
Server.Flags().StringVar(&c.Proxy.TLS.ListenerCertFile, "proxy-listener-cert-file", "", "PEM encoded file with server certificate")
8282
Server.Flags().StringVar(&c.Proxy.TLS.ListenerKeyFile, "proxy-listener-key-file", "", "PEM encoded file with private key for the server certificate")
8383
Server.Flags().StringVar(&c.Proxy.TLS.ListenerKeyPassword, "proxy-listener-key-password", "", "Password to decrypt rsa private key")
84-
Server.Flags().StringVar(&c.Proxy.TLS.CAChainCertFile, "proxy-listener-ca-chain-cert-file", "", "PEM encoded CA's certificate file")
84+
Server.Flags().StringVar(&c.Proxy.TLS.CAChainCertFile, "proxy-listener-ca-chain-cert-file", "", "PEM encoded CA's certificate file. If provided, client certificate is required and verified")
8585

8686
// local authentication plugin
8787
Server.Flags().BoolVar(&c.Auth.Local.Enable, "auth-local-enable", false, "Enable local SASL/PLAIN authentication performed by listener - SASL handshake will not be passed to kafka brokers")

proxy/auth_test.go

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@ import (
77
"fmt"
88
"github.com/grepplabs/kafka-proxy/pkg/apis"
99
"github.com/stretchr/testify/assert"
10-
"net"
1110
"testing"
1211
"time"
1312
)
1413

1514
func TestAuthHandshake(t *testing.T) {
1615
a := assert.New(t)
1716

18-
magic, err := Uint64()
17+
magic, err := RandomUint64()
1918
a.Nil(err)
2019

2120
fmt.Println(magic)
@@ -83,45 +82,7 @@ func (p *testTokenInfo) VerifyToken(ctx context.Context, request apis.VerifyRequ
8382
return apis.VerifyResponse{Success: false}, p.err
8483
}
8584

86-
func makePipe() (c1, c2 net.Conn, stop func(), err error) {
87-
ln, err := net.Listen("tcp4", "127.0.0.1:0")
88-
if err != nil {
89-
return nil, nil, nil, err
90-
}
91-
92-
// Start a connection between two endpoints.
93-
var err1, err2 error
94-
done := make(chan bool)
95-
go func() {
96-
c2, err2 = ln.Accept()
97-
close(done)
98-
}()
99-
c1, err1 = net.Dial(ln.Addr().Network(), ln.Addr().String())
100-
<-done
101-
102-
stop = func() {
103-
if err1 == nil {
104-
c1.Close()
105-
}
106-
if err2 == nil {
107-
c2.Close()
108-
}
109-
ln.Close()
110-
}
111-
112-
switch {
113-
case err1 != nil:
114-
stop()
115-
return nil, nil, nil, err1
116-
case err2 != nil:
117-
stop()
118-
return nil, nil, nil, err2
119-
default:
120-
return c1, c2, stop, nil
121-
}
122-
}
123-
124-
func Uint64() (uint64, error) {
85+
func RandomUint64() (uint64, error) {
12586
var b [8]byte
12687

12788
_, err := rand.Read(b[:])

proxy/tls.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func newTLSListenerConfig(conf *config.Config) (*tls.Config, error) {
4545
return nil, errors.New("Failed to parse listener root certificate")
4646
}
4747
cfg.ClientCAs = clientCAs
48+
cfg.ClientAuth = tls.RequireAndVerifyClientCert
4849
}
4950
return cfg, nil
5051
}

0 commit comments

Comments
 (0)