Skip to content

Commit 111cbba

Browse files
committed
csigrpc: only overwrite secret fields if already set
The previous version was adding "secrets: *** strippped ***" even when the "secrets" field was unset.
1 parent fd53240 commit 111cbba

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

pkg/csigrpc/csigrpc_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ func TestStripSecrets(t *testing.T) {
5555
{"hello world", `"hello world"`},
5656
{true, "true"},
5757
{false, "false"},
58+
{&csi.CreateVolumeRequest{}, `{}`},
5859
{createVolume, `{"capacity_range":{"required_bytes":1024},"name":"foo","secrets":"***stripped***","volume_capabilities":[{"AccessType":{"Mount":{"fs_type":"ext4"}}}]}`},
5960

6061
// There is currently no test case that can verify

pkg/csigrpc/secrets.go

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

0 commit comments

Comments
 (0)