Skip to content

Commit f44e790

Browse files
authored
Merge pull request #8776 from strongjz/ci-unit-test
Trivy Image Scanning
2 parents 0f61d9d + ead3c2b commit f44e790

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed
+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# This workflow uses actions that are not certified by GitHub.
2+
# They are provided by a third-party and are governed by
3+
# separate terms of service, privacy policy, and support
4+
# documentation.
5+
6+
name: Vulnerability Scan
7+
8+
on:
9+
workflow_dispatch:
10+
release:
11+
schedule:
12+
- cron: '00 9 * * 1'
13+
14+
permissions:
15+
contents: read
16+
security-events: write
17+
18+
jobs:
19+
version:
20+
runs-on: ubuntu-latest
21+
outputs:
22+
versions: ${{ steps.version.outputs.TAGS }}
23+
steps:
24+
- name: Checkout code
25+
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b
26+
with:
27+
fetch-depth: 0
28+
29+
- name: Latest Tag
30+
id: version
31+
shell: bash
32+
run: |
33+
readarray -t TAGS_ARRAY <<<"$(git tag --list 'controller-v*.*.*' --sort=-version:refname | grep -v 'beta\|alpha')"
34+
FULL_TAGS=(${TAGS_ARRAY[0]} ${TAGS_ARRAY[1]} ${TAGS_ARRAY[2]})
35+
SHORT_TAGS=()
36+
for i in ${FULL_TAGS[@]}
37+
do
38+
echo "tag: $i"
39+
short=$(echo "$i" | cut -d - -f 2)
40+
SHORT_TAGS+=($short)
41+
done
42+
echo "${SHORT_TAGS[0]},${SHORT_TAGS[1]},${SHORT_TAGS[2]}"
43+
TAGS_JSON="[\"${SHORT_TAGS[0]}\",\"${SHORT_TAGS[1]}\",\"${SHORT_TAGS[2]}\"]"
44+
echo "${TAGS_JSON}"
45+
echo "::set-output name=TAGS::${TAGS_JSON}"
46+
47+
scan:
48+
runs-on: ubuntu-latest
49+
needs: version
50+
strategy:
51+
matrix:
52+
versions: ${{ fromJSON(needs.version.outputs.versions) }}
53+
steps:
54+
- name: Checkout code
55+
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b
56+
57+
- shell: bash
58+
id: test
59+
run: echo "Scanning registry.k8s.io/ingress-nginx/controller@${{ matrix.versions }}"
60+
61+
- name: Scan image with AquaSec/Trivy
62+
id: scan
63+
uses: aquasecurity/trivy-action@0105373003c89c494a3f436bd5efc57f3ac1ca20 #v0.5.1
64+
with:
65+
image-ref: registry.k8s.io/ingress-nginx/controller:${{ matrix.versions }}
66+
format: 'sarif'
67+
output: trivy-results-${{ matrix.versions }}.sarif
68+
exit-code: 0
69+
vuln-type: 'os,library'
70+
severity: 'CRITICAL,HIGH,MEDIUM,LOW,UNKNOWN'
71+
72+
- name: Output Sarif File
73+
shell: bash
74+
run: cat ${{ github.workspace }}/trivy-results-${{ matrix.versions }}.sarif
75+
76+
# This step checks out a copy of your repository.
77+
- name: Upload SARIF file
78+
uses: github/codeql-action/upload-sarif@0c670bbf0414f39666df6ce8e718ec5662c21e03
79+
with:
80+
token: ${{ github.token }}
81+
# Path to SARIF file relative to the root of the repository
82+
sarif_file: ${{ github.workspace }}/trivy-results-${{ matrix.versions }}.sarif
83+
84+
- name: Vulz Count
85+
shell: bash
86+
run: |
87+
TRIVY_COUNT=$(cat ${{ github.workspace }}/trivy-results-${{ matrix.versions }}.sarif | jq '.runs[0].results | length')
88+
echo "TRIVY_COUNT: $TRIVY_COUNT"
89+
echo "Image Vulnerability scan output" >> $GITHUB_STEP_SUMMARY
90+
echo "Image ID: registry.k8s.io/ingress-nginx/controller@${{ matrix.versions }}" >> $GITHUB_STEP_SUMMARY
91+
echo "" >> $GITHUB_STEP_SUMMARY
92+
echo "Trivy Count: $TRIVY_COUNT" >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)