Skip to content

Commit 663368c

Browse files
committed
protosanitizer: only overwrite secret fields if already set
The previous version was adding "secrets: *** strippped ***" even when the "secrets" field was unset.
1 parent af584b9 commit 663368c

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

protosanitizer/protosanitizer.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ func strip(parsed interface{}, msg interface{}) {
9595
for _, field := range fields {
9696
ex, err := proto.GetExtension(field.Options, csi.E_CsiSecret)
9797
if err == nil && ex != nil && *ex.(*bool) {
98-
parsedFields[field.GetName()] = "***stripped***"
98+
// Overwrite only if already set.
99+
if _, ok := parsedFields[field.GetName()]; ok {
100+
parsedFields[field.GetName()] = "***stripped***"
101+
}
99102
} else if field.GetType() == protobuf.FieldDescriptorProto_TYPE_MESSAGE {
100103
// When we get here,
101104
// the type name is something like ".csi.v1.CapacityRange" (leading dot!)

protosanitizer/protosanitizer_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ func TestStripSecrets(t *testing.T) {
7070
{"hello world", `"hello world"`},
7171
{true, "true"},
7272
{false, "false"},
73+
{&csi.CreateVolumeRequest{}, `{}`},
7374
// Test case from https://github.com/kubernetes-csi/csi-lib-utils/pull/1#pullrequestreview-180126394.
7475
{&csi.CreateVolumeRequest{
7576
Name: "test-volume",

0 commit comments

Comments
 (0)