Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-4.9] Bug 2009849: Avoid logging BMC password when creds change #183

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 25 additions & 2 deletions pkg/provisioner/ironic/update_opts.go
Expand Up @@ -3,6 +3,7 @@ package ironic
import (
"fmt"
"reflect"
"strings"

"github.com/go-logr/logr"

Expand Down Expand Up @@ -72,6 +73,27 @@ func deref(v interface{}) interface{} {
return ptrVal.Elem().Interface()
}

func sanitisedValue(data interface{}) interface{} {
dataType := reflect.TypeOf(data)
if dataType.Kind() != reflect.Map ||
dataType.Key().Kind() != reflect.String {
return data
}

stleerh marked this conversation as resolved.
Show resolved Hide resolved
value := reflect.ValueOf(data)
safeValue := reflect.MakeMap(dataType)

for _, k := range value.MapKeys() {
safeDatumValue := value.MapIndex(k)
if strings.Contains(k.String(), "password") {
safeDatumValue = reflect.ValueOf("<redacted>")
}
safeValue.SetMapIndex(k, safeDatumValue)
}

return safeValue.Interface()
}

func getUpdateOperation(name string, currentData map[string]interface{}, desiredValue interface{}, path string, log logr.Logger) *nodes.UpdateOperation {
current, present := currentData[name]

Expand All @@ -81,10 +103,11 @@ func getUpdateOperation(name string, currentData map[string]interface{}, desired
if log != nil {
if present {
log.Info("updating option data",
"value", desiredValue, "old_value", current)
"value", sanitisedValue(desiredValue),
"old_value", current)
} else {
log.Info("adding option data",
"value", desiredValue)
"value", sanitisedValue(desiredValue))
}
}
return &nodes.UpdateOperation{
Expand Down
28 changes: 28 additions & 0 deletions pkg/provisioner/ironic/updateopts_test.go
Expand Up @@ -1229,3 +1229,31 @@ func TestGetUpdateOptsForNodeSecureBoot(t *testing.T) {
})
}
}

func TestSanitisedValue(t *testing.T) {
unchanged := []interface{}{
"foo",
42,
true,
[]string{"bar", "baz"},
map[string]string{"foo": "bar"},
map[string][]string{"foo": {"bar", "baz"}},
map[string]interface{}{"foo": []string{"bar", "baz"}, "bar": 42},
}

for _, u := range unchanged {
assert.Exactly(t, u, sanitisedValue(u))
}

unsafe := map[string]interface{}{
"foo": "bar",
"password": "secret",
"ipmi_password": "secret",
}
safe := map[string]interface{}{
"foo": "bar",
"password": "<redacted>",
"ipmi_password": "<redacted>",
}
assert.Exactly(t, safe, sanitisedValue(unsafe))
}