-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.go
77 lines (61 loc) · 1.42 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 main
import (
"encoding/json"
"io/ioutil"
"net"
"net/http"
"os"
"github.com/aquasecurity/kube-bench/check"
)
const port = "8080"
const outputFile = "/output/kube-bench.json"
// ID for the Policies category, which is not node specific.
const policiesID = "5"
type kubeBenchModel struct {
Name string
Controls []check.Controls
}
func main() {
data := map[string]check.Controls{}
daemonsetName := os.Getenv("DAEMONSET_SERVICE")
if daemonsetName == "" {
panic("Must set DAEMONSET_SERVICE")
}
// The headless service will return multiple IPs, one for each pod.
addresses, err := net.LookupHost(daemonsetName)
if err != nil {
panic(err)
}
for _, address := range addresses {
response, err := http.Get("http://" + address + ":" + port)
if err != nil {
panic(err)
}
body, err := ioutil.ReadAll(response.Body)
if err != nil {
panic(err)
}
responseData := kubeBenchModel{}
err = json.Unmarshal(body, &responseData)
if err != nil {
panic(err)
}
for _, control := range responseData.Controls {
key := control.ID
// ID 5 "Policies" should be the same for every node.
if key != policiesID {
key = responseData.Name + "/" + key
}
data[key] = control
}
response.Body.Close()
}
outputBytes, err := json.MarshalIndent(data, "", " ")
if err != nil {
panic(err)
}
err = ioutil.WriteFile(outputFile, []byte(outputBytes), 0644)
if err != nil {
panic(err)
}
}