-
Notifications
You must be signed in to change notification settings - Fork 432
/
securityscan_utils.go
148 lines (133 loc) · 4.37 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
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(semver)
if err != nil {
return err
}
prevMinorVersion = semver
} else {
fmt.Printf("<details><summary> Release %s </summary>\n\n", tag)
err = printImageReportGloo(semver)
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 version 1.<version>.x
func OpenSourceImages(semver *version.Version) []string {
images := []string{"access-logger", "certgen", "discovery", "gloo", "gloo-envoy-wrapper", "ingress", "sds"}
kubectlThirteen := semver.Minor() == 13
kubectlTwelve := semver.Minor() == 12 && semver.AtLeast(version.MustParseSemantic("1.12.3"))
kubectlEleven := semver.Minor() == 11 && semver.AtLeast(version.MustParseSemantic("1.11.28"))
if kubectlThirteen || kubectlTwelve || kubectlEleven {
images = append(images, "kubectl")
}
if semver.LessThan(version.MustParseSemantic("1.12.0")) {
images = append(images, "gateway")
}
return images
}
// List of images only included in gloo edge enterprise
// In 1.7, we replaced the grpcserver images with gloo-fed images.
func EnterpriseImages(semver *version.Version) []string {
images := []string{"rate-limit-ee", "gloo-ee", "gloo-ee-envoy-wrapper", "observability-ee", "extauth-ee"}
if semver.AtLeast(version.MustParseSemantic("1.12.0")) {
images = append(images, "caching-ee")
}
if semver.AtLeast(version.MustParseSemantic("1.10.0")) {
images = append(images, "discovery-ee")
}
if semver.AtLeast(version.MustParseSemantic("1.7.0")) {
images = append(images, "gloo-fed", "gloo-fed-apiserver", "gloo-fed-apiserver-envoy", "gloo-federation-console", "gloo-fed-rbac-validating-webhook")
} else if semver.LessThan(version.MustParseSemantic("1.7.0")) {
images = append(images, "grpcserver-ui", "grpcserver-envoy", "grpcserver-ee")
}
return images
}
func printImageReportGloo(semver *version.Version) error {
for _, image := range OpenSourceImages(semver) {
fmt.Printf("**Gloo %s image**\n\n", image)
url := "https://storage.googleapis.com/solo-gloo-security-scans/gloo/" + semver.String() + "/" + 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()
for _, image := range EnterpriseImages(semver) {
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
}