Skip to content

Commit 618ca85

Browse files
committed
kmsv2: fixed issue with an invalid authority header being sent by the KMSv2 service
1 parent 9682c62 commit 618ca85

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

staging/src/k8s.io/apiserver/pkg/storage/value/encrypt/envelope/kmsv2/grpc_service.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ func NewGRPCService(ctx context.Context, endpoint, providerName string, callTime
5858
s := &gRPCService{callTimeout: callTimeout}
5959
s.connection, err = grpc.Dial(
6060
addr,
61+
grpc.WithAuthority("localhost"),
6162
grpc.WithTransportCredentials(insecure.NewCredentials()),
6263
grpc.WithDefaultCallOptions(grpc.WaitForReady(true)),
6364
grpc.WithContextDialer(

staging/src/k8s.io/apiserver/pkg/storage/value/encrypt/envelope/testing/v2/kms_plugin_mock.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131

3232
"google.golang.org/grpc"
3333
"google.golang.org/grpc/codes"
34+
"google.golang.org/grpc/metadata"
3435
"google.golang.org/grpc/status"
3536

3637
"k8s.io/apimachinery/pkg/util/wait"
@@ -61,7 +62,16 @@ type Base64Plugin struct {
6162

6263
// NewBase64Plugin is a constructor for Base64Plugin.
6364
func NewBase64Plugin(t testing.TB, socketPath string) *Base64Plugin {
64-
server := grpc.NewServer()
65+
server := grpc.NewServer(
66+
grpc.UnaryInterceptor(
67+
func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
68+
if val := metadata.ValueFromIncomingContext(ctx, ":authority"); len(val) != 1 || val[0] != "localhost" {
69+
t.Errorf("wanted localhost authority, got: %v", val)
70+
}
71+
return handler(ctx, req)
72+
},
73+
),
74+
)
6575
result := &Base64Plugin{
6676
grpcServer: server,
6777
mu: &sync.Mutex{},

0 commit comments

Comments
 (0)