Skip to content

Commit a618653

Browse files
committed
Clear secrets from request for klog print in logGRPC()
Malicious user can put a secret in request as explained here: #1372.
1 parent b105d5a commit a618653

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

pkg/gce-pd-csi-driver/utils.go

+12
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"errors"
2222
"fmt"
23+
"reflect"
2324

2425
csi "github.com/container-storage-interface/spec/lib/go/csi"
2526
"google.golang.org/grpc"
@@ -63,6 +64,17 @@ func logGRPC(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, h
6364
// Note that secrets are not included in any RPC message. In the past protosanitizer and other log
6465
// stripping was shown to cause a significant increase of CPU usage (see
6566
// https://github.com/kubernetes-sigs/gcp-compute-persistent-disk-csi-driver/issues/356#issuecomment-550529004).
67+
// However malicious user still can put a secret in request as explained here:
68+
// https://github.com/kubernetes-sigs/gcp-compute-persistent-disk-csi-driver/issues/1372
69+
// Reflect magic below simply clears Secrets map from request.
70+
v := reflect.ValueOf(&req).Elem()
71+
e := reflect.New(v.Elem().Type()).Elem()
72+
e.Set(v.Elem())
73+
f := reflect.Indirect(e).FieldByName("Secrets")
74+
if f.IsValid() && f.CanSet() && f.Kind() == reflect.Map {
75+
f.Set(reflect.MakeMap(f.Type()))
76+
v.Set(e)
77+
}
6678
klog.V(4).Infof("%s called with request: %s", info.FullMethod, req)
6779
resp, err := handler(ctx, req)
6880
if err != nil {

0 commit comments

Comments
 (0)