Skip to content

Commit

Permalink
fix: sanitize Helm logs
Browse files Browse the repository at this point in the history
Signed-off-by: Tyler Gillson <tyler.gillson@gmail.com>
  • Loading branch information
TylerGillson committed Nov 22, 2023
1 parent 2372a74 commit bdfd104
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions pkg/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,23 @@ func (c *helmClient) exec(args []string) error {
return nil
}

fmt.Println("helm " + strings.Join(args, " "))
sb := strings.Builder{}
mask := false
for _, a := range args {
if mask {
sb.WriteString("***** ")
mask = false
continue
}
if a == "--password" {
mask = true
}
sb.WriteString(a)
sb.WriteString(" ")
}
sanitizedArgs := sb.String()

fmt.Println("helm " + sanitizedArgs)
cmd := exec.Command(c.helmPath, args...)
if c.stdout != nil {
cmd.Stdout = c.stdout
Expand All @@ -72,7 +88,7 @@ func (c *helmClient) exec(args []string) error {
if strings.Contains(string(output), "release: not found") {
return nil
}
klog.Errorf("Error executing command: helm %s", strings.Join(args, " "))
klog.Errorf("Error executing command: helm %s", sanitizedArgs)
klog.Errorf("Output: %s, Error: %v", string(output), err)
return fmt.Errorf("error executing helm %s: %s", args[0], string(output))
}
Expand Down

0 comments on commit bdfd104

Please sign in to comment.