forked from k8sgateway/k8sgateway
-
Notifications
You must be signed in to change notification settings - Fork 0
/
securityscan_utils.go
131 lines (117 loc) · 3.66 KB
/
securityscan_utils.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package securityscanutils
import (
"fmt"
"io/ioutil"
"net/http"
"k8s.io/apimachinery/pkg/util/version"
)
func BuildSecurityScanReportGloo(tags []string) error {
// tags are sorted by minor version
latestTag := tags[0]
prevMinorVersion, _ := version.ParseSemantic(latestTag)
for ix, tag := range tags {
semver, err := version.ParseSemantic(tag)
if err != nil {
return err
}
if ix == 0 || semver.Minor() != prevMinorVersion.Minor() {
fmt.Printf("\n***Latest %d.%d.x Gloo Open Source Release: %s***\n\n", semver.Major(), semver.Minor(), tag)
err = printImageReportGloo(tag)
if err != nil {
return err
}
prevMinorVersion = semver
} else {
fmt.Printf("<details><summary> Release %s </summary>\n\n", tag)
err = printImageReportGloo(tag)
if err != nil {
return err
}
fmt.Println("</details>")
}
}
return nil
}
func BuildSecurityScanReportGlooE(tags []string) error {
// tags are sorted by minor version
latestTag := tags[0]
prevMinorVersion, _ := version.ParseSemantic(latestTag)
for ix, tag := range tags {
semver, err := version.ParseSemantic(tag)
if err != nil {
return err
}
if ix == 0 || semver.Minor() != prevMinorVersion.Minor() {
fmt.Printf("\n***Latest %d.%d.x Gloo Enterprise Release: %s***\n\n", semver.Major(), semver.Minor(), tag)
err = printImageReportGlooE(semver)
if err != nil {
return err
}
prevMinorVersion = semver
} else {
fmt.Printf("<details><summary>Release %s </summary>\n\n", tag)
err = printImageReportGlooE(semver)
if err != nil {
return err
}
fmt.Println("</details>")
}
}
return nil
}
// List of images included in gloo edge open source
func OpenSourceImages() []string {
return []string{"access-logger", "certgen", "discovery", "gateway", "gloo", "gloo-envoy-wrapper", "ingress", "sds"}
}
// List of images only included in gloo edge enterprise
// In 1.7, we replaced the grpcserver images with gloo-fed images.
// For images before 1.7, set before17 to true.
func EnterpriseImages(before17 bool) []string {
extraImages := []string{"gloo-fed", "gloo-fed-apiserver", "gloo-fed-apiserver-envoy", "gloo-federation-console", "gloo-fed-rbac-validating-webhook"}
if before17 {
extraImages = []string{"grpcserver-ui", "grpcserver-envoy", "grpcserver-ee"}
}
return append([]string{"rate-limit-ee", "gloo-ee", "gloo-ee-envoy-wrapper", "observability-ee", "extauth-ee"}, extraImages...)
}
func printImageReportGloo(tag string) error {
for _, image := range OpenSourceImages() {
fmt.Printf("**Gloo %s image**\n\n", image)
url := "https://storage.googleapis.com/solo-gloo-security-scans/gloo/" + tag + "/" + image + "_cve_report.docgen"
report, err := GetSecurityScanReport(url)
if err != nil {
return err
}
fmt.Printf("%s\n\n", report)
}
return nil
}
func printImageReportGlooE(semver *version.Version) error {
tag := semver.String()
hasFedVersion, _ := semver.Compare("1.7.0")
for _, image := range EnterpriseImages(hasFedVersion < 0) {
fmt.Printf("**Gloo Enterprise %s image**\n\n", image)
url := "https://storage.googleapis.com/solo-gloo-security-scans/solo-projects/" + tag + "/" + image + "_cve_report.docgen"
report, err := GetSecurityScanReport(url)
if err != nil {
return err
}
fmt.Printf("%s\n\n", report)
}
return nil
}
func GetSecurityScanReport(url string) (string, error) {
resp, err := http.Get(url)
if err != nil {
return "", err
}
var report string
if resp.StatusCode == http.StatusOK {
bodyBytes, _ := ioutil.ReadAll(resp.Body)
report = string(bodyBytes)
} else if resp.StatusCode == http.StatusNotFound {
// Older releases may be missing scan results
report = "No scan found\n"
}
resp.Body.Close()
return report, nil
}