@@ -102,7 +102,7 @@ func getLogLevel(method string) int32 {
102102func LogGRPC (ctx context.Context , req interface {}, info * grpc.UnaryServerInfo , handler grpc.UnaryHandler ) (interface {}, error ) {
103103 level := klog .Level (getLogLevel (info .FullMethod ))
104104 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" ))
106106
107107 resp , err := handler (ctx , req )
108108 if err != nil {
@@ -113,7 +113,25 @@ func LogGRPC(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, h
113113 return resp , err
114114}
115115
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 {
117135 var parsed map [string ]interface {}
118136
119137 err := json .Unmarshal ([]byte (req .String ()), & parsed )
@@ -126,11 +144,11 @@ func stripServiceAccountToken(req fmt.Stringer) string {
126144 return req .String ()
127145 }
128146
129- if _ , ok := volumeContext ["csi.storage.k8s.io/serviceAccount.tokens" ]; ! ok {
147+ if _ , ok := volumeContext [key ]; ! ok {
130148 return req .String ()
131149 }
132150
133- volumeContext ["csi.storage.k8s.io/serviceAccount.tokens" ] = "***stripped***"
151+ volumeContext [key ] = "***stripped***"
134152
135153 b , err := json .Marshal (parsed )
136154 if err != nil {
0 commit comments