From: Dan Fuhry Date: Wed, 19 Nov 2025 21:46:12 +0000 (-0500) Subject: [grpc/client] make serverId a string X-Git-Url: https://go.fuhry.dev/?a=commitdiff_plain;h=525a9b921854c687f453f3febd675242636c6ea6;p=runtime.git [grpc/client] make serverId a string Prevent gRPC clients from trying to load the server's identity by calling `mtls.NewRemoteServiceIdentity` (which only returns a stub identity) and changing the `NewGrpcClient` function signature to accept a string instead of an Identity. --- diff --git a/attestation/rpc_client/main.go b/attestation/rpc_client/main.go index d82dd98..d59e8bf 100644 --- a/attestation/rpc_client/main.go +++ b/attestation/rpc_client/main.go @@ -18,8 +18,7 @@ func main() { flag.Parse() clientId := mtls.DefaultIdentity() - serverId := mtls.NewServiceIdentity("attest") - client, err := grpc.NewGrpcClient(ctx, serverId, clientId) + client, err := grpc.NewGrpcClient(ctx, "attest", clientId) if err != nil { panic(err) } diff --git a/automation/bryston_ctl/client/main.go b/automation/bryston_ctl/client/main.go index 5695ac0..edf4345 100644 --- a/automation/bryston_ctl/client/main.go +++ b/automation/bryston_ctl/client/main.go @@ -24,8 +24,7 @@ func main() { logger := log.Default().WithPrefix("BrystonCtlClient") clientId := mtls.DefaultIdentity() - serverId := mtls.NewServiceIdentity("bryston_ctl") - client, err := grpc.NewGrpcClient(ctx, serverId, clientId) + client, err := grpc.NewGrpcClient(ctx, "bryston_ctl", clientId) if err != nil { logger.Panic(err) } diff --git a/cmd/echo_client/main.go b/cmd/echo_client/main.go index 76f7cf1..a2cb2b5 100644 --- a/cmd/echo_client/main.go +++ b/cmd/echo_client/main.go @@ -18,8 +18,7 @@ func main() { logger := log.Default().WithPrefix("EchoClient") clientId := mtls.DefaultIdentity() - serverId := mtls.NewServiceIdentity("echo") - client, err := grpc.NewGrpcClient(ctx, serverId, clientId) + client, err := grpc.NewGrpcClient(ctx, "echo", clientId) if err != nil { logger.Panic(err) } diff --git a/cmd/echo_server/main.go b/cmd/echo_server/main.go index d7c6347..f0acaad 100644 --- a/cmd/echo_server/main.go +++ b/cmd/echo_server/main.go @@ -14,6 +14,7 @@ import ( func main() { var err error + mtls.SetDefaultIdentity("echo") flag.Parse() diff --git a/cmd/grpc_health_probe/main.go b/cmd/grpc_health_probe/main.go index 648a0ab..244d9eb 100644 --- a/cmd/grpc_health_probe/main.go +++ b/cmd/grpc_health_probe/main.go @@ -70,7 +70,7 @@ func main() { var conn *grpc.ClientConn for { - client, err := grpc.NewGrpcClient(ctx, mtls.NewServiceIdentity(*serverId), mtls.DefaultIdentity(), opts...) + client, err := grpc.NewGrpcClient(ctx, *serverId, mtls.DefaultIdentity(), opts...) if err != nil { if *wait && time.Now().Before(deadline) { log.Default().Warningf("error connecting (%v) retrying in 1s", err) diff --git a/ephs/client.go b/ephs/client.go index 4f3c55b..1749b99 100644 --- a/ephs/client.go +++ b/ephs/client.go @@ -401,10 +401,9 @@ func (c *clientImpl) watch(origCtx context.Context, origPath string, stream ephs func (c *clientImpl) grpcClient() (ephs_pb.EphsClient, error) { var err error - serverId := mtls.NewRemoteServiceIdentity("ephs") if c.client == nil { - c.client, err = grpc.NewGrpcClient(c.defaultCtx, serverId, c.id, + c.client, err = grpc.NewGrpcClient(c.defaultCtx, "ephs", c.id, grpc.WithConnectionFactory(&grpc_common.QUICConnectionFactory{ QUICConfig: ephsQuicConfig.Clone(), })) diff --git a/grpc/internal/client/client.go b/grpc/internal/client/client.go index b981af5..5551948 100644 --- a/grpc/internal/client/client.go +++ b/grpc/internal/client/client.go @@ -91,10 +91,10 @@ func WithDNSSRV() ClientOption { }) } -func NewGrpcClient(ctx context.Context, serverId, clientId mtls.Identity, opts ...ClientOption) (Client, error) { +func NewGrpcClient(ctx context.Context, serverId string, clientId mtls.Identity, opts ...ClientOption) (Client, error) { cl := &client{ ctx: ctx, - serverId: serverId, + serverId: mtls.NewRemoteServiceIdentity(serverId), clientId: clientId, connFac: common.NewDefaultConnectionFactory(), } @@ -112,7 +112,7 @@ func NewGrpcClient(ctx context.Context, serverId, clientId mtls.Identity, opts . } cl.watcher = &sd.SDWatcher{ - Service: serverId.Name(), + Service: cl.serverId.Name(), EtcdClient: etcdc, Protocol: sd.ProtocolGRPC, }