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

Sort control output #8

Merged
merged 1 commit into from
Aug 19, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Kubescape is the first tool for testing if Kubernetes is deployed securely as defined in [Kubernetes Hardening Guidance by to NSA and CISA](https://www.nsa.gov/News-Features/Feature-Stories/Article-View/Article/2716980/nsa-cisa-release-kubernetes-hardening-guidance/)
Tests are configured with YAML files, making this tool easy to update as test specifications evolve.

<img src="docs/using-mov.gif">
<img src="docs/demo.gif">

# TL;DR
## Installation
Expand All @@ -24,15 +24,31 @@ kubescape scan framework nsa --exclude-namespaces kube-system,kube-public

If you wish to scan all namespaces in your cluster, remove the `--exclude-namespaces` flag.

<img src="docs/run.jpeg">
<img src="docs/summery.PNG">


# Status
[![build](https://github.com/armosec/kubescape/actions/workflows/build.yaml/badge.svg)](https://github.com/armosec/kubescape/actions/workflows/build.yaml)
[![Github All Releases](https://img.shields.io/github/downloads/armosec/kubescape/total.svg)]()

# How to build
`go mod tidy && go build -o kubescape` :zany_face:

1. Clone Project
```
git clone git@github.com:armosec/kubescape.git kubescape && cd "$_"
```

2. Build
```
go mod tidy && go build -o kubescape .
```

3. Run
```
./kubescape scan framework nsa --exclude-namespaces kube-system,kube-public
```

4. Enjoy :zany_face:

# Under the hood

Expand Down
Binary file added docs/demo.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/summery.PNG
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 18 additions & 6 deletions printer/printresults.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"kube-escape/cautils"
"os"
"sort"

"kube-escape/cautils/k8sinterface"
"kube-escape/cautils/opapolicy"
Expand Down Expand Up @@ -68,12 +69,14 @@ func (printer *Printer) SummerySetup(postureReport *opapolicy.PostureReport) {
}

func (printer *Printer) PrintResults() {
for control, controlSummery := range printer.summery {
printer.printTitle(control, &controlSummery)
printer.printResult(control, &controlSummery)

if controlSummery.TotalResources > 0 {
printer.printSummery(control, &controlSummery)
controlNames := printer.getSortedControlsNames()
for i := 0; i < len(controlNames); i++ {
controlSummery := printer.summery[controlNames[i]]
printer.printTitle(controlNames[i], &controlSummery)
printer.printResult(controlNames[i], &controlSummery)

if printer.summery[controlNames[i]].TotalResources > 0 {
printer.printSummery(controlNames[i], &controlSummery)
}

}
Expand Down Expand Up @@ -165,3 +168,12 @@ func (printer *Printer) PrintSummaryTable() {
summaryTable.SetFooter(generateFooter(len(printer.summery), sumFailed, sumTotal))
summaryTable.Render()
}

func (printer *Printer) getSortedControlsNames() []string {
controlNames := make([]string, 0, len(printer.summery))
for k := range printer.summery {
controlNames = append(controlNames, k)
}
sort.Strings(controlNames)
return controlNames
}