Skip to content

Commit 7b70a3a

Browse files
committed
roachtest/cdc: fix cdc/kafka-auth
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
1 parent b2e3187 commit 7b70a3a

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
@@ -1698,7 +1698,7 @@ func (t *testCerts) CACertBase64() string {
16981698
return base64.StdEncoding.EncodeToString([]byte(t.CACert))
16991699
}
17001700

1701-
func makeTestCerts(sinkNodeIP string) (*testCerts, error) {
1701+
func makeTestCerts(sinkNodeIP string, dnsNames ...string) (*testCerts, error) {
17021702
CAKey, err := rsa.GenerateKey(cryptorand.Reader, keyLength)
17031703
if err != nil {
17041704
return nil, errors.Wrap(err, "CA private key")
@@ -1714,7 +1714,7 @@ func makeTestCerts(sinkNodeIP string) (*testCerts, error) {
17141714
return nil, errors.Wrap(err, "CA cert gen")
17151715
}
17161716

1717-
SinkCert, err := generateSinkCert(sinkNodeIP, SinkKey, CACertSpec, CAKey)
1717+
SinkCert, err := generateSinkCert(sinkNodeIP, SinkKey, CACertSpec, CAKey, dnsNames...)
17181718
if err != nil {
17191719
return nil, errors.Wrap(err, "kafka cert gen")
17201720
}
@@ -1748,7 +1748,11 @@ func makeTestCerts(sinkNodeIP string) (*testCerts, error) {
17481748
}
17491749

17501750
func generateSinkCert(
1751-
sinkIP string, priv *rsa.PrivateKey, CACert *x509.Certificate, CAKey *rsa.PrivateKey,
1751+
sinkIP string,
1752+
priv *rsa.PrivateKey,
1753+
CACert *x509.Certificate,
1754+
CAKey *rsa.PrivateKey,
1755+
dnsNames ...string,
17521756
) ([]byte, error) {
17531757
ip := net.ParseIP(sinkIP)
17541758
if ip == nil {
@@ -1772,10 +1776,9 @@ func generateSinkCert(
17721776
NotAfter: timeutil.Now().Add(certLifetime),
17731777
KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDataEncipherment | x509.KeyUsageDigitalSignature | x509.KeyUsageKeyAgreement,
17741778
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth, x509.ExtKeyUsageClientAuth},
1775-
DNSNames: []string{"localhost"},
1779+
DNSNames: append([]string{"localhost"}, dnsNames...),
17761780
IPAddresses: []net.IP{ip},
17771781
}
1778-
17791782
return x509.CreateCertificate(cryptorand.Reader, certSpec, CACert, &priv.PublicKey, CAKey)
17801783
}
17811784

@@ -2347,7 +2350,13 @@ func (k kafkaManager) configureAuth(ctx context.Context) *testCerts {
23472350
}
23482351
kafkaIP := ips[0]
23492352

2350-
testCerts, err := makeTestCerts(kafkaIP)
2353+
details, err := k.c.RunWithDetailsSingleNode(ctx, k.t.L(), option.WithNodes(k.kafkaSinkNode), "hostname", "-f")
2354+
if err != nil {
2355+
k.t.Fatal(err)
2356+
}
2357+
hostname := strings.TrimSpace(details.Stdout)
2358+
k.t.L().Printf("hostname included in TLS certificates: %s", hostname)
2359+
testCerts, err := makeTestCerts(kafkaIP, hostname)
23512360
if err != nil {
23522361
k.t.Fatal(err)
23532362
}

0 commit comments

Comments
 (0)