Skip to content

Commit

Permalink
fix: obfuscate args
Browse files Browse the repository at this point in the history
  • Loading branch information
vsukhin committed Oct 31, 2023
1 parent 4ad3606 commit 90c41d9
Show file tree
Hide file tree
Showing 16 changed files with 51 additions and 24 deletions.
2 changes: 1 addition & 1 deletion contrib/executor/artillery/pkg/runner/artillery.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (r *ArtilleryRunner) Run(ctx context.Context, execution testkube.Execution)

// run executor
command, args := executor.MergeCommandAndArgs(execution.Command, args)
output.PrintLogf("%s Test run command %s %s", ui.IconRocket, command, strings.Join(args, " "))
output.PrintLogf("%s Test run command %s %s", ui.IconRocket, command, strings.Join(envManager.ObfuscateStringSlice(args), " "))
out, runerr := executor.Run(runPath, command, envManager, args...)

out = envManager.ObfuscateSecrets(out)
Expand Down
2 changes: 1 addition & 1 deletion contrib/executor/curl/pkg/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (r *CurlRunner) Run(ctx context.Context, execution testkube.Execution) (res
}

runPath := workingDir
outputPkg.PrintLogf("%s Test run command %s %s", ui.IconRocket, command, strings.Join(args, " "))
outputPkg.PrintLogf("%s Test run command %s %s", ui.IconRocket, command, strings.Join(envManager.ObfuscateStringSlice(args), " "))
output, err := executor.Run(runPath, command, envManager, args...)
output = envManager.ObfuscateSecrets(output)

Expand Down
2 changes: 1 addition & 1 deletion contrib/executor/cypress/pkg/runner/cypress.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (r *CypressRunner) Run(ctx context.Context, execution testkube.Execution) (

// run cypress inside repo directory ignore execution error in case of failed test
command, args = executor.MergeCommandAndArgs(execution.Command, args)
output.PrintLogf("%s Test run command %s %s", ui.IconRocket, command, strings.Join(args, " "))
output.PrintLogf("%s Test run command %s %s", ui.IconRocket, command, strings.Join(envManager.ObfuscateStringSlice(args), " "))
out, err = executor.Run(runPath, command, envManager, args...)
out = envManager.ObfuscateSecrets(out)

Expand Down
8 changes: 4 additions & 4 deletions contrib/executor/ginkgo/pkg/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (r *GinkgoRunner) Run(ctx context.Context, execution testkube.Execution) (r
}

// Set up ginkgo potential args
ginkgoArgs, junitReport, err := BuildGinkgoArgs(ginkgoParams, path, runPath, reportFile, execution)
ginkgoArgs, junitReport, err := BuildGinkgoArgs(envManager, ginkgoParams, path, runPath, reportFile, execution)
if err != nil {
return result, err
}
Expand All @@ -122,7 +122,7 @@ func (r *GinkgoRunner) Run(ctx context.Context, execution testkube.Execution) (r

// run executor here
command, args = executor.MergeCommandAndArgs(execution.Command, ginkgoArgs)
output.PrintLogf("%s Test run command %s %s", ui.IconRocket, command, strings.Join(args, " "))
output.PrintLogf("%s Test run command %s %s", ui.IconRocket, command, strings.Join(envManager.ObfuscateStringSlice(args), " "))
out, err := executor.Run(runPath, command, envManager, args...)
out = envManager.ObfuscateSecrets(out)

Expand Down Expand Up @@ -252,7 +252,7 @@ func FindGinkgoParams(execution *testkube.Execution, defaultParams map[string]st
return retVal
}

func BuildGinkgoArgs(params map[string]string, path, runPath, reportFile string, execution testkube.Execution) ([]string, bool, error) {
func BuildGinkgoArgs(envManager *env.Manager, params map[string]string, path, runPath, reportFile string, execution testkube.Execution) ([]string, bool, error) {
output.PrintLogf("%s Building Ginkgo arguments from params", ui.IconWorld)

args := execution.Args
Expand Down Expand Up @@ -314,7 +314,7 @@ func BuildGinkgoArgs(params map[string]string, path, runPath, reportFile string,
args[i] = os.ExpandEnv(args[i])
}

output.PrintLogf("%s Ginkgo arguments from params built: %s", ui.IconCheckMark, args)
output.PrintLogf("%s Ginkgo arguments from params built: %s", ui.IconCheckMark, envManager.ObfuscateStringSlice(args))
return args, hasJunit && hasReport, nil
}

Expand Down
1 change: 1 addition & 0 deletions contrib/executor/gradle/pkg/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ func (r *GradleRunner) Run(ctx context.Context, execution testkube.Execution) (r
args[i] = os.ExpandEnv(args[i])
}

output.PrintEvent("Running task: "+task, project, gradleCommand, envManager.ObfuscateStringSlice(args))
out, err := executor.Run(runPath, gradleCommand, envManager, args...)
out = envManager.ObfuscateSecrets(out)

Expand Down
4 changes: 2 additions & 2 deletions contrib/executor/jmeter/pkg/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (r *JMeterRunner) Run(ctx context.Context, execution testkube.Execution) (r
args[i] = os.ExpandEnv(args[i])
}

output.PrintLogf("%s Using arguments: %v", ui.IconWorld, args)
output.PrintLogf("%s Using arguments: %v", ui.IconWorld, envManager.ObfuscateStringSlice(args))

entryPoint := getEntryPoint()
for i := range execution.Command {
Expand All @@ -173,7 +173,7 @@ func (r *JMeterRunner) Run(ctx context.Context, execution testkube.Execution) (r

command, args := executor.MergeCommandAndArgs(execution.Command, args)
// run JMeter inside repo directory ignore execution error in case of failed test
output.PrintLogf("%s Test run command %s %s", ui.IconRocket, command, strings.Join(args, " "))
output.PrintLogf("%s Test run command %s %s", ui.IconRocket, command, strings.Join(envManager.ObfuscateStringSlice(args), " "))
out, err := executor.Run(runPath, command, envManager, args...)
if err != nil {
return *result.WithErrors(errors.Errorf("jmeter run error: %v", err)), nil
Expand Down
4 changes: 2 additions & 2 deletions contrib/executor/jmeterd/pkg/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func (r *JMeterDRunner) Run(ctx context.Context, execution testkube.Execution) (
args[i] = os.ExpandEnv(args[i])
}

output.PrintLogf("%s Using arguments: %v", ui.IconWorld, args)
output.PrintLogf("%s Using arguments: %v", ui.IconWorld, envManager.ObfuscateStringSlice(args))

entryPoint := getEntryPoint()
for i := range execution.Command {
Expand All @@ -220,7 +220,7 @@ func (r *JMeterDRunner) Run(ctx context.Context, execution testkube.Execution) (

command, args := executor.MergeCommandAndArgs(execution.Command, args)
// run JMeter inside repo directory ignore execution error in case of failed test
output.PrintLogf("%s Test run command %s %s", ui.IconRocket, command, strings.Join(args, " "))
output.PrintLogf("%s Test run command %s %s", ui.IconRocket, command, strings.Join(envManager.ObfuscateStringSlice(args), " "))
out, err := executor.Run(runPath, command, envManager, args...)
if err != nil {
return *result.WithErrors(errors.Errorf("jmeter run error: %v", err)), nil
Expand Down
2 changes: 1 addition & 1 deletion contrib/executor/k6/pkg/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (r *K6Runner) Run(ctx context.Context, execution testkube.Execution) (resul
}

command, args := executor.MergeCommandAndArgs(execution.Command, args)
outputPkg.PrintEvent("Running", directory, command, args)
outputPkg.PrintEvent("Running", directory, command, envManager.ObfuscateStringSlice(args))
runPath := directory
if execution.Content.Repository != nil && execution.Content.Repository.WorkingDir != "" {
runPath = filepath.Join(directory, execution.Content.Repository.WorkingDir)
Expand Down
4 changes: 2 additions & 2 deletions contrib/executor/kubepug/pkg/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ func (r *KubepugRunner) Run(ctx context.Context, execution testkube.Execution) (
return testkube.ExecutionResult{}, fmt.Errorf("could not build up parameters: %w", err)
}

output.PrintLogf("%s Running kubepug with arguments: %v", ui.IconWorld, args)
envManager := env.NewManagerWithVars(execution.Variables)
envManager.GetReferenceVars(envManager.Variables)
output.PrintLogf("%s Running kubepug with arguments: %v", ui.IconWorld, envManager.ObfuscateStringSlice(args))

runPath := workingDir
command, args := executor.MergeCommandAndArgs(execution.Command, args)
output.PrintLogf("%s Test run command %s %s", ui.IconRocket, command, strings.Join(args, " "))
output.PrintLogf("%s Test run command %s %s", ui.IconRocket, command, strings.Join(envManager.ObfuscateStringSlice(args), " "))
out, err := executor.Run(runPath, command, envManager, args...)
out = envManager.ObfuscateSecrets(out)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion contrib/executor/maven/pkg/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (r *MavenRunner) Run(ctx context.Context, execution testkube.Execution) (re
args[i] = os.ExpandEnv(args[i])
}

outputPkg.PrintEvent("Running goal: "+goal, mavenHome, mavenCommand, args)
outputPkg.PrintEvent("Running goal: "+goal, mavenHome, mavenCommand, envManager.ObfuscateStringSlice(args))
output, err := executor.Run(runPath, mavenCommand, envManager, args...)
output = envManager.ObfuscateSecrets(output)

Expand Down
2 changes: 1 addition & 1 deletion contrib/executor/playwright/pkg/runner/playwright.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (r *PlaywrightRunner) Run(ctx context.Context, execution testkube.Execution
envManager.GetReferenceVars(envManager.Variables)

command, args := executor.MergeCommandAndArgs(execution.Command, args)
output.PrintEvent("Running", runPath, command, args)
output.PrintEvent("Running", runPath, command, envManager.ObfuscateStringSlice(args))
out, runErr := executor.Run(runPath, command, envManager, args...)
out = envManager.ObfuscateSecrets(out)

Expand Down
2 changes: 1 addition & 1 deletion contrib/executor/postman/pkg/runner/newman/newman.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (r *NewmanRunner) Run(ctx context.Context, execution testkube.Execution) (r
// we'll get error here in case of failed test too so we treat this as
// starter test execution with failed status
command, args := executor.MergeCommandAndArgs(execution.Command, args)
output.PrintLogf("%s Test run command %s %s", ui.IconRocket, command, strings.Join(args, " "))
output.PrintLogf("%s Test run command %s %s", ui.IconRocket, command, strings.Join(envManager.ObfuscateStringSlice(args), " "))
out, err := executor.Run(runPath, command, envManager, args...)

out = envManager.ObfuscateSecrets(out)
Expand Down
3 changes: 2 additions & 1 deletion contrib/executor/soapui/pkg/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ func (r *SoapUIRunner) runSoapUI(execution *testkube.Execution, workingDir strin

runPath := workingDir
command, args := executor.MergeCommandAndArgs(execution.Command, nil)
output.PrintLogf("%s Test run command %s %s", ui.IconRocket, strings.Join(execution.Command, " "), strings.Join(execution.Args, " "))
output.PrintLogf("%s Test run command %s %s", ui.IconRocket, strings.Join(execution.Command, " "),
strings.Join(envManager.ObfuscateStringSlice(execution.Args), " "))
output, err := executor.Run(runPath, command, envManager, args...)
output = envManager.ObfuscateSecrets(output)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions contrib/executor/tracetest/pkg/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ func (r *TracetestRunner) Run(ctx context.Context, execution testkube.Execution)
output.PrintLogf("%s Could not build up parameters: %s", ui.IconCross, err.Error())
return testkube.ExecutionResult{}, fmt.Errorf("could not build up parameters: %w", err)
}
output.PrintLogf("%s Using arguments: %v", ui.IconWorld, args)
output.PrintLogf("%s Using arguments: %v", ui.IconWorld, envManager.ObfuscateStringSlice(args))

command, args := executor.MergeCommandAndArgs(execution.Command, args)

// Run tracetest test from definition file
output.PrintLogf("%s Test run command %s %s", ui.IconRocket, command, strings.Join(args, " "))
output.PrintLogf("%s Test run command %s %s", ui.IconRocket, command, strings.Join(envManager.ObfuscateStringSlice(args), " "))
output, err := executor.Run("", command, envManager, args...)
runResult := model.Result{Output: string(output), ServerEndpoint: te, OutputEndpoint: toe}

Expand Down
9 changes: 5 additions & 4 deletions contrib/executor/zap/pkg/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,17 @@ func (r *ZapRunner) Run(ctx context.Context, execution testkube.Execution) (resu
if err != nil {
return *result.WithErrors(err), nil
}
args := zapArgs(scanType, options, reportFile)
output.PrintLogf("%s Reading execution arguments", ui.IconWorld)
args = MergeArgs(args, reportFile, execution)
output.PrintLogf("%s Arguments are ready: %s", ui.IconCheckMark, args)

output.PrintLogf("%s Preparing variables", ui.IconWorld)
envManager := env.NewManagerWithVars(execution.Variables)
envManager.GetReferenceVars(envManager.Variables)
output.PrintLogf("%s Variables are prepared", ui.IconCheckMark)

args := zapArgs(scanType, options, reportFile)
output.PrintLogf("%s Reading execution arguments", ui.IconWorld)
args = MergeArgs(args, reportFile, execution)
output.PrintLogf("%s Arguments are ready: %s", ui.IconCheckMark, envManager.ObfuscateStringSlice(args))

// when using file based ZAP parameters it expects a /zap/wrk directory
// we simply symlink the directory
os.Symlink(workingDir, filepath.Join(r.ZapHome, "wrk"))
Expand Down
24 changes: 24 additions & 0 deletions pkg/executor/env/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ type Interface interface {
GetReferenceVars(variables map[string]testkube.Variable)
// ObfuscateSecrets obfuscates secret values
ObfuscateSecrets(p []byte) []byte
// ObfuscateStringSlice obfuscates string slice values
ObfuscateStringSlice(values []string) []string
}

// NewManager returns an implementation of the Manager
Expand Down Expand Up @@ -285,3 +287,25 @@ func (m Manager) ObfuscateSecrets(p []byte) []byte {

return p
}

// ObfuscateStringSlice obfuscates string slice values
func (m Manager) ObfuscateStringSlice(values []string) []string {
if m.Variables == nil {
return values
}

var results []string
for _, value := range values {
for _, variable := range m.Variables {
if !variable.IsSecret() {
continue
}

value = strings.ReplaceAll(value, variable.Value, strings.Repeat("*", len(variable.Value)))
}

results = append(results, value)
}

return results
}

0 comments on commit 90c41d9

Please sign in to comment.