-
Notifications
You must be signed in to change notification settings - Fork 75
164 lines (145 loc) · 6.29 KB
/
trivy.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
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
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
name: Vulnerability Scanning
on:
workflow_dispatch:
push:
branches: [ "main" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "main" ]
schedule:
- cron: '0 7 * * 1-5' # Run every weekday at 7am UTC
permissions:
contents: read
jobs:
trivy:
strategy:
fail-fast: false
matrix:
image: [
{dockerfile: Dockerfile, name: liquibase/liquibase, suffix: ""},
{dockerfile: Dockerfile.alpine, name: liquibase/liquibase, suffix: "-alpine"},
]
permissions:
contents: read # for actions/checkout to fetch code
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
name: Trivy
runs-on: "ubuntu-22.04"
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Build ${{ matrix.image.name }}${{ matrix.image.suffix }} from Dockerfile
run: |
docker build -f ${{ matrix.image.dockerfile }} -t ${{ matrix.image.name }}${{ matrix.image.suffix }}:${{ github.sha }} .
- name: Run Trivy vulnerability scanner
uses: aquasecurity/[email protected]
with:
image-ref: '${{ matrix.image.name }}${{ matrix.image.suffix }}:${{ github.sha }}'
vuln-type: 'os,library'
format: 'sarif'
output: 'trivy-results.sarif'
severity: 'HIGH,CRITICAL'
exit-code: '1'
limit-severities-for-sarif: true
- name: Notify Slack on Build Failure
if: failure()
uses: rtCamp/action-slack-notify@v2
env:
SLACK_COLOR: 'failure'
SLACK_MESSAGE: "View details on GitHub Actions: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}. Triggered by repository: ${{ github.repository }} and job: ${{ github.job }}"
SLACK_TITLE: "❌ ${{ github.repository }} ❌ Trivy failed on branch ${{ github.ref_name }} for commit ${{ github.sha }} in repository ${{ github.repository }}"
SLACK_USERNAME: liquibot
SLACK_WEBHOOK: ${{ secrets.DOCKER_SLACK_WEBHOOK_URL }}
SLACK_ICON_EMOJI: ":whale:"
SLACK_FOOTER: "${{ github.repository }} - ${{ matrix.image.name }}${{ matrix.image.suffix }}:${{ github.sha }}"
SLACK_LINK_NAMES: true
- name: Upload Trivy scan results to GitHub Security tab
if: always()
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: 'trivy-results.sarif'
category: '${{ matrix.image.name }}${{ matrix.image.suffix }}'
- name: Generate Security Report
if: always()
uses: rsdmike/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
outputDir: ./reports/
sarifReportDir: .
- name: Upload Security Report
if: always()
uses: actions/upload-artifact@v3
with:
name: security-report-trivy
path: ./reports/summary.pdf
scout:
strategy:
fail-fast: false
matrix:
image: [
{dockerfile: Dockerfile, name: liquibase/liquibase, suffix: ""},
{dockerfile: Dockerfile.alpine, name: liquibase/liquibase, suffix: "-alpine"},
]
permissions:
contents: read # for actions/checkout to fetch code
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
pull-requests: write # for docker/scout-action to write comments on pull requests
name: Scout
runs-on: "ubuntu-22.04"
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Build ${{ matrix.image.name }}${{ matrix.image.suffix }} from Dockerfile
run: |
docker build -f ${{ matrix.image.dockerfile }} -t ${{ matrix.image.name }}${{ matrix.image.suffix }}:${{ github.sha }} .
- uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Docker Scout
uses: docker/[email protected]
with:
command: cves
image: '${{ matrix.image.name }}${{ matrix.image.suffix }}:${{ github.sha }}'
github-token: ${{ secrets.GITHUB_TOKEN }}
write-comment: true
sarif-file: 'scout-results.sarif'
summary: true
exit-code: true
only-severities: "critical,high"
- name: Notify Slack on Build Failure
if: failure()
uses: rtCamp/action-slack-notify@v2
env:
SLACK_COLOR: 'failure'
SLACK_MESSAGE: "View details on GitHub Actions: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}. Triggered by repository: ${{ github.repository }} and job: ${{ github.job }}"
SLACK_TITLE: "❌ ${{ github.repository }} ❌ Docker Scout failed on branch ${{ github.ref_name }} for commit ${{ github.sha }} in repository ${{ github.repository }}"
SLACK_USERNAME: liquibot
SLACK_WEBHOOK: ${{ secrets.DOCKER_SLACK_WEBHOOK_URL }}
SLACK_ICON_EMOJI: ":whale:"
SLACK_FOOTER: "${{ github.repository }} - ${{ matrix.image.name }}${{ matrix.image.suffix }}:${{ github.sha }}"
SLACK_LINK_NAMES: true
- name: Upload Scout scan results to GitHub Security tab
if: always()
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: 'scout-results.sarif'
category: '${{ matrix.image.name }}${{ matrix.image.suffix }}'
- name: Generate Security Report
if: always()
uses: rsdmike/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
outputDir: ./reports/
sarifReportDir: .
- name: Upload Security Report
if: always()
uses: actions/upload-artifact@v3
with:
name: security-report-scout
path: ./reports/summary.pdf