Zanzana/enable TLS for client side gRPC (#103000)

* zanzana - add tls to the client

* remove todo

* gofmt

* adjust comment
This commit is contained in:
mohammad-hamid
2025-04-02 09:12:58 -04:00
committed by GitHub
parent 360c57b3d7
commit 192d3783d5
2 changed files with 14 additions and 3 deletions
+11 -3
View File
@@ -5,12 +5,14 @@ import (
"errors"
"fmt"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
"github.com/fullstorydev/grpchan/inprocgrpc"
grpcAuth "github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/auth"
openfgav1 "github.com/openfga/api/proto/openfga/v1"
"github.com/prometheus/client_golang/prometheus"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
healthv1pb "google.golang.org/grpc/health/grpc_health_v1"
authnlib "github.com/grafana/authlib/authn"
@@ -53,9 +55,15 @@ func ProvideZanzana(cfg *setting.Cfg, db db.DB, tracer tracing.Tracer, features
return nil, fmt.Errorf("missing stack ID")
}
transportCredentials := insecure.NewCredentials()
if cfg.ZanzanaClient.ServerCertFile != "" {
transportCredentials, err = credentials.NewClientTLSFromFile(cfg.ZanzanaClient.ServerCertFile, "")
if err != nil {
return nil, fmt.Errorf("failed to initialize TLS certificate: %w", err)
}
}
dialOptions := []grpc.DialOption{
// TODO: add TLS support
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithTransportCredentials(transportCredentials),
grpc.WithPerRPCCredentials(
NewGRPCTokenAuth(AuthzServiceAudience, fmt.Sprintf("stacks-%s", cfg.StackID), tokenClient),
),
+3
View File
@@ -18,6 +18,9 @@ type ZanzanaClientSettings struct {
// Addr is the address of the Zanzana server.
// Only used when mode is set to client.
Addr string
// Certificate used to authenticate the Server
// Only used when mode is set to client
ServerCertFile string
// Token used to perform the exchange request.
// Only used when mode is set to client.
Token string