Skip to content

Commit 646c3bd

Browse files
authored
Merge pull request #240 from cisagov/improvement/add_trivy_scanning
Scan the Docker image for vulnerabilities at build time
2 parents 00e680c + 8479455 commit 646c3bd

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

.github/dependabot.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ updates:
2929
# Managed by cisagov/skeleton-docker
3030
# - dependency-name: actions/download-artifact
3131
# - dependency-name: actions/upload-artifact
32+
# - dependency-name: aquasecurity/trivy-action
3233
# - dependency-name: docker/build-push-action
3334
# - dependency-name: docker/login-action
3435
# - dependency-name: docker/metadata-action

.github/workflows/build.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,54 @@ jobs:
362362
- name: Setup tmate debug session
363363
uses: mxschmitt/action-tmate@v3
364364
if: env.RUN_TMATE
365+
scan:
366+
name: Scan the image for vulnerabilities
367+
needs:
368+
- diagnostics
369+
- repo-metadata
370+
- build
371+
permissions:
372+
# actions/checkout needs this to fetch code
373+
contents: read
374+
runs-on: ubuntu-latest
375+
steps:
376+
- name: Apply standard cisagov job preamble
377+
uses: cisagov/action-job-preamble@v1
378+
with:
379+
# This functionality is poorly implemented and has been
380+
# causing problems due to the MITM implementation hogging or
381+
# leaking memory. As a result we disable it by default. If
382+
# you want to temporarily enable it, simply set
383+
# monitor_permissions equal to "true".
384+
#
385+
# TODO: Re-enable this functionality when practical. See
386+
# cisagov/skeleton-docker#224 for more details.
387+
monitor_permissions: "false"
388+
# Use a variable to specify the permissions monitoring
389+
# configuration. By default this will yield the
390+
# configuration stored in the cisagov organization-level
391+
# variable, but if you want to use a different configuration
392+
# then simply:
393+
# 1. Create a repository-level variable with the name
394+
# ACTIONS_PERMISSIONS_CONFIG.
395+
# 2. Set this new variable's value to the configuration you
396+
# want to use for this repository.
397+
#
398+
# Note in particular that changing the permissions
399+
# monitoring configuration *does not* require you to modify
400+
# this workflow.
401+
permissions_monitoring_config: ${{ vars.ACTIONS_PERMISSIONS_CONFIG }}
402+
- name: Download docker image artifact
403+
uses: actions/download-artifact@v4
404+
with:
405+
name: dist
406+
path: dist
407+
- name: Load docker image
408+
run: docker load < dist/image.tar.gz
409+
- name: Run Trivy vulnerability scanner
410+
uses: aquasecurity/trivy-action@0.32.0
411+
with:
412+
image-ref: ${{ needs.repo-metadata.outputs.image-name }}:latest
365413
test:
366414
# Executes tests on the single-platform image created in the "build" job.
367415
name: Test image
@@ -450,6 +498,7 @@ jobs:
450498
- lint
451499
- repo-metadata
452500
- prepare
501+
- scan
453502
- test
454503
permissions:
455504
# actions/checkout needs this to fetch code

trivy.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
# Fail if something is flagged
3+
exit-code: 1
4+
# Only flag critical and high vulnerabilities
5+
severity:
6+
- CRITICAL
7+
- HIGH

0 commit comments

Comments
 (0)