Skip to content

Commit bd5fd4d

Browse files
committed
Add scheduled and on-demand Trivy image scan workflow
1 parent 1011c89 commit bd5fd4d

File tree

2 files changed

+65
-2
lines changed

2 files changed

+65
-2
lines changed

.github/workflows/docker-publish.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,29 +44,39 @@ jobs:
4444

4545
- name: Build image for scanning
4646
uses: docker/build-push-action@v6
47+
env:
48+
DOCKER_BUILD_CHECKS_ANNOTATIONS: false
49+
DOCKER_BUILD_SUMMARY: false
50+
DOCKER_BUILD_RECORD_UPLOAD: false
4751
with:
4852
context: docker
4953
load: true
5054
tags: ghcr.io/${{ github.repository }}:scan
5155

5256
- name: Scan image with Trivy
5357
id: trivy-scan
54-
uses: aquasecurity/trivy-action@master
58+
uses: aquasecurity/trivy-action@0.34.0
5559
with:
5660
image-ref: ghcr.io/${{ github.repository }}:scan
61+
ignore-unfixed: true
62+
scanners: vuln
5763
format: sarif
5864
output: trivy-results.sarif
5965
severity: CRITICAL,HIGH
6066
exit-code: '1'
6167

6268
- name: Upload Trivy scan results to GitHub Security
63-
uses: github/codeql-action/upload-sarif@v3
69+
uses: github/codeql-action/upload-sarif@v4
6470
if: always() && steps.trivy-scan.conclusion != 'skipped'
6571
with:
6672
sarif_file: trivy-results.sarif
6773

6874
- name: Build and push
6975
uses: docker/build-push-action@v6
76+
env:
77+
DOCKER_BUILD_CHECKS_ANNOTATIONS: true
78+
DOCKER_BUILD_SUMMARY: true
79+
DOCKER_BUILD_RECORD_UPLOAD: false
7080
with:
7181
context: docker
7282
platforms: linux/amd64,linux/arm64

.github/workflows/image-scan.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Image Security Scan
2+
run-name: Image Security Scan (${{ github.event_name == 'schedule' && 'latest' || github.ref_name }})
3+
4+
on:
5+
schedule:
6+
- cron: '0 0 1 * *'
7+
workflow_dispatch:
8+
9+
jobs:
10+
scan:
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
security-events: write
15+
16+
steps:
17+
- name: Checkout
18+
if: github.event_name == 'workflow_dispatch'
19+
uses: actions/checkout@v4
20+
21+
- name: Set up Docker Buildx
22+
if: github.event_name == 'workflow_dispatch'
23+
uses: docker/setup-buildx-action@v3
24+
25+
- name: Build image
26+
if: github.event_name == 'workflow_dispatch'
27+
uses: docker/build-push-action@v6
28+
env:
29+
DOCKER_BUILD_CHECKS_ANNOTATIONS: false
30+
DOCKER_BUILD_SUMMARY: false
31+
DOCKER_BUILD_RECORD_UPLOAD: false
32+
with:
33+
context: docker
34+
load: true
35+
tags: buildcage:scan
36+
37+
- name: Scan image with Trivy
38+
id: trivy-scan
39+
uses: aquasecurity/trivy-action@0.34.0
40+
with:
41+
image-ref: ${{ github.event_name == 'schedule' && format('ghcr.io/{0}:latest', github.repository) || 'buildcage:scan' }}
42+
ignore-unfixed: true
43+
scanners: vuln
44+
format: sarif
45+
output: trivy-results.sarif
46+
severity: CRITICAL,HIGH
47+
exit-code: '1'
48+
49+
- name: Upload Trivy scan results to GitHub Security
50+
uses: github/codeql-action/upload-sarif@v4
51+
if: always() && steps.trivy-scan.conclusion != 'skipped'
52+
with:
53+
sarif_file: trivy-results.sarif

0 commit comments

Comments
 (0)