Skip to content

Commit 9d9fa12

Browse files
TLS for grpc service (#104)
Signed-off-by: James-Milligan <[email protected]>
1 parent 91e66a8 commit 9d9fa12

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

pkg/service/grpc_service.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
log "github.com/sirupsen/logrus"
1212
"google.golang.org/grpc"
1313
"google.golang.org/grpc/codes"
14+
"google.golang.org/grpc/credentials"
1415
"google.golang.org/grpc/status"
1516
"google.golang.org/protobuf/types/known/structpb"
1617
)
@@ -32,8 +33,18 @@ type GRPCService struct {
3233
// GRPC and HTTP
3334
func (s *GRPCService) Serve(ctx context.Context, eval eval.IEvaluator) error {
3435
s.Eval = eval
35-
// TODO: Needs TLS implementation: https://github.com/open-feature/flagd/issues/103
36-
grpcServer := grpc.NewServer()
36+
37+
// TLS
38+
var serverOpts []grpc.ServerOption
39+
if s.GRPCServiceConfiguration.ServerCertPath != "" && s.GRPCServiceConfiguration.ServerKeyPath != "" {
40+
config, err := loadTLSConfig(s.GRPCServiceConfiguration.ServerCertPath, s.GRPCServiceConfiguration.ServerKeyPath)
41+
if err != nil {
42+
return err
43+
}
44+
serverOpts = append(serverOpts, grpc.Creds(credentials.NewTLS(config)))
45+
}
46+
47+
grpcServer := grpc.NewServer(serverOpts...)
3748
gen.RegisterServiceServer(grpcServer, s)
3849

3950
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", s.GRPCServiceConfiguration.Port))

0 commit comments

Comments
 (0)