diff --git a/cmd/common.go b/cmd/common.go index ef09d82..de24273 100644 --- a/cmd/common.go +++ b/cmd/common.go @@ -19,6 +19,7 @@ import ( "io/ioutil" "os" "path/filepath" + "strings" "github.com/aquasecurity/kube-bench/check" "github.com/golang/glog" @@ -142,6 +143,10 @@ func prettyPrint(r *check.Controls, summary check.Summary) { colorPrint(check.INFO, fmt.Sprintf("%s %s\n", g.ID, g.Text)) for _, c := range g.Checks { colorPrint(c.State, fmt.Sprintf("%s %s\n", c.ID, c.Text)) + + if includeTestOutput && c.State == check.FAIL && len(c.ActualValue) > 0 { + printRawOutput(c.ActualValue) + } } } @@ -240,3 +245,9 @@ func isMaster() bool { } return true } + +func printRawOutput(output string) { + for _, row := range strings.Split(output, "\n") { + fmt.Println(fmt.Sprintf("\t %s", row)) + } +} diff --git a/cmd/root.go b/cmd/root.go index 2f481ba..7b09fcd 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -47,6 +47,7 @@ var ( noSummary bool noRemediations bool filterOpts FilterOpts + includeTestOutput bool ) // RootCmd represents the base command when called without any subcommands @@ -87,6 +88,7 @@ func init() { RootCmd.PersistentFlags().BoolVar(&pgSQL, "pgsql", false, "Save the results to PostgreSQL") RootCmd.PersistentFlags().BoolVar(&filterOpts.Scored, "scored", true, "Run the scored CIS checks") RootCmd.PersistentFlags().BoolVar(&filterOpts.Unscored, "unscored", true, "Run the unscored CIS checks") + RootCmd.PersistentFlags().BoolVar(&includeTestOutput, "include-test-output", false, "Prints the actual result when test fails") RootCmd.PersistentFlags().StringVarP( &filterOpts.CheckList,