-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtrivy.yaml
More file actions
251 lines (237 loc) · 10.1 KB
/
Copy pathtrivy.yaml
File metadata and controls
251 lines (237 loc) · 10.1 KB
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
version: 2.1
description: |
Run trivy and report errors by email
display:
home_url: https://github.com/donkeycode/circle-orbs
source_url: https://github.com/donkeycode/circle-orbs
orbs:
docker: donkeycode/docker@0.0.27
utils: donkeycode/utils@0.0.5
commands:
install:
description: |
Install trivy
steps:
- run:
command: |
curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin v0.18.3
name: Install trivy
scan:
description: |
This command will scan images
parameters:
files:
description: List of files to scan
type: string
images:
description: List of images to scan
type: string
steps:
- utils/install_bash
- run:
command: |-
cat \<<EOF > ~/project/.circleci/top.tpl
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style>
* {
font-family: Arial, Helvetica, sans-serif;
}
h1 {
text-align: center;
}
.group-header th {
font-size: 200%;
}
.sub-header th {
font-size: 150%;
}
table, th, td {
border: 1px solid black;
border-collapse: collapse;
white-space: nowrap;
padding: .3em;
}
table {
margin: 0 auto;
}
.severity {
text-align: center;
font-weight: bold;
color: #fafafa;
}
.severity-LOW .severity { background-color: #5fbb31; }
.severity-MEDIUM .severity { background-color: #e9c600; }
.severity-HIGH .severity { background-color: #ff8800; }
.severity-CRITICAL .severity { background-color: #e40000; }
.severity-UNKNOWN .severity { background-color: #747474; }
.severity-LOW { background-color: #5fbb3160; }
.severity-MEDIUM { background-color: #e9c60060; }
.severity-HIGH { background-color: #ff880060; }
.severity-CRITICAL { background-color: #e4000060; }
.severity-UNKNOWN { background-color: #74747460; }
table tr td:first-of-type {
font-weight: bold;
}
.links a,
.links[data-more-links=on] a {
display: block;
}
.links[data-more-links=off] a:nth-of-type(1n+5) {
display: none;
}
a.toggle-more-links { cursor: pointer; }
</style>
<title>{{- escapeXML ( index . 0 ).Target }} - Trivy Report - {{ now }} </title>
</head>
<body>
<p>Bonjour,</p>
<p>Nous venons de procéder au scan de sécurité de votre projet,<br /> N'hésitez pas à contacter support@donkeycode.com pour planifier les corrections</p>
EOF
cat \<<EOF > ~/project/.circleci/footer.tpl
</body>
</html>
EOF
cat \<<EOF > ~/project/.circleci/scan_images.tpl
{{- if . }}
<table>
{{- range . }}
<tr class="group-header"><th colspan="6">{{ escapeXML .Type }}</th></tr>
{{- if (eq (len .Vulnerabilities) 0) }}
<tr><th colspan="6">No Vulnerabilities found</th></tr>
{{- else }}
<tr class="sub-header">
<th>Package</th>
<th>Vulnerability ID</th>
<th>Severity</th>
<th>Installed Version</th>
<th>Fixed Version</th>
<th>Links</th>
</tr>
{{- range .Vulnerabilities }}
<tr class="severity-{{ escapeXML .Vulnerability.Severity }}">
<td class="pkg-name">{{ escapeXML .PkgName }}</td>
<td>{{ escapeXML .VulnerabilityID }}</td>
<td class="severity">{{ escapeXML .Vulnerability.Severity }}</td>
<td class="pkg-version">{{ escapeXML .InstalledVersion }}</td>
<td>{{ escapeXML .FixedVersion }}</td>
<td class="links" data-more-links="off">
{{- range .Vulnerability.References }}
<a href={{ escapeXML . | printf "%q" }}>{{ escapeXML . }}</a>
{{- end }}
</td>
</tr>
{{- end }}
{{- end }}
{{- end }}
</table>
{{- else }}
<p>Trivy Returned Empty Report</p>
{{- end }}
EOF
cat \<<EOF > ~/project/.circleci/scan_images.sh
#!/bin/bash
mkdir -p /reports/images
images=(${IMAGES})
INDEX=0
for image in "\${images[@]}"
do
docker pull \${image}
echo "<h2>\${image}</h2>" > /reports/images/\${INDEX}a.html
trivy image --format template --template "@/root/project/.circleci/scan_images.tpl" -o /reports/images/\${INDEX}b.html \${image}
let INDEX=\${INDEX}+1
done
files=(${FILES})
mkdir -p /reports/files
INDEX=0
for file in "\${files[@]}"
do
echo "<h2>\${file}</h2>" > /reports/files/\${INDEX}a.html
trivy fs --format template --template "@/root/project/.circleci/scan_images.tpl" -o /reports/files/\${INDEX}b.html \${file}
let INDEX=\${INDEX}+1
done
cat ~/project/.circleci/top.tpl > /email.html
echo "<h1>Images docker</h1>" >> /email.html
ls /reports/images/ | rev | cut -d " " -f 1 | rev | xargs -I {} cat /reports/images/{} >> /email.html
echo "<h1>Files</h1>" >> /email.html
ls /reports/files/ | rev | cut -d " " -f 1 | rev | xargs -I {} cat /reports/files/{} >> /email.html
cat ~/project/.circleci/footer.tpl >> /email.html
mv /email.html /reports/email.html
EOF
bash ~/project/.circleci/scan_images.sh
environment:
FILES: <<parameters.files>>
IMAGES: <<parameters.images>>
name: Scan images and files
- store_artifacts:
path: /reports
executors:
default:
description: |
Docker executor
docker:
- image: donkeycode/docker-with-compose
jobs:
scan:
description: |
Sample description
executor: default
parameters:
files:
description: List of files to scan
type: string
images:
description: List of images to scan
type: string
mail_from:
default: hosting@donkeycode.com
description: Mail from
type: string
mail_subject:
default: Security report
description: Mail subject
type: string
mail_to:
description: Mail Report To
type: string
use_ecr:
default: true
description: Set false to use standard docker login
type: boolean
steps:
- checkout
- setup_remote_docker:
docker_layer_caching: true
- when:
condition: <<parameters.use_ecr>>
steps:
- docker/ecr_login
- when:
condition:
not: <<parameters.use_ecr>>
steps:
- docker/login
- install
- scan:
files: <<parameters.files>>
images: <<parameters.images>>
- utils/mail:
body_file: /reports/email.html
from: <<parameters.mail_from>>
subject: <<parameters.mail_subject>>
to: <<parameters.mail_to>>
examples:
example:
description: |
Sample example description.
usage:
version: "2.1"
orbs:
trivy: donkeycode/trivy@0.0.1
workflows:
use-my-orb:
jobs:
- trivy/scan:
images: '"testorbs/api" "testorbs/front"'