Skip to content

Commit

Permalink
csigrpc: only overwrite secret fields if already set
Browse files Browse the repository at this point in the history
The previous version was adding "secrets: *** strippped ***"
even when the "secrets" field was unset.
  • Loading branch information
pohly committed Nov 29, 2018
1 parent fd53240 commit 111cbba
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/csigrpc/csigrpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func TestStripSecrets(t *testing.T) {
{"hello world", `"hello world"`},
{true, "true"},
{false, "false"},
{&csi.CreateVolumeRequest{}, `{}`},
{createVolume, `{"capacity_range":{"required_bytes":1024},"name":"foo","secrets":"***stripped***","volume_capabilities":[{"AccessType":{"Mount":{"fs_type":"ext4"}}}]}`},

// There is currently no test case that can verify
Expand Down
5 changes: 4 additions & 1 deletion pkg/csigrpc/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ func strip(parsed interface{}, msg interface{}) {
for _, field := range fields {
ex, err := proto.GetExtension(field.Options, csi.E_CsiSecret)
if err == nil && ex != nil && *ex.(*bool) {
parsedFields[field.GetName()] = "***stripped***"
// Overwrite only if already set.
if _, ok := parsedFields[field.GetName()]; ok {
parsedFields[field.GetName()] = "***stripped***"
}
} else if field.GetType() == protobuf.FieldDescriptorProto_TYPE_MESSAGE {
// When we get here,
// the type name is something like ".csi.v1.CapacityRange" (leading dot!)
Expand Down

0 comments on commit 111cbba

Please sign in to comment.