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 75d7f54 commit 278aaff
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
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
1 change: 1 addition & 0 deletions pkg/csigrpc/secrets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func TestStripSecrets(t *testing.T) {
{"hello world", `"hello world"`},
{true, "true"},
{false, "false"},
{&csi.CreateVolumeRequest{}, `{}`},
{createVolume, `{"accessibility_requirements":{"requisite":[{"segments":{"foo":"bar","x":"y"}},{"segments":{"a":"b"}}]},"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

0 comments on commit 278aaff

Please sign in to comment.