@@ -102,7 +102,7 @@ func getLogLevel(method string) int32 {
102
102
func LogGRPC (ctx context.Context , req interface {}, info * grpc.UnaryServerInfo , handler grpc.UnaryHandler ) (interface {}, error ) {
103
103
level := klog .Level (getLogLevel (info .FullMethod ))
104
104
klog .V (level ).Infof ("GRPC call: %s" , info .FullMethod )
105
- klog .V (level ).Infof ("GRPC request: %s" , stripServiceAccountToken (protosanitizer .StripSecrets (req )))
105
+ klog .V (level ).Infof ("GRPC request: %s" , StripSensitiveValue (protosanitizer .StripSecrets (req ), "csi.storage.k8s.io/serviceAccount.tokens" ))
106
106
107
107
resp , err := handler (ctx , req )
108
108
if err != nil {
@@ -113,7 +113,25 @@ func LogGRPC(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, h
113
113
return resp , err
114
114
}
115
115
116
- func stripServiceAccountToken (req fmt.Stringer ) string {
116
+ type stripSensitiveValue struct {
117
+ // volume_context[key] is the value to be stripped.
118
+ key string
119
+ // req is the csi grpc request stripped by `protosanitizer.StripSecrets`
120
+ req fmt.Stringer
121
+ }
122
+
123
+ func StripSensitiveValue (req fmt.Stringer , key string ) fmt.Stringer {
124
+ return & stripSensitiveValue {
125
+ key : key ,
126
+ req : req ,
127
+ }
128
+ }
129
+
130
+ func (s * stripSensitiveValue ) String () string {
131
+ return stripSensitiveValueByKey (s .req , s .key )
132
+ }
133
+
134
+ func stripSensitiveValueByKey (req fmt.Stringer , key string ) string {
117
135
var parsed map [string ]interface {}
118
136
119
137
err := json .Unmarshal ([]byte (req .String ()), & parsed )
@@ -126,11 +144,11 @@ func stripServiceAccountToken(req fmt.Stringer) string {
126
144
return req .String ()
127
145
}
128
146
129
- if _ , ok := volumeContext ["csi.storage.k8s.io/serviceAccount.tokens" ]; ! ok {
147
+ if _ , ok := volumeContext [key ]; ! ok {
130
148
return req .String ()
131
149
}
132
150
133
- volumeContext ["csi.storage.k8s.io/serviceAccount.tokens" ] = "***stripped***"
151
+ volumeContext [key ] = "***stripped***"
134
152
135
153
b , err := json .Marshal (parsed )
136
154
if err != nil {
0 commit comments