Skip to content

Commit 70e2aad

Browse files
committed
Add GitHub Actions workflows for Anchore Grype, Trivy, and Dependency Review scans
1 parent a6f81b7 commit 70e2aad

File tree

3 files changed

+129
-0
lines changed

3 files changed

+129
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# https://github.com/anchore/grype
2+
# https://github.com/anchore/scan-action
3+
4+
name: Anchore Grype Vulnerability Scan (Container Image Scanning)
5+
6+
on:
7+
push:
8+
branches: [main]
9+
pull_request:
10+
branches: [main]
11+
schedule:
12+
- cron: 0 1 * * 0
13+
14+
env:
15+
fail-build: false # Set to true to fail the build if vulnerabilities are found
16+
imageName: "webapp01"
17+
tag: ${{ github.sha }}
18+
19+
jobs:
20+
anchore-grype-scan:
21+
name: Anchore Grype Vulnerability Scan
22+
23+
runs-on: ubuntu-latest
24+
25+
permissions:
26+
contents: read # for actions/checkout to fetch code
27+
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
28+
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
29+
30+
steps:
31+
- name: Checkout code
32+
uses: actions/checkout@v4
33+
34+
- name: Build an image from Dockerfile
35+
uses: docker/build-push-action@v4
36+
with:
37+
tags: "${{ env.imageName }}:${{ env.tag }}"
38+
push: false
39+
load: true
40+
41+
- name: Run the Anchore Grype scan action
42+
uses: anchore/scan-action@v6
43+
id: scan
44+
with:
45+
image: "${{ env.imageName }}:${{ env.tag }}"
46+
fail-build: ${{ env.fail-build }}
47+
severity-cutoff: critical
48+
49+
- name: Upload Anchore vulnerability report to GitHub Security tab
50+
uses: github/codeql-action/upload-sarif@v3
51+
with:
52+
sarif_file: ${{ steps.scan.outputs.sarif }}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# https://trivy.dev/latest/
2+
# https://github.com/aquasecurity/trivy
3+
# https://github.com/aquasecurity/trivy-action
4+
5+
name: Trivy Container Image Scanning
6+
7+
on:
8+
push:
9+
branches: [main]
10+
pull_request:
11+
branches: [main]
12+
schedule:
13+
- cron: 0 1 * * 0
14+
15+
env:
16+
imageName: "webapp01"
17+
tag: ${{ github.sha }}
18+
19+
jobs:
20+
trivy:
21+
name: Trivy vulnerability scanner
22+
23+
runs-on: ubuntu-latest
24+
25+
permissions:
26+
contents: read # for actions/checkout to fetch code
27+
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
28+
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
29+
30+
steps:
31+
- name: Checkout code
32+
uses: actions/checkout@v4
33+
34+
- name: Build an image from Dockerfile
35+
run: |
36+
docker build ./src/webapp01 --file ./src/webapp01/Dockerfile --tag ${{ env.imageName }}:${{ env.tag }}
37+
38+
- name: Run Trivy vulnerability scanner
39+
uses: aquasecurity/trivy-action@0.29.0
40+
with:
41+
image-ref: "${{ env.imageName }}:${{ env.tag }}"
42+
format: "sarif"
43+
output: "trivy-results.sarif"
44+
45+
- name: Upload Trivy scan results to GitHub Security tab
46+
uses: github/codeql-action/upload-sarif@v3
47+
if: always()
48+
with:
49+
sarif_file: "trivy-results.sarif"
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Source repository: https://github.com/actions/dependency-review-action
2+
# Public documentation: https://docs.github.com/en/code-security/supply-chain-security/understanding-your-software-supply-chain/about-dependency-review#dependency-review-enforcement
3+
4+
name: 'SCA - Dependency Review'
5+
6+
on:
7+
pull_request:
8+
branches: [ "main" ]
9+
10+
permissions:
11+
contents: read
12+
# Write permissions for pull-requests are required for using the `comment-summary-in-pr` option, comment out if you aren't using this option
13+
pull-requests: write
14+
15+
jobs:
16+
dependency-review:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: 'Checkout repository'
20+
uses: actions/checkout@v4
21+
- name: 'Dependency Review'
22+
uses: actions/dependency-review-action@v4
23+
# Commonly enabled options, see https://github.com/actions/dependency-review-action#configuration-options for all available options.
24+
with:
25+
comment-summary-in-pr: always
26+
fail-on-severity: 'moderate'
27+
allow-licenses: MIT, Apache-2.0
28+

0 commit comments

Comments
 (0)