@@ -127,6 +127,168 @@ jobs:
127
127
sarif_file : ' trivy-results.sarif'
128
128
` ` `
129
129
130
+ ### Using Trivy to scan your private registry
131
+ It's also possible to scan your private registry with Trivy's built-in image scan. All you have to do is set ENV vars.
132
+
133
+ #### Docker Hub registry
134
+ Docker Hub needs ` TRIVY_USERNAME` and `TRIVY_PASSWORD`.
135
+ You don't need to set ENV vars when downloading from a public repository.
136
+ ` ` ` yaml
137
+ name: build
138
+ on:
139
+ push:
140
+ branches:
141
+ - master
142
+ pull_request:
143
+ jobs:
144
+ build:
145
+ name: Build
146
+ runs-on: ubuntu-18.04
147
+ steps:
148
+ - name: Checkout code
149
+ uses: actions/checkout@v2
150
+
151
+ - name: Build an image from Dockerfile
152
+ run: |
153
+ docker build -t docker.io/my-organization/my-app:${{ github.sha }} .
154
+
155
+ - name: Run Trivy vulnerability scanner
156
+ uses: aquasecurity/trivy-action@master
157
+ with:
158
+ image-ref: 'docker.io/my-organization/my-app:${{ github.sha }}'
159
+ format: 'template'
160
+ template: '@/contrib/sarif.tpl'
161
+ output: 'trivy-results.sarif'
162
+ env:
163
+ TRIVY_USERNAME: Username
164
+ TRIVY_PASSWORD: Password
165
+
166
+ - name: Upload Trivy scan results to GitHub Security tab
167
+ uses: github/codeql-action/upload-sarif@v1
168
+ with:
169
+ sarif_file: 'trivy-results.sarif'
170
+ ` ` `
171
+
172
+ # ### AWS ECR (Elastic Container Registry)
173
+ Trivy uses AWS SDK. You don't need to install `aws` CLI tool.
174
+ You can use [AWS CLI's ENV Vars][env-var].
175
+
176
+ [env-var] : https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html
177
+ ` ` ` yaml
178
+ name: build
179
+ on:
180
+ push:
181
+ branches:
182
+ - master
183
+ pull_request:
184
+ jobs:
185
+ build:
186
+ name: Build
187
+ runs-on: ubuntu-18.04
188
+ steps:
189
+ - name: Checkout code
190
+ uses: actions/checkout@v2
191
+
192
+ - name: Build an image from Dockerfile
193
+ run: |
194
+ docker build -t docker.io/my-organization/my-app:${{ github.sha }} .
195
+
196
+ - name: Run Trivy vulnerability scanner
197
+ uses: aquasecurity/trivy-action@master
198
+ with:
199
+ image-ref: 'docker.io/my-organization/my-app:${{ github.sha }}'
200
+ format: 'template'
201
+ template: '@/contrib/sarif.tpl'
202
+ output: 'trivy-results.sarif'
203
+ env:
204
+ AWS_ACCESS_KEY_ID: key_id
205
+ AWS_SECRET_ACCESS_KEY: access_key
206
+ AWS_DEFAULT_REGION: us-west-2
207
+
208
+ - name: Upload Trivy scan results to GitHub Security tab
209
+ uses: github/codeql-action/upload-sarif@v1
210
+ with:
211
+ sarif_file: 'trivy-results.sarif'
212
+ ` ` `
213
+
214
+ # ### GCR (Google Container Registry)
215
+ Trivy uses Google Cloud SDK. You don't need to install `gcloud` command.
216
+
217
+ If you want to use target project's repository, you can set it via `GOOGLE_APPLICATION_CREDENTIAL`.
218
+ ` ` ` yaml
219
+ name: build
220
+ on:
221
+ push:
222
+ branches:
223
+ - master
224
+ pull_request:
225
+ jobs:
226
+ build:
227
+ name: Build
228
+ runs-on: ubuntu-18.04
229
+ steps:
230
+ - name: Checkout code
231
+ uses: actions/checkout@v2
232
+
233
+ - name: Build an image from Dockerfile
234
+ run: |
235
+ docker build -t docker.io/my-organization/my-app:${{ github.sha }} .
236
+
237
+ - name: Run Trivy vulnerability scanner
238
+ uses: aquasecurity/trivy-action@master
239
+ with:
240
+ image-ref: 'docker.io/my-organization/my-app:${{ github.sha }}'
241
+ format: 'template'
242
+ template: '@/contrib/sarif.tpl'
243
+ output: 'trivy-results.sarif'
244
+ env:
245
+ GOOGLE_APPLICATION_CREDENTIAL: /path/to/credential.json
246
+
247
+ - name: Upload Trivy scan results to GitHub Security tab
248
+ uses: github/codeql-action/upload-sarif@v1
249
+ with:
250
+ sarif_file: 'trivy-results.sarif'
251
+ ` ` `
252
+
253
+ # ### Self-Hosted
254
+ BasicAuth server needs `TRIVY_USERNAME` and `TRIVY_PASSWORD`.
255
+ if you want to use 80 port, use NonSSL `TRIVY_NON_SSL=true`
256
+ ` ` ` yaml
257
+ name: build
258
+ on:
259
+ push:
260
+ branches:
261
+ - master
262
+ pull_request:
263
+ jobs:
264
+ build:
265
+ name: Build
266
+ runs-on: ubuntu-18.04
267
+ steps:
268
+ - name: Checkout code
269
+ uses: actions/checkout@v2
270
+
271
+ - name: Build an image from Dockerfile
272
+ run: |
273
+ docker build -t docker.io/my-organization/my-app:${{ github.sha }} .
274
+
275
+ - name: Run Trivy vulnerability scanner
276
+ uses: aquasecurity/trivy-action@master
277
+ with:
278
+ image-ref: 'docker.io/my-organization/my-app:${{ github.sha }}'
279
+ format: 'template'
280
+ template: '@/contrib/sarif.tpl'
281
+ output: 'trivy-results.sarif'
282
+ env:
283
+ TRIVY_USERNAME: Username
284
+ TRIVY_PASSWORD: Password
285
+
286
+ - name: Upload Trivy scan results to GitHub Security tab
287
+ uses: github/codeql-action/upload-sarif@v1
288
+ with:
289
+ sarif_file: 'trivy-results.sarif'
290
+ ` ` `
291
+
130
292
# # Customizing
131
293
132
294
# ## inputs
0 commit comments