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

fix: don't log certain fields #5662

Merged
merged 3 commits into from
Mar 3, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions util/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ func Run(cmd *exec.Cmd) (string, error) {
}

func RunWithRedactor(cmd *exec.Cmd, redactor func(text string) string) (string, error) {
opts := argoexec.CmdOpts{Timeout: timeout}
span := tracing.NewLoggingTracer(log.NewLogrusLogger(logrus.New())).StartSpan(fmt.Sprintf("exec %v", cmd.Args[0]))
span.SetBaggageItem("dir", fmt.Sprintf("%v", cmd.Dir))
span.SetBaggageItem("args", fmt.Sprintf("%v", cmd.Args))
defer span.Finish()
opts := argoexec.CmdOpts{Timeout: timeout}
if redactor != nil {
span.SetBaggageItem("args", redactor(fmt.Sprintf("%v", cmd.Args)))
opts.Redactor = redactor
} else {
span.SetBaggageItem("args", fmt.Sprintf("%v", cmd.Args))
}
defer span.Finish()
return argoexec.RunCommandExt(cmd, opts)
}
12 changes: 12 additions & 0 deletions util/exec/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package exec
import (
"os"
"os/exec"
"regexp"
"testing"
"time"

Expand All @@ -27,3 +28,14 @@ func TestRun(t *testing.T) {
assert.NoError(t, err)
assert.NotEmpty(t, out)
}

func TestHideUsernamePassword(t *testing.T) {
_, err := RunWithRedactor(exec.Command("helm registry login https://charts.bitnami.com/bitnami", "--username", "foo", "--password", "bar"), nil)
assert.NotEmpty(t, err)

var redactor = func(text string) string {
return regexp.MustCompile("(--username|--password) [^ ]*").ReplaceAllString(text, "$1 ******")
}
_, err = RunWithRedactor(exec.Command("helm registry login https://charts.bitnami.com/bitnami", "--username", "foo", "--password", "bar"), redactor)
assert.NotEmpty(t, err)
}