-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
65431: changefeedccl: Add query parameter for specifying certificates for schema registries r=spiffyyeng a=spiffyyeng changefeedccl: Add query parameter for specifying certificates for schema registries Added query params to schema registry URL to indicate custom CA certificates to trust while dialing Confluent schema registries. Resolves #64622 Release note (enterprise change): Added ca_cert as a query param to Confluent registry schema URL to trust custom certs on connection. Co-authored-by: Ryan Min <ryanmin42@gmail.com>
- Loading branch information
Showing
11 changed files
with
410 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// Copyright 2021 The Cockroach Authors. | ||
// | ||
// Licensed as a CockroachDB Enterprise file under the Cockroach Community | ||
// License (the "License"); you may not use this file except in compliance with | ||
// the License. You may obtain a copy of the License at | ||
// | ||
// https://github.com/cockroachdb/cockroach/blob/master/licenses/CCL.txt | ||
|
||
package cdctest | ||
|
||
import ( | ||
"crypto/rand" | ||
"crypto/rsa" | ||
"crypto/x509" | ||
"crypto/x509/pkix" | ||
"encoding/base64" | ||
"encoding/pem" | ||
"math/big" | ||
"net" | ||
"strings" | ||
"time" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/util/timeutil" | ||
"github.com/cockroachdb/errors" | ||
) | ||
|
||
const certLifetime = 30 * 24 * time.Hour | ||
|
||
// EncodeBase64ToString stores the base64 encoding of src in dest | ||
func EncodeBase64ToString(src []byte, dest *string) { | ||
if src != nil { | ||
encoded := base64.StdEncoding.EncodeToString(src) | ||
*dest = encoded | ||
} | ||
} | ||
|
||
// GenerateCACert generates a new self-signed CA cert using priv | ||
func GenerateCACert(priv *rsa.PrivateKey) ([]byte, *x509.Certificate, error) { | ||
serial, err := randomSerial() | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
certSpec := &x509.Certificate{ | ||
SerialNumber: serial, | ||
Subject: pkix.Name{ | ||
Country: []string{"US"}, | ||
Organization: []string{"Cockroach Labs"}, | ||
OrganizationalUnit: []string{"Engineering"}, | ||
CommonName: "Roachtest Temporary Insecure CA", | ||
}, | ||
NotBefore: timeutil.Now(), | ||
NotAfter: timeutil.Now().Add(certLifetime), | ||
KeyUsage: x509.KeyUsageCertSign | x509.KeyUsageCRLSign, | ||
IsCA: true, | ||
BasicConstraintsValid: true, | ||
MaxPathLenZero: true, | ||
IPAddresses: []net.IP{net.ParseIP("127.0.0.1"), net.ParseIP("::1")}, | ||
} | ||
cert, err := x509.CreateCertificate(rand.Reader, certSpec, certSpec, &priv.PublicKey, priv) | ||
return cert, certSpec, err | ||
} | ||
|
||
func pemEncode(dataType string, data []byte) (string, error) { | ||
ret := new(strings.Builder) | ||
err := pem.Encode(ret, &pem.Block{Type: dataType, Bytes: data}) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return ret.String(), nil | ||
} | ||
|
||
// PemEncodePrivateKey encodes key in PEM format | ||
func PemEncodePrivateKey(key *rsa.PrivateKey) (string, error) { | ||
return pemEncode("RSA PRIVATE KEY", x509.MarshalPKCS1PrivateKey(key)) | ||
} | ||
|
||
// PemEncodeCert encodes cert in PEM format | ||
func PemEncodeCert(cert []byte) (string, error) { | ||
return pemEncode("CERTIFICATE", cert) | ||
} | ||
|
||
func randomSerial() (*big.Int, error) { | ||
limit := new(big.Int).Lsh(big.NewInt(1), 128) | ||
ret, err := rand.Int(rand.Reader, limit) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "generate random serial") | ||
} | ||
return ret, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.