@@ -138,7 +138,8 @@ func main() {
138
138
go func () {
139
139
http .HandleFunc ("/validate" , ValidateDeployment )
140
140
log .Println ("Starting webhook server on :8000..." )
141
- err := http .ListenAndServeTLS (":8000" , "certs/tls.crt" , "certs/tls.key" , nil )
141
+ // local go for certs/tls.crt and certs/tls.key
142
+ err := http .ListenAndServeTLS (":8000" , "/certs/tls.crt" , "/certs/tls.key" , nil ) // k8s
142
143
if err != nil {
143
144
log .Fatalf ("Failed to start webhook server: %v" , err )
144
145
}
@@ -241,15 +242,27 @@ func ValidateDeployment(w http.ResponseWriter, r *http.Request) {
241
242
images := []string {}
242
243
denied := false
243
244
var reasons []string
245
+ BYPASS_CVE_DENIED := false
244
246
// InitContainers
245
247
for _ , c := range dep .Spec .Template .Spec .InitContainers {
248
+ for _ , e := range c .Env {
249
+ if e .Name == "BYPASS_CVE_DENIED" && (e .Value == "yes" || e .Value == "true" ) {
250
+ BYPASS_CVE_DENIED = true
251
+ }
252
+ }
246
253
images = append (images , c .Image )
247
254
}
248
255
// Containers
249
256
for _ , c := range dep .Spec .Template .Spec .Containers {
257
+ for _ , e := range c .Env {
258
+ if e .Name == "BYPASS_CVE_DENIED" && (e .Value == "yes" || e .Value == "true" ) {
259
+ BYPASS_CVE_DENIED = true
260
+ }
261
+ }
250
262
images = append (images , c .Image )
251
263
}
252
264
for _ , image := range images {
265
+ log .Printf ("started scanning for [ %s ]" , image )
253
266
ok , vulns , err := scanImageWithTrivy (image )
254
267
if err != nil {
255
268
log .Printf ("Error scanning image %s: %v" , image , err )
@@ -262,7 +275,14 @@ func ValidateDeployment(w http.ResponseWriter, r *http.Request) {
262
275
}
263
276
message := "Images allowed"
264
277
if denied {
265
- message = fmt .Sprintf ("Denied images due to CVEs: %v" , reasons )
278
+ message = fmt .Sprintf ("Denied images due to total CVEs across %v images: %v" , len (images ), reasons )
279
+ log .Printf ("Denied images due to CVEs: %v" , reasons )
280
+ }
281
+
282
+ // look for BYPASS_CVE env - you need to skip
283
+ if BYPASS_CVE_DENIED {
284
+ log .Printf ("It have CVE across all the %v images, but we are skipping as BYPASS_CVE_DENIED set true" , len (images ))
285
+ denied = false
266
286
}
267
287
268
288
log .Printf ("Validating Deployment: %s, Images: %v" , dep .Name , images )
0 commit comments