Skip to content
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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

sagnghos
Copy link

@sagnghos sagnghos commented Jan 7, 2025

Add support for creating gRPC client connection using mutual TLS (mTLS) for external spanner hosts

@sagnghos sagnghos requested review from a team as code owners January 7, 2025 18:05
@product-auto-label product-auto-label bot added the api: spanner Issues related to the Spanner API. label Jan 7, 2025
}
capool := x509.NewCertPool()
if !capool.AppendCertsFromPEM(ca) {
return nil, fmt.Errorf("failed to append the CA certificate to CA pool")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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) {
Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the Spanner API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants