Enable xDS credentials
This change should be relatively straightforward. It is a noop outside of the context of xDS (as demonstrated by the fact that the tests all pass), but it enables xDS-provided certificates (i.e. the ones that would be provided/specified in GRPC_XDS_BOOTSTRAP). See proposal [A29](https://github.com/grpc/proposal/blob/master/A29-xds-tls-security.md#go) for additional detail.
This commit is contained in:
parent
70c215f7e2
commit
0620352c14
17
grpcurl.go
17
grpcurl.go
|
|
@ -28,6 +28,7 @@ import (
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
"google.golang.org/grpc/credentials"
|
"google.golang.org/grpc/credentials"
|
||||||
"google.golang.org/grpc/credentials/insecure"
|
"google.golang.org/grpc/credentials/insecure"
|
||||||
|
xdsCredentials "google.golang.org/grpc/credentials/xds"
|
||||||
"google.golang.org/grpc/metadata"
|
"google.golang.org/grpc/metadata"
|
||||||
protov2 "google.golang.org/protobuf/proto"
|
protov2 "google.golang.org/protobuf/proto"
|
||||||
"google.golang.org/protobuf/types/descriptorpb"
|
"google.golang.org/protobuf/types/descriptorpb"
|
||||||
|
|
@ -629,7 +630,16 @@ func BlockingDial(ctx context.Context, network, address string, creds credential
|
||||||
TransportCredentials: creds,
|
TransportCredentials: creds,
|
||||||
writeResult: writeResult,
|
writeResult: writeResult,
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
creds = insecure.NewCredentials()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var err error
|
||||||
|
creds, err = xdsCredentials.NewClientCredentials(xdsCredentials.ClientOptions{FallbackCreds: creds})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
dialer := func(ctx context.Context, address string) (net.Conn, error) {
|
dialer := func(ctx context.Context, address string) (net.Conn, error) {
|
||||||
// NB: We *could* handle the TLS handshake ourselves, in the custom
|
// NB: We *could* handle the TLS handshake ourselves, in the custom
|
||||||
// dialer (instead of customizing both the dialer and the credentials).
|
// dialer (instead of customizing both the dialer and the credentials).
|
||||||
|
|
@ -655,13 +665,8 @@ func BlockingDial(ctx context.Context, network, address string, creds credential
|
||||||
opts = append([]grpc.DialOption{grpc.FailOnNonTempDialError(true)}, opts...)
|
opts = append([]grpc.DialOption{grpc.FailOnNonTempDialError(true)}, opts...)
|
||||||
// But we don't want caller to be able to override these two, so we put
|
// But we don't want caller to be able to override these two, so we put
|
||||||
// them *after* the explicitly provided options.
|
// them *after* the explicitly provided options.
|
||||||
opts = append(opts, grpc.WithBlock(), grpc.WithContextDialer(dialer))
|
opts = append(opts, grpc.WithBlock(), grpc.WithContextDialer(dialer), grpc.WithTransportCredentials(creds))
|
||||||
|
|
||||||
if creds == nil {
|
|
||||||
opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
|
||||||
} else {
|
|
||||||
opts = append(opts, grpc.WithTransportCredentials(creds))
|
|
||||||
}
|
|
||||||
conn, err := grpc.DialContext(ctx, address, opts...)
|
conn, err := grpc.DialContext(ctx, address, opts...)
|
||||||
var res interface{}
|
var res interface{}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue