Skip to content

Commit f040b61

Browse files
updated the backend to use trivy client
1 parent 1be8d75 commit f040b61

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

main.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ import (
44
"bytes"
55
"encoding/json"
66
"fmt"
7+
"log"
8+
"net/http"
9+
"os"
10+
"os/exec"
11+
"strings"
12+
"time"
13+
714
"github.com/joho/godotenv"
815
"github.com/manzil-infinity180/k8s-custom-controller/controller"
916
admissionv1 "k8s.io/api/admission/v1"
@@ -15,12 +22,6 @@ import (
1522
"k8s.io/client-go/rest"
1623
"k8s.io/client-go/tools/clientcmd"
1724
"k8s.io/client-go/tools/clientcmd/api"
18-
"log"
19-
"net/http"
20-
"os"
21-
"os/exec"
22-
"strings"
23-
"time"
2425
)
2526

2627
// homeDir retrieves the user's home directory
@@ -183,7 +184,16 @@ func parseRequest(r *http.Request) (*admissionv1.AdmissionReview, error) {
183184
}
184185

185186
func scanImageWithTrivy(image string) (bool, string, error) {
186-
cmd := exec.Command("trivy", "image", "--quiet", "--severity", "HIGH,CRITICAL", "--format", "json", image)
187+
// cmd := exec.Command("trivy", "image", "--quiet", "--severity", "HIGH,CRITICAL", "--format", "json", image)
188+
// out, err := cmd.Output()
189+
cmd := exec.Command(
190+
"trivy",
191+
"image",
192+
"--scanners", "vuln",
193+
"--server", "http://trivy-server-service.default.svc:8080", // [service_name].[namespace].svc:[port] (if not port 80)
194+
"--format", "json",
195+
image,
196+
)
187197
out, err := cmd.Output()
188198
if err != nil {
189199
return false, "", fmt.Errorf("trivy scan failed for %s: %v", image, err)

0 commit comments

Comments
 (0)