-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
feat(spanner): add mTLS support external spanner hosts #11381
base: main
Are you sure you want to change the base?
Conversation
} | ||
capool := x509.NewCertPool() | ||
if !capool.AppendCertsFromPEM(ca) { | ||
return nil, fmt.Errorf("failed to append the CA certificate to CA pool") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return nil, fmt.Errorf("failed to append the CA certificate to CA pool") | |
return nil, errors.New("failed to append the CA certificate to CA pool") |
// - The returned gRPC connection can be passed to `option.WithGRPCConn(grpcConn)` to create a client using mTLS. | ||
func NewMtlsConn(endpoint, caCertificate, clientCertificate, clientCertificateKey string) (*grpc.ClientConn, error) { | ||
if clientCertificate == "" || clientCertificateKey == "" { | ||
return nil, fmt.Errorf("client certificate and key are mandatory for mTLS connection") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return nil, fmt.Errorf("client certificate and key are mandatory for mTLS connection") | |
return nil, errors.New("client certificate and key are mandatory for mTLS connection") |
clientCerts := []tls.Certificate{cert} | ||
|
||
if caCertificate == "" { | ||
return nil, fmt.Errorf("ca certificate is required for mTLS connection") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return nil, fmt.Errorf("ca certificate is required for mTLS connection") | |
return nil, errors.New("ca certificate is required for mTLS connection") |
@@ -1399,6 +1402,67 @@ func (c *Client) BatchWriteWithOptions(ctx context.Context, mgs []*MutationGroup | |||
} | |||
} | |||
|
|||
// CertPool creates a x509.CertPool from the given CA certificate file. | |||
func CertPool(caCertFile string) (*x509.CertPool, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want it to be public?
Add support for creating gRPC client connection using mutual TLS (mTLS) for external spanner hosts