-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: add aqua trivy as trivy operator (#572)
Signed-off-by: FogDong <[email protected]> Signed-off-by: FogDong <[email protected]>
- Loading branch information
Showing
11 changed files
with
165 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import ( | ||
"vela/op" | ||
"strings" | ||
"encoding/yaml" | ||
) | ||
|
||
"trivy-check": { | ||
type: "workflow-step" | ||
annotations: { | ||
"definition.oam.dev/example-url": "https://raw.githubusercontent.com/kubevela/catalog/master/examples/trivy-operator/trivy-check-example.yaml" | ||
} | ||
labels: {} | ||
description: "" | ||
} | ||
template: { | ||
findResource: op.#Steps & { | ||
resourceType: *parameter.resource.kind | string | ||
resourceName: *parameter.resource.name | string | ||
if parameter.resource.kind == "Deployment" { | ||
deployment: op.#Read & { | ||
value: { | ||
apiVersion: "apps/v1" | ||
kind: "Deployment" | ||
metadata: { | ||
name: parameter.resource.name | ||
namespace: context.namespace | ||
} | ||
} | ||
} | ||
rs: op.#List & { | ||
resource: { | ||
apiVersion: "apps/v1" | ||
kind: "ReplicaSet" | ||
} | ||
filter: { | ||
namespace: context.namespace | ||
matchingLabels: deployment.value.spec.selector.matchLabels | ||
} | ||
} | ||
resourceType: "ReplicaSet" | ||
if rs.list != _|_ { | ||
if rs.list.items != _|_ { | ||
if len(rs.list.items) > 0 { | ||
resourceName: rs.list.items[0].metadata.name | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
findVulns: op.#Steps & { | ||
scanPod: op.#List & { | ||
resource: { | ||
apiVersion: "v1" | ||
kind: "Pod" | ||
} | ||
filter: { | ||
namespace: "trivy-system" | ||
matchingLabels: { | ||
"trivy-operator.resource.kind": findResource.resourceType | ||
"trivy-operator.resource.name": findResource.resourceName | ||
} | ||
} | ||
} | ||
wait: op.#ConditionalWait & { | ||
continue: len(scanPod.list.items) == 0 | ||
} | ||
vulns: op.#List & { | ||
resource: { | ||
apiVersion: "aquasecurity.github.io/v1alpha1" | ||
kind: "VulnerabilityReport" | ||
} | ||
filter: { | ||
namespace: context.namespace | ||
matchingLabels: { | ||
"trivy-operator.resource.kind": findResource.resourceType | ||
"trivy-operator.resource.name": findResource.resourceName | ||
} | ||
} | ||
} | ||
} | ||
|
||
trivyLevel: strings.Join(parameter.level, ",") | ||
result: { | ||
report: {...} | ||
if findVulns.vulns.list != _|_ && findVulns.vulns.list.items != _|_ for v in findVulns.vulns.list.items { | ||
report: "\(v.report.artifact.repository):\(v.report.artifact.tag)": { | ||
summary: v.report.summary | ||
if parameter.showDetail { | ||
details: [ for vul in v.report.vulnerabilities if strings.Contains(trivyLevel, vul.severity) { | ||
"\(vul.severity) \(vul.vulnerabilityID)": { | ||
link: vul.primaryLink | ||
title: vul.title | ||
resource: vul.resource | ||
} | ||
}] | ||
} | ||
} | ||
} | ||
|
||
if len(report) > 0 { | ||
message: "Trivy Scan Result: \n\n" + yaml.Marshal(report) | ||
} | ||
if len(report) == 0 { | ||
message: "No processed trivy scanning job found for \(findResource.resourceType) \(findResource.resourceName)" | ||
} | ||
} | ||
parameter: { | ||
level: *["CRITICAL"] | [...string] | ||
showDetail: *true | bool | ||
resource: { | ||
kind: *"Deployment" | "StatefulSet" | "ReplicaSet" | "Job" | "Pod" | "DaemonSet" | string | ||
name: string | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,7 @@ | ||
parameter: { | ||
//+usage=Deploy to specified clusters. Leave empty to deploy to all clusters. | ||
// +usage=Deploy to specified clusters. Leave empty to deploy to all clusters. | ||
clusters?: [...string] | ||
|
||
//+usage=Namespace to deploy to, defaults to cert-manager | ||
// +usage=Namespace to deploy to, defaults to cert-manager | ||
namespace: *"trivy-system" | string | ||
|
||
// +usage=Specify image including image repository address and image name to use for the trivy-operator | ||
"repository": *"devopstales/trivy-operator" | string | ||
|
||
// +usage=Specify image tag to use for the trivy-operator | ||
"tag": *"2.4.1" | string | ||
|
||
// +usage=Specify if persistent storage (pv) is enabled or not, no persistent storage when false | ||
"enabled": *false | bool | ||
|
||
// +usage=Specify the crontab for trivy-operator to scanning image in labled namespace | ||
"crontab": *"*/5 * * * *" | string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package main | ||
|
||
aquaTrivyHelm: { | ||
name: "aqua-trivy-system-helm" | ||
dependsOn: ["trivy-system-ns"] | ||
type: "helm" | ||
|
||
properties: { | ||
repoType: "helm" | ||
url: "https://aquasecurity.github.io/helm-charts" | ||
chart: "trivy-operator" | ||
version: "0.9.1" | ||
targetNamespace: parameter.namespace | ||
values: { | ||
trivy: ignoreUnfixed: true | ||
} | ||
} | ||
} |
Oops, something went wrong.