Merge pull request #7462 from hashicorp/fix_log_secret_filter

make sure we filter the ui as well as the logs
This commit is contained in:
Adrien Delorme 2019-04-04 15:15:30 +02:00 committed by GitHub
commit baa43fe78b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View File

@ -626,6 +626,9 @@ func TestSensitiveVars(t *testing.T) {
if filtered[0] != tc.Expected && len(filtered) != 1 {
t.Fatalf("not filtering sensitive vars; filtered is %#v", filtered)
}
// clear filter so it doesn't break other tests
LogSecretFilter.s = make(map[string]struct{})
}
}

View File

@ -247,6 +247,13 @@ func (rw *BasicUi) Message(message string) {
rw.l.Lock()
defer rw.l.Unlock()
// Use LogSecretFilter to scrub out sensitive variables
for s := range LogSecretFilter.s {
if s != "" {
message = strings.Replace(message, s, "<sensitive>", -1)
}
}
log.Printf("ui: %s", message)
_, err := fmt.Fprint(rw.Writer, message+"\n")
if err != nil {
@ -263,6 +270,13 @@ func (rw *BasicUi) Error(message string) {
writer = rw.Writer
}
// Use LogSecretFilter to scrub out sensitive variables
for s := range LogSecretFilter.s {
if s != "" {
message = strings.Replace(message, s, "<sensitive>", -1)
}
}
log.Printf("ui error: %s", message)
_, err := fmt.Fprint(writer, message+"\n")
if err != nil {