Skip to content

Commit b8cca1b

Browse files
craig[bot]wenyihu6
andcommitted
Merge #119077
119077: roachtest/cdc: fix cdc/kafka-auth r=stevendanna a=wenyihu6 From [kafka 2.0](https://kafka.apache.org/20/documentation.html#security_confighostname) onwards, host name verification of servers is enabled by default. Previously, the self-signed test certificate we generated for kafka-auth only included “localhost” in the list of subject alternative names. However, kafka appears to make internal connections using the fully qualified domain name. As a result, some inter-broker communication has been failing with a hostname verification error for some time. But the failure wasn’t raised to the user until the sarama upgrade happened. This patch fixes the failure by adding the proper hostname of the kafka node to the certificate. We don’t believe this represents a meaningful customer-facing issue. The misconfiguration of the test kafka cluster would have surfaced even with older sarama versions if the test had involved more than just connecting to the kafka cluster. Fixes: #118525 Release note: none Co-authored-by: Wenyi Hu <[email protected]>
2 parents e39dafe + 7b70a3a commit b8cca1b

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

pkg/cmd/roachtest/tests/cdc.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1741,7 +1741,7 @@ func (t *testCerts) CACertBase64() string {
17411741
return base64.StdEncoding.EncodeToString([]byte(t.CACert))
17421742
}
17431743

1744-
func makeTestCerts(sinkNodeIP string) (*testCerts, error) {
1744+
func makeTestCerts(sinkNodeIP string, dnsNames ...string) (*testCerts, error) {
17451745
CAKey, err := rsa.GenerateKey(cryptorand.Reader, keyLength)
17461746
if err != nil {
17471747
return nil, errors.Wrap(err, "CA private key")
@@ -1757,7 +1757,7 @@ func makeTestCerts(sinkNodeIP string) (*testCerts, error) {
17571757
return nil, errors.Wrap(err, "CA cert gen")
17581758
}
17591759

1760-
SinkCert, err := generateSinkCert(sinkNodeIP, SinkKey, CACertSpec, CAKey)
1760+
SinkCert, err := generateSinkCert(sinkNodeIP, SinkKey, CACertSpec, CAKey, dnsNames...)
17611761
if err != nil {
17621762
return nil, errors.Wrap(err, "kafka cert gen")
17631763
}
@@ -1791,7 +1791,11 @@ func makeTestCerts(sinkNodeIP string) (*testCerts, error) {
17911791
}
17921792

17931793
func generateSinkCert(
1794-
sinkIP string, priv *rsa.PrivateKey, CACert *x509.Certificate, CAKey *rsa.PrivateKey,
1794+
sinkIP string,
1795+
priv *rsa.PrivateKey,
1796+
CACert *x509.Certificate,
1797+
CAKey *rsa.PrivateKey,
1798+
dnsNames ...string,
17951799
) ([]byte, error) {
17961800
ip := net.ParseIP(sinkIP)
17971801
if ip == nil {
@@ -1815,10 +1819,9 @@ func generateSinkCert(
18151819
NotAfter: timeutil.Now().Add(certLifetime),
18161820
KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDataEncipherment | x509.KeyUsageDigitalSignature | x509.KeyUsageKeyAgreement,
18171821
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth, x509.ExtKeyUsageClientAuth},
1818-
DNSNames: []string{"localhost"},
1822+
DNSNames: append([]string{"localhost"}, dnsNames...),
18191823
IPAddresses: []net.IP{ip},
18201824
}
1821-
18221825
return x509.CreateCertificate(cryptorand.Reader, certSpec, CACert, &priv.PublicKey, CAKey)
18231826
}
18241827

@@ -2390,7 +2393,13 @@ func (k kafkaManager) configureAuth(ctx context.Context) *testCerts {
23902393
}
23912394
kafkaIP := ips[0]
23922395

2393-
testCerts, err := makeTestCerts(kafkaIP)
2396+
details, err := k.c.RunWithDetailsSingleNode(ctx, k.t.L(), option.WithNodes(k.kafkaSinkNode), "hostname", "-f")
2397+
if err != nil {
2398+
k.t.Fatal(err)
2399+
}
2400+
hostname := strings.TrimSpace(details.Stdout)
2401+
k.t.L().Printf("hostname included in TLS certificates: %s", hostname)
2402+
testCerts, err := makeTestCerts(kafkaIP, hostname)
23942403
if err != nil {
23952404
k.t.Fatal(err)
23962405
}

0 commit comments

Comments
 (0)