kmsv2: fixed issue with an invalid authority header being sent by the KMSv2 service

This commit is contained in:
Marcus Ruddick 2024-08-26 14:43:02 -10:00 committed by grant
parent 9682c62148
commit 618ca85bc9
2 changed files with 12 additions and 1 deletions

View File

@ -58,6 +58,7 @@ func NewGRPCService(ctx context.Context, endpoint, providerName string, callTime
s := &gRPCService{callTimeout: callTimeout}
s.connection, err = grpc.Dial(
addr,
grpc.WithAuthority("localhost"),
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithDefaultCallOptions(grpc.WaitForReady(true)),
grpc.WithContextDialer(

View File

@ -31,6 +31,7 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"
"k8s.io/apimachinery/pkg/util/wait"
@ -61,7 +62,16 @@ type Base64Plugin struct {
// NewBase64Plugin is a constructor for Base64Plugin.
func NewBase64Plugin(t testing.TB, socketPath string) *Base64Plugin {
server := grpc.NewServer()
server := grpc.NewServer(
grpc.UnaryInterceptor(
func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
if val := metadata.ValueFromIncomingContext(ctx, ":authority"); len(val) != 1 || val[0] != "localhost" {
t.Errorf("wanted localhost authority, got: %v", val)
}
return handler(ctx, req)
},
),
)
result := &Base64Plugin{
grpcServer: server,
mu: &sync.Mutex{},