From 11d4926c8551109d0808df1147b3f5a4704f6183 Mon Sep 17 00:00:00 2001 From: dwertent Date: Wed, 20 Oct 2021 14:49:27 +0300 Subject: [PATCH 1/2] updte junit results --- cautils/customerloader.go | 6 +++--- resultshandling/printer/junit.go | 21 +++++++++++++++++---- resultshandling/printer/printresults.go | 6 +++--- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/cautils/customerloader.go b/cautils/customerloader.go index 8e723b20..c0f5ea5d 100644 --- a/cautils/customerloader.go +++ b/cautils/customerloader.go @@ -129,8 +129,8 @@ func (c *EmptyConfig) GetDefaultNS() string { return k8sinterf func (c *EmptyConfig) GetBackendAPI() getter.IBackend { return nil } // TODO: return mock obj func (c *EmptyConfig) GetClusterName() string { return "unknown" } func (c *EmptyConfig) GenerateURL() { - message := fmt.Sprintf("You can see the results in a user-friendly UI, choose your preferred compliance framework, check risk results history and trends, manage exceptions, get remediation recommendations and much more by registering here: https://%s", getter.GetArmoAPIConnector().GetFrontendURL()) - InfoTextDisplay(os.Stdout, message+"\n") + message := fmt.Sprintf("\nCheckout for more cool features: https://%s\n", getter.GetArmoAPIConnector().GetFrontendURL()) + InfoTextDisplay(os.Stdout, fmt.Sprintf("\n%s\n", message)) } // ====================================================================================== @@ -165,7 +165,7 @@ func (c *ClusterConfig) GenerateURL() { if c.configObj == nil { return } - message := fmt.Sprintf("You can see the results in a user-friendly UI, choose your preferred compliance framework, check risk results history and trends, manage exceptions, get remediation recommendations and much more by registering here: %s", u.String()) + message := fmt.Sprintf("\nCheckout for more cool features: https://%s\n", getter.GetArmoAPIConnector().GetFrontendURL()) if c.configObj.CustomerAdminEMail != "" { InfoTextDisplay(os.Stdout, message+"\n") return diff --git a/resultshandling/printer/junit.go b/resultshandling/printer/junit.go index d3b15c38..370a5d0a 100644 --- a/resultshandling/printer/junit.go +++ b/resultshandling/printer/junit.go @@ -17,9 +17,11 @@ type JUnitTestSuites struct { type JUnitTestSuite struct { XMLName xml.Name `xml:"testsuite"` Tests int `xml:"tests,attr"` - Failures int `xml:"failures,attr"` Time string `xml:"time,attr"` Name string `xml:"name,attr"` + Resources int `xml:"resources,attr"` + Excluded int `xml:"excluded,attr"` + Failed int `xml:"filed,attr"` Properties []JUnitProperty `xml:"properties>property,omitempty"` TestCases []JUnitTestCase `xml:"testcase"` } @@ -30,6 +32,9 @@ type JUnitTestCase struct { Classname string `xml:"classname,attr"` Name string `xml:"name,attr"` Time string `xml:"time,attr"` + Resources int `xml:"resources,attr"` + Excluded int `xml:"excluded,attr"` + Failed int `xml:"filed,attr"` SkipMessage *JUnitSkipMessage `xml:"skipped,omitempty"` Failure *JUnitFailure `xml:"failure,omitempty"` } @@ -55,7 +60,12 @@ type JUnitFailure struct { func convertPostureReportToJunitResult(postureResult *reporthandling.PostureReport) (*JUnitTestSuites, error) { juResult := JUnitTestSuites{XMLName: xml.Name{Local: "Kubescape scan results"}} for _, framework := range postureResult.FrameworkReports { - suite := JUnitTestSuite{Name: framework.Name} + suite := JUnitTestSuite{ + Name: framework.Name, + Resources: framework.GetNumberOfResources(), + Excluded: framework.GetNumberOfWarningResources(), + Failed: framework.GetNumberOfFailedResources(), + } for _, controlReports := range framework.ControlReports { suite.Tests = suite.Tests + 1 testCase := JUnitTestCase{} @@ -63,9 +73,12 @@ func convertPostureReportToJunitResult(postureResult *reporthandling.PostureRepo testCase.Classname = "Kubescape" testCase.Time = "0" if 0 < len(controlReports.RuleReports[0].RuleResponses) { - suite.Failures = suite.Failures + 1 + + testCase.Resources = framework.GetNumberOfResources() + testCase.Excluded = framework.GetNumberOfWarningResources() + testCase.Failed = framework.GetNumberOfFailedResources() failure := JUnitFailure{} - failure.Message = fmt.Sprintf("%d resources failed", len(controlReports.RuleReports[0].RuleResponses)) + failure.Message = fmt.Sprintf("%d resources failed", testCase.Failed) for _, ruleResponses := range controlReports.RuleReports[0].RuleResponses { failure.Contents = fmt.Sprintf("%s\n%s", failure.Contents, ruleResponses.AlertMessage) } diff --git a/resultshandling/printer/printresults.go b/resultshandling/printer/printresults.go index 97602e05..2a718e4c 100644 --- a/resultshandling/printer/printresults.go +++ b/resultshandling/printer/printresults.go @@ -54,7 +54,7 @@ func calculatePostureScore(postureReport *reporthandling.PostureReport) float32 } func (printer *Printer) ActionPrint(opaSessionObj *cautils.OPASessionObj) float32 { - var score float32 + score := calculatePostureScore(opaSessionObj.PostureReport) if printer.printerType == PrettyPrinter { printer.SummarySetup(opaSessionObj.PostureReport) @@ -67,6 +67,7 @@ func (printer *Printer) ActionPrint(opaSessionObj *cautils.OPASessionObj) float3 os.Exit(1) } printer.writer.Write(postureReportStr) + fmt.Printf("\nFinal score: %d\n", int(score*100)) } else if printer.printerType == JunitResultPrinter { junitResult, err := convertPostureReportToJunitResult(opaSessionObj.PostureReport) if err != nil { @@ -79,13 +80,12 @@ func (printer *Printer) ActionPrint(opaSessionObj *cautils.OPASessionObj) float3 os.Exit(1) } printer.writer.Write(postureReportStr) + fmt.Printf("\nFinal score: %d\n", int(score*100)) } else if !cautils.IsSilent() { fmt.Println("unknown output printer") os.Exit(1) } - score = calculatePostureScore(opaSessionObj.PostureReport) - return score } From 9cb937798f1b2696e57f90edc1b4a6c19d4a887c Mon Sep 17 00:00:00 2001 From: dwertent Date: Wed, 20 Oct 2021 14:53:19 +0300 Subject: [PATCH 2/2] update readme --- README.md | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 5afce369..ff012afc 100644 --- a/README.md +++ b/README.md @@ -21,11 +21,9 @@ curl -s https://raw.githubusercontent.com/armosec/kubescape/master/install.sh | ## Run: ``` -kubescape scan framework nsa --exclude-namespaces kube-system,kube-public +kubescape scan framework nsa ``` -If you wish to scan all namespaces in your cluster, remove the `--exclude-namespaces` flag. - ### Click [👍](https://github.com/armosec/kubescape/stargazers) if you want us to continue to develop and improve Kubescape 😀 @@ -86,15 +84,15 @@ Set-ExecutionPolicy RemoteSigned -scope CurrentUser ### Examples -* Scan a running Kubernetes cluster with [`nsa`](https://www.nsa.gov/News-Features/Feature-Stories/Article-View/Article/2716980/nsa-cisa-release-kubernetes-hardening-guidance/) framework and submit results to [Armo portal](https://portal.armo.cloud/) +* Scan a running Kubernetes cluster with [`nsa`](https://www.nsa.gov/News-Features/Feature-Stories/Article-View/Article/2716980/nsa-cisa-release-kubernetes-hardening-guidance/) framework and submit results to [ARMO portal](https://portal.armo.cloud/) ``` -kubescape scan framework nsa --exclude-namespaces kube-system,kube-public --submit +kubescape scan framework nsa --submit ``` -* Scan a running Kubernetes cluster with [`mitre`](https://www.microsoft.com/security/blog/2020/04/02/attack-matrix-kubernetes/) framework and submit results to [Armo portal](https://portal.armo.cloud/) +* Scan a running Kubernetes cluster with [`MITRE ATT&CK®`](https://www.microsoft.com/security/blog/2021/03/23/secure-containerized-environments-with-updated-threat-matrix-for-kubernetes/) framework and submit results to [ARMO portal](https://portal.armo.cloud/) ``` -kubescape scan framework mitre --exclude-namespaces kube-system,kube-public --submit +kubescape scan framework mitre --submit ``` * Scan local `yaml`/`json` files before deploying. [Take a look at the demonstration](https://youtu.be/Ox6DaR7_4ZI) @@ -187,7 +185,7 @@ go build -o kubescape . 3. Run ``` -./kubescape scan framework nsa --exclude-namespaces kube-system,kube-public +./kubescape scan framework nsa ``` 4. Enjoy :zany_face: