-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
77 lines (63 loc) · 2.36 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// package
package main
import (
"flag"
"fmt"
"os"
"path/filepath"
"time"
"github.com/mritunjaysharma394/policy-report-prototype/pkg/report"
"github.com/mritunjaysharma394/policy-report-prototype/pkg/kubebench"
"k8s.io/client-go/util/homedir"
)
var (
name string
namespace string
category string
kubeconfig string
kubebenchYAML string
kubebenchImg string
kubebenchTargets string
kubebenchVersion string
kubebenchBenchmark string
timeout time.Duration
)
func parseArguments() {
flag.StringVar(&name, "name", "kube-bench", "name of policy report")
flag.StringVar(&namespace, "namespace", "default", "namespace of the cluster")
flag.StringVar(&category, "category", "CIS Benchmarks", "category of the policy report")
flag.StringVar(&kubebenchYAML, "yaml", "job.yaml", "YAML for kube-bench job")
flag.StringVar(&kubebenchTargets, "kube-bench-targets", "master,node,etcd,policies", "targets for benchmark of kube-bench job")
flag.StringVar(&kubebenchVersion, "kube-bench-version", "", "specify the Kubernetes version for kube-bench job")
flag.StringVar(&kubebenchBenchmark, "kube-bench-benchmark", "", "specify the benchmark for kube-bench job")
kubebenchImg = *flag.String("kubebenchImg", "aquasec/kube-bench:latest", "kube-bench image used as part of this test")
timeout = *flag.Duration("timeout", 10*time.Minute, "Test Timeout")
if home := homedir.HomeDir(); home != "" {
flag.StringVar(&kubeconfig, "kubeconfig", filepath.Join(home, ".kube", "config"), "(optional) absolute path to the kubeconfig file")
} else {
flag.StringVar(&kubeconfig, "kubeconfig", "", "absolute path to the kubeconfig file")
}
flag.Parse()
}
func main() {
parseArguments()
//run kube-bench job
cis, err := kubebench.RunJob(kubeconfig, kubebenchYAML, kubebenchImg, kubebenchVersion, kubebenchBenchmark, kubebenchTargets, timeout)
if err != nil {
fmt.Printf("failed to run job of kube-bench: %v \n", err)
os.Exit(-1)
}
// create policy report
r, err := report.New(cis, name, category)
if err != nil {
fmt.Printf("failed to create policy reports: %v \n", err)
os.Exit(-1)
}
// write policy report
r, err = report.Write(r, namespace, kubeconfig)
if err != nil {
fmt.Printf("failed to create policy reports: %v \n", err)
os.Exit(-1)
}
fmt.Printf("wrote policy report %s/%s \n", r.Namespace, r.Name)
}