Skip to content

Commit 356cabf

Browse files
authored
Merge pull request #404 from jpayvazian/master
Sanitize CSI request logs
2 parents 896b7e7 + 4bb8125 commit 356cabf

File tree

4 files changed

+68
-11
lines changed

4 files changed

+68
-11
lines changed

pkg/driver/controller.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func newControllerService(driverOptions *DriverOptions) controllerService {
110110
}
111111
}
112112
func (d *controllerService) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) (*csi.CreateVolumeResponse, error) {
113-
klog.V(4).InfoS("CreateVolume: called", "args", req)
113+
klog.V(4).InfoS("CreateVolume: called", "args", util.SanitizeRequest(req))
114114
volName := req.GetName()
115115
if len(volName) == 0 {
116116
return nil, status.Error(codes.InvalidArgument, "Volume name not provided")
@@ -274,7 +274,7 @@ func (d *controllerService) CreateVolume(ctx context.Context, req *csi.CreateVol
274274
}
275275

276276
func (d *controllerService) DeleteVolume(ctx context.Context, req *csi.DeleteVolumeRequest) (*csi.DeleteVolumeResponse, error) {
277-
klog.V(4).InfoS("DeleteVolume: called", "args", req)
277+
klog.V(4).InfoS("DeleteVolume: called", "args", util.SanitizeRequest(req))
278278
volumeID := req.GetVolumeId()
279279
if len(volumeID) == 0 {
280280
return nil, status.Error(codes.InvalidArgument, "Volume ID not provided")
@@ -310,7 +310,7 @@ func (d *controllerService) ControllerModifyVolume(ctx context.Context, req *csi
310310
}
311311

312312
func (d *controllerService) ControllerGetCapabilities(ctx context.Context, req *csi.ControllerGetCapabilitiesRequest) (*csi.ControllerGetCapabilitiesResponse, error) {
313-
klog.V(4).InfoS("ControllerGetCapabilities: called", "args", req)
313+
klog.V(4).InfoS("ControllerGetCapabilities: called", "args", util.SanitizeRequest(req))
314314
var caps []*csi.ControllerServiceCapability
315315
for _, cap := range controllerCaps {
316316
c := &csi.ControllerServiceCapability{
@@ -326,17 +326,17 @@ func (d *controllerService) ControllerGetCapabilities(ctx context.Context, req *
326326
}
327327

328328
func (d *controllerService) GetCapacity(ctx context.Context, req *csi.GetCapacityRequest) (*csi.GetCapacityResponse, error) {
329-
klog.V(4).InfoS("GetCapacity: called", "args", req)
329+
klog.V(4).InfoS("GetCapacity: called", "args", util.SanitizeRequest(req))
330330
return nil, status.Error(codes.Unimplemented, "")
331331
}
332332

333333
func (d *controllerService) ListVolumes(ctx context.Context, req *csi.ListVolumesRequest) (*csi.ListVolumesResponse, error) {
334-
klog.V(4).InfoS("ListVolumes: called", "args", req)
334+
klog.V(4).InfoS("ListVolumes: called", "args", util.SanitizeRequest(req))
335335
return nil, status.Error(codes.Unimplemented, "")
336336
}
337337

338338
func (d *controllerService) ValidateVolumeCapabilities(ctx context.Context, req *csi.ValidateVolumeCapabilitiesRequest) (*csi.ValidateVolumeCapabilitiesResponse, error) {
339-
klog.V(4).InfoS("ValidateVolumeCapabilities: called", "args", req)
339+
klog.V(4).InfoS("ValidateVolumeCapabilities: called", "args", util.SanitizeRequest(req))
340340
volumeID := req.GetVolumeId()
341341
if len(volumeID) == 0 {
342342
return nil, status.Error(codes.InvalidArgument, "Volume ID not provided")
@@ -403,7 +403,7 @@ func (d *controllerService) ListSnapshots(ctx context.Context, req *csi.ListSnap
403403
}
404404

405405
func (d *controllerService) ControllerExpandVolume(ctx context.Context, req *csi.ControllerExpandVolumeRequest) (*csi.ControllerExpandVolumeResponse, error) {
406-
klog.V(4).InfoS("ControllerExpandVolume: called", "args", req)
406+
klog.V(4).InfoS("ControllerExpandVolume: called", "args", util.SanitizeRequest(req))
407407
volumeID := req.GetVolumeId()
408408
if len(volumeID) == 0 {
409409
return nil, status.Error(codes.InvalidArgument, "Volume ID not provided")

pkg/driver/node.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"k8s.io/apimachinery/pkg/util/wait"
2727
"sigs.k8s.io/aws-fsx-csi-driver/pkg/cloud"
2828
"sigs.k8s.io/aws-fsx-csi-driver/pkg/driver/internal"
29+
"sigs.k8s.io/aws-fsx-csi-driver/pkg/util"
2930

3031
"github.com/container-storage-interface/spec/lib/go/csi"
3132
"google.golang.org/grpc/codes"
@@ -93,7 +94,7 @@ func (d *nodeService) NodeUnstageVolume(ctx context.Context, req *csi.NodeUnstag
9394
}
9495

9596
func (d *nodeService) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolumeRequest) (*csi.NodePublishVolumeResponse, error) {
96-
klog.V(4).InfoS("NodePublishVolume: called with", "args", req)
97+
klog.V(4).InfoS("NodePublishVolume: called with", "args", util.SanitizeRequest(req))
9798

9899
volumeID := req.GetVolumeId()
99100
if len(volumeID) == 0 {
@@ -181,7 +182,7 @@ func (d *nodeService) NodePublishVolume(ctx context.Context, req *csi.NodePublis
181182
}
182183

183184
func (d *nodeService) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpublishVolumeRequest) (*csi.NodeUnpublishVolumeResponse, error) {
184-
klog.V(4).InfoS("NodeUnpublishVolume: called", "args", req)
185+
klog.V(4).InfoS("NodeUnpublishVolume: called", "args", util.SanitizeRequest(req))
185186

186187
volumeID := req.GetVolumeId()
187188
if len(volumeID) == 0 {
@@ -226,7 +227,7 @@ func (d *nodeService) NodeExpandVolume(ctx context.Context, req *csi.NodeExpandV
226227
}
227228

228229
func (d *nodeService) NodeGetCapabilities(ctx context.Context, req *csi.NodeGetCapabilitiesRequest) (*csi.NodeGetCapabilitiesResponse, error) {
229-
klog.V(4).InfoS("NodeGetCapabilities: called", "args", req)
230+
klog.V(4).InfoS("NodeGetCapabilities: called", "args", util.SanitizeRequest(req))
230231
var caps []*csi.NodeServiceCapability
231232
for _, cap := range nodeCaps {
232233
c := &csi.NodeServiceCapability{
@@ -242,7 +243,7 @@ func (d *nodeService) NodeGetCapabilities(ctx context.Context, req *csi.NodeGetC
242243
}
243244

244245
func (d *nodeService) NodeGetInfo(ctx context.Context, req *csi.NodeGetInfoRequest) (*csi.NodeGetInfoResponse, error) {
245-
klog.V(4).InfoS("NodeGetInfo: called", "args", req)
246+
klog.V(4).InfoS("NodeGetInfo: called", "args", util.SanitizeRequest(req))
246247

247248
return &csi.NodeGetInfoResponse{
248249
NodeId: d.metadata.GetInstanceID(),

pkg/util/util.go

+18
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"os"
2424
"path"
2525
"path/filepath"
26+
"reflect"
2627
"strings"
2728

2829
"github.com/aws/aws-sdk-go-v2/service/fsx/types"
@@ -118,3 +119,20 @@ func GetURLHost(urlStr string) (string, error) {
118119

119120
return u.Host, nil
120121
}
122+
123+
// SanitizeRequest takes a request object and returns a copy of the request with
124+
// the "Secrets" field cleared.
125+
func SanitizeRequest(req interface{}) interface{} {
126+
v := reflect.ValueOf(&req).Elem()
127+
e := reflect.New(v.Elem().Type()).Elem()
128+
129+
e.Set(v.Elem())
130+
131+
f := reflect.Indirect(e).FieldByName("Secrets")
132+
133+
if f.IsValid() && f.CanSet() && f.Kind() == reflect.Map {
134+
f.Set(reflect.MakeMap(f.Type()))
135+
v.Set(e)
136+
}
137+
return req
138+
}

pkg/util/util_test.go

+38
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package util
1919
import (
2020
"fmt"
2121
"math"
22+
"reflect"
2223
"testing"
2324

2425
"github.com/aws/aws-sdk-go-v2/service/fsx/types"
@@ -320,3 +321,40 @@ func TestConvertToInt32(t *testing.T) {
320321
})
321322
}
322323
}
324+
325+
type TestRequest struct {
326+
Name string
327+
Secrets map[string]string
328+
}
329+
330+
func TestSanitizeRequest(t *testing.T) {
331+
tests := []struct {
332+
name string
333+
req interface{}
334+
expected interface{}
335+
}{
336+
{
337+
name: "Request with Secrets",
338+
req: &TestRequest{
339+
Name: "Test",
340+
Secrets: map[string]string{
341+
"key1": "value1",
342+
"key2": "value2",
343+
},
344+
},
345+
expected: &TestRequest{
346+
Name: "Test",
347+
Secrets: map[string]string{},
348+
},
349+
},
350+
}
351+
352+
for _, tt := range tests {
353+
t.Run(tt.name, func(t *testing.T) {
354+
result := SanitizeRequest(tt.req)
355+
if !reflect.DeepEqual(result, tt.expected) {
356+
t.Errorf("SanitizeRequest() = %v, expected %v", result, tt.expected)
357+
}
358+
})
359+
}
360+
}

0 commit comments

Comments
 (0)