-
Notifications
You must be signed in to change notification settings - Fork 1
127 lines (114 loc) · 3.37 KB
/
scan.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
name: Vulnerability scan
on:
workflow_call:
inputs:
REGISTRY:
required: true
type: string
NAMESPACE:
required: true
type: string
TAG:
required: true
type: string
workflow_dispatch:
inputs:
REGISTRY:
description: Target registry to push images
required: true
type: string
default: ghcr.io
NAMESPACE:
description: Target namespace to the given registry
required: true
type: string
default: this-is-tobi/template-monorepo-ts
TAG:
description: Tag used to scan images
required: true
type: string
default: latest
permissions:
issues: write
jobs:
infos:
name: Generate infos
runs-on: ubuntu-latest
outputs:
build-matrix: ${{ steps.build-matrix.outputs.BUILD_MATRIX }}
steps:
- name: Checks-out repository
uses: actions/checkout@v4
- name: Generate matrix
id: build-matrix
run: |
echo "BUILD_MATRIX=$(jq -c . < ./ci/matrix/docker.json)" >> $GITHUB_OUTPUT
images-scan:
name: Scan images vulnerabilities
runs-on: ubuntu-latest
needs:
- infos
strategy:
matrix:
images: ${{ fromJSON(needs.infos.outputs.build-matrix) }}
steps:
- name: Checks-out repository
uses: actions/checkout@v4
- name: Set up Docker buildx
if: ${{ matrix.images.build != false }}
uses: docker/setup-buildx-action@v3
- name: Run Trivy vulnerability scanner on images
uses: aquasecurity/trivy-action@master
with:
image-ref: "${{ inputs.REGISTRY }}/${{ inputs.NAMESPACE }}/${{ matrix.images.name }}:${{ inputs.TAG }}"
format: template
template: "@/contrib/sarif.tpl"
vuln-type: "os,library"
ignore-unfixed: true
output: trivy-results.sarif
continue-on-error: true
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: trivy-results.sarif
continue-on-error: true
config-scan:
name: Scan config files vulnerabilities
runs-on: ubuntu-latest
needs:
- infos
steps:
- name: Checks-out repository
uses: actions/checkout@v4
- name: Run Trivy vulnerability scanner on config files
uses: aquasecurity/trivy-action@master
with:
scan-ref: .
scan-type: config
format: template
template: "@/contrib/sarif.tpl"
skip-dirs: "**/node_modules,ci"
ignore-unfixed: true
output: trivy-results.sarif
continue-on-error: true
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: trivy-results.sarif
continue-on-error: true
scan-notif:
name: Notify users
runs-on: ubuntu-latest
needs:
- infos
- images-scan
- config-scan
if: ${{ github.event_name == 'pull_request' }}
steps:
- name: Comment PR
uses: thollander/actions-comment-pull-request@v2
with:
message: |
🤖 Hey !
The security scan report for the current pull request is available [here](https://github.com/${{ github.repository }}/security/code-scanning?query=is%3Aopen+branch%3Amain+pr%3A${{ github.event.pull_request.number || github.event.number }}).
comment_tag: vuln-scan