-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathkube_hunter.go
51 lines (46 loc) · 1.18 KB
/
kube_hunter.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
package cmd
import (
"context"
starboardapi "github.com/aquasecurity/starboard/pkg/generated/clientset/versioned"
"github.com/aquasecurity/starboard/pkg/kubehunter"
"github.com/aquasecurity/starboard/pkg/kubehunter/crd"
"github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/client-go/kubernetes"
)
func NewKubeHunterCmd(cf *genericclioptions.ConfigFlags) *cobra.Command {
cmd := &cobra.Command{
Use: "kube-hunter",
Short: "Hunt for security weaknesses",
RunE: func(cmd *cobra.Command, args []string) (err error) {
ctx := context.Background()
config, err := cf.ToRESTConfig()
if err != nil {
return
}
kubernetesClientset, err := kubernetes.NewForConfig(config)
if err != nil {
return
}
opts, err := getScannerOpts(cmd)
if err != nil {
return
}
report, err := kubehunter.NewScanner(opts, kubernetesClientset).Scan(ctx)
if err != nil {
return
}
starboardClientset, err := starboardapi.NewForConfig(config)
if err != nil {
return
}
err = crd.NewWriter(starboardClientset).Write(ctx, report, "cluster")
if err != nil {
return
}
return
},
}
registerScannerOpts(cmd)
return cmd
}