Skip to content

Commit bc66678

Browse files
committed
Add daily check for vulnerability issues using Trivy
1 parent 3f93529 commit bc66678

File tree

4 files changed

+101
-3
lines changed

4 files changed

+101
-3
lines changed

.github/workflows/build-notebooks-TEMPLATE.yaml

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ jobs:
4343
4444
df -h
4545
46+
sudo apt-get update
47+
sudo apt-get remove -y '^dotnet-.*'
48+
sudo apt-get remove -y '^llvm-.*'
49+
sudo apt-get remove -y 'php.*'
50+
sudo apt-get remove -y '^mongodb-.*'
51+
sudo apt-get autoremove -y
52+
sudo apt-get clean
53+
sudo rm -rf /usr/local/.ghcup &
4654
sudo rm -rf /usr/local/lib/android &
4755
sudo rm -rf /usr/local/share/boost &
4856
sudo rm -rf /usr/local/lib/node_modules &
@@ -96,14 +104,40 @@ jobs:
96104
mkdir -p $HOME/.local/share/containers/storage/tmp
97105
98106
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#push
99-
- name: "push: make ${{ inputs.target }}"
107+
- name: "push|schedule: make ${{ inputs.target }}"
100108
run: "make ${{ inputs.target }}"
101-
if: "${{ fromJson(inputs.github).event_name == 'push' }}"
109+
if: ${{ fromJson(inputs.github).event_name == 'push' || fromJson(inputs.github).event_name == 'schedule' }}
102110
env:
103111
IMAGE_TAG: "${{ github.ref_name }}_${{ github.sha }}"
104112
IMAGE_REGISTRY: "ghcr.io/${{ github.repository }}/workbench-images"
105113
CONTAINER_BUILD_CACHE_ARGS: "--cache-from ${{ env.CACHE }} --cache-to ${{ env.CACHE }}"
106114

115+
- name: "schedule: run Trivy vulnerability scanner"
116+
if: "${{ fromJson(inputs.github).event_name == 'schedule' }}"
117+
run: |
118+
TRIVY_VERSION=0.52.2
119+
REPORT_FOLDER=${{ github.workspace }}/report
120+
REPORT_FILE=trivy-report.md
121+
REPORT_TEMPLATE=trivy-markdown.tpl
122+
123+
mkdir -p $REPORT_FOLDER
124+
cp ci/$REPORT_TEMPLATE $REPORT_FOLDER
125+
126+
IMAGE_NAME=ghcr.io/${{ github.repository }}/workbench-images:${{ inputs.target }}-${{ github.ref_name }}_${{ github.sha }}
127+
echo "Scanning $IMAGE_NAME"
128+
129+
podman run --rm \
130+
-v $REPORT_FOLDER:/report \
131+
docker.io/aquasec/trivy:$TRIVY_VERSION \
132+
image \
133+
--scanners vuln,secret \
134+
--exit-code 0 --timeout 30m \
135+
--severity CRITICAL,HIGH \
136+
--format template --template "@/report/$REPORT_TEMPLATE" -o /report/$REPORT_FILE \
137+
$IMAGE_NAME
138+
139+
cat $REPORT_FOLDER/$REPORT_FILE >> $GITHUB_STEP_SUMMARY
140+
107141
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request
108142
- name: "pull_request: make ${{ inputs.target }}"
109143
run: |

.github/workflows/build-notebooks.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
},
88
"on": {
99
"push": {},
10-
"workflow_dispatch": {}
10+
"workflow_dispatch": {},
11+
"schedule": [
12+
{
13+
"cron": "0 2 * * *"
14+
}
15+
]
1116
},
1217
"jobs": {
1318
"base-ubi8-python-3_8": {

ci/cached-builds/gen_gha_matrix_jobs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ def write_github_workflow_file(tree: dict[str, list[str]], path: pathlib.Path) -
106106
"on": {
107107
"push": {},
108108
"workflow_dispatch": {},
109+
"schedule": [{ "cron": "0 2 * * *"}], # 2am UTC everyday
109110
},
110111
"jobs": jobs,
111112
}

ci/trivy-markdown.tpl

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
## Vulnerability Report by [Trivy](https://trivy.dev)
2+
3+
<details>
4+
{{- if . }}
5+
{{- range . }}
6+
{{- if or (gt (len .Vulnerabilities) 0) (gt (len .Misconfigurations) 0) }}
7+
<h3>Target: <code>{{- if and (eq .Class "os-pkgs") .Type }}{{ .Type | toString | escapeXML }} ({{ .Class | toString | escapeXML }}){{- else }}{{ .Target | toString | escapeXML }}{{ if .Type }} ({{ .Type | toString | escapeXML }}){{ end }}{{- end }}</code></h3>
8+
{{- if (gt (len .Vulnerabilities) 0) }}
9+
<h4>Vulnerabilities ({{ len .Vulnerabilities }})</h4>
10+
<table>
11+
<tr>
12+
<th>Package</th>
13+
<th>ID</th>
14+
<th>Severity</th>
15+
<th>Installed Version</th>
16+
<th>Fixed Version</th>
17+
</tr>
18+
{{- range .Vulnerabilities }}
19+
<tr>
20+
<td><code>{{ escapeXML .PkgName }}</code></td>
21+
<td>{{ escapeXML .VulnerabilityID }}</td>
22+
<td>{{ escapeXML .Severity }}</td>
23+
<td>{{ escapeXML .InstalledVersion }}</td>
24+
<td>{{ escapeXML .FixedVersion }}</td>
25+
</tr>
26+
{{- end }}
27+
</table>
28+
{{- end }}
29+
{{- if (gt (len .Misconfigurations ) 0) }}
30+
<h4>Misconfigurations</h4>
31+
<table>
32+
<tr>
33+
<th>Type</th>
34+
<th>ID</th>
35+
<th>Check</th>
36+
<th>Severity</th>
37+
<th>Message</th>
38+
</tr>
39+
{{- range .Misconfigurations }}
40+
<tr>
41+
<td>{{ escapeXML .Type }}</td>
42+
<td>{{ escapeXML .ID }}</td>
43+
<td>{{ escapeXML .Title }}</td>
44+
<td>{{ escapeXML .Severity }}</td>
45+
<td>
46+
{{ escapeXML .Message }}
47+
<br><a href={{ escapeXML .PrimaryURL | printf "%q" }}>{{ escapeXML .PrimaryURL }}</a></br>
48+
</td>
49+
</tr>
50+
{{- end }}
51+
</table>
52+
{{- end }}
53+
{{- end }}
54+
{{- end }}
55+
{{- else }}
56+
<h3>Empty report</h3>
57+
{{- end }}
58+
</details>

0 commit comments

Comments
 (0)