Skip to content

Commit 4eb6516

Browse files
committed
Sanitize request for klog print in logGRPC()
Malicious user can put a secret in request as explained here: kubernetes-sigs#1372.
1 parent b105d5a commit 4eb6516

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Diff for: pkg/gce-pd-csi-driver/utils.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"fmt"
2323

2424
csi "github.com/container-storage-interface/spec/lib/go/csi"
25+
"github.com/kubernetes-csi/csi-lib-utils/protosanitizer"
2526
"google.golang.org/grpc"
2627
"k8s.io/klog/v2"
2728
)
@@ -63,7 +64,12 @@ 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).
66-
klog.V(4).Infof("%s called with request: %s", info.FullMethod, req)
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+
if klog.V(4).Enabled() {
70+
sanitizedReq := protosanitizer.StripSecrets(req)
71+
klog.Infof("%s called with request: %s", info.FullMethod, sanitizedReq)
72+
}
6773
resp, err := handler(ctx, req)
6874
if err != nil {
6975
klog.Errorf("%s returned with error: %v", info.FullMethod, err.Error())

0 commit comments

Comments
 (0)