Skip to content

Commit b1a0e55

Browse files
committed
GitHub Advanced Security container scanning with 3rdparty integrations
1 parent 7901792 commit b1a0e55

File tree

5 files changed

+163
-2
lines changed

5 files changed

+163
-2
lines changed

.github/workflows/anchore.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# This workflow uses actions that are not certified by GitHub.
2+
# They are provided by a third-party and are governed by
3+
# separate terms of service, privacy policy, and support
4+
# documentation.
5+
6+
# This workflow checks out code, builds an image, performs a container image
7+
# vulnerability scan with Anchore's Grype tool, and integrates the results with GitHub Advanced Security
8+
# code scanning feature. For more information on the Anchore scan action usage
9+
# and parameters, see https://github.com/anchore/scan-action. For more
10+
# information on Anchore's container image scanning tool Grype, see
11+
# https://github.com/anchore/grype
12+
name: Anchore Grype vulnerability scan
13+
14+
on:
15+
push:
16+
branches: [ "main" ]
17+
pull_request:
18+
# The branches below must be a subset of the branches above
19+
branches: [ "main" ]
20+
schedule:
21+
- cron: '30 4 * * 3'
22+
23+
permissions:
24+
contents: read
25+
26+
jobs:
27+
Anchore-Build-Scan:
28+
permissions:
29+
contents: read # for actions/checkout to fetch code
30+
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
31+
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
32+
runs-on: ubuntu-latest
33+
steps:
34+
- name: Check out the code
35+
uses: actions/checkout@v3
36+
- name: Build the Docker image
37+
run: docker build . --file Dockerfile --tag localbuild/testimage:latest
38+
- name: Run the Anchore Grype scan action
39+
uses: anchore/scan-action@d5aa5b6cb9414b0c7771438046ff5bcfa2854ed7
40+
id: scan
41+
with:
42+
image: "localbuild/testimage:latest"
43+
fail-build: false
44+
severity-cutoff: critical
45+
- name: Upload vulnerability report
46+
uses: github/codeql-action/upload-sarif@v2
47+
with:
48+
sarif_file: ${{ steps.scan.outputs.sarif }}

.github/workflows/tfsec.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# This workflow uses actions that are not certified by GitHub.
2+
# They are provided by a third-party and are governed by
3+
# separate terms of service, privacy policy, and support
4+
# documentation.
5+
6+
name: tfsec
7+
8+
on:
9+
push:
10+
branches: [ "main" ]
11+
pull_request:
12+
branches: [ "main" ]
13+
schedule:
14+
- cron: '44 10 * * 4'
15+
16+
jobs:
17+
tfsec:
18+
name: Run tfsec sarif report
19+
runs-on: ubuntu-latest
20+
permissions:
21+
actions: read
22+
contents: read
23+
security-events: write
24+
25+
steps:
26+
- name: Clone repo
27+
uses: actions/checkout@v3
28+
29+
- name: Run tfsec
30+
uses: aquasecurity/tfsec-sarif-action@9a83b5c3524f825c020e356335855741fd02745f
31+
with:
32+
sarif_file: tfsec.sarif
33+
34+
- name: Upload SARIF file
35+
uses: github/codeql-action/upload-sarif@v2
36+
with:
37+
# Path to SARIF file relative to the root of the repository
38+
sarif_file: tfsec.sarif

.github/workflows/trivy.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# This workflow uses actions that are not certified by GitHub.
2+
# They are provided by a third-party and are governed by
3+
# separate terms of service, privacy policy, and support
4+
# documentation.
5+
6+
name: build
7+
8+
on:
9+
push:
10+
branches: [ "main" ]
11+
pull_request:
12+
# The branches below must be a subset of the branches above
13+
branches: [ "main" ]
14+
schedule:
15+
- cron: '37 14 * * 2'
16+
17+
permissions:
18+
contents: read
19+
20+
jobs:
21+
build:
22+
permissions:
23+
contents: read # for actions/checkout to fetch code
24+
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
25+
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
26+
name: Build
27+
runs-on: "ubuntu-20.04"
28+
steps:
29+
- name: Checkout code
30+
uses: actions/checkout@v3
31+
32+
- name: Build an image from Dockerfile
33+
run: |
34+
docker build -t docker.io/my-organization/my-app:${{ github.sha }} .
35+
36+
- name: Run Trivy vulnerability scanner
37+
uses: aquasecurity/trivy-action@7b7aa264d83dc58691451798b4d117d53d21edfe
38+
with:
39+
image-ref: 'docker.io/my-organization/my-app:${{ github.sha }}'
40+
format: 'template'
41+
template: '@/contrib/sarif.tpl'
42+
output: 'trivy-results.sarif'
43+
severity: 'CRITICAL,HIGH'
44+
45+
- name: Upload Trivy scan results to GitHub Security tab
46+
uses: github/codeql-action/upload-sarif@v2
47+
with:
48+
sarif_file: 'trivy-results.sarif'

Dockerfile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# a really old, vulnerable nodejs base image, using Debian 8
2+
FROM vaikas/nodejsservice
3+
4+
# some metadata so we can correlate the image with the source
5+
LABEL org.opencontainers.image.source = "https://github.com/aegilops/testing-container-security"
6+
LABEL org.opencontainers.image.path "Dockerfile"
7+
LABEL org.opencontainers.image.title "testing-container-security"
8+
LABEL org.opencontainers.image.description "A very old base nodejs image"
9+
LABEL org.opencontainers.image.authors "@aegilops"
10+
LABEL org.opencontainers.image.licenses "Copyright GitHub (C) 2023"
11+
LABEL org.opencontainers.image.documentation https://github.com/aegilops/testing-container-security/README.md
12+
13+
# Runner user
14+
RUN adduser --disabled-password --gecos "" --uid 1000 runner
15+
16+
# Make and set the working directory
17+
RUN mkdir -p /test \
18+
&& chown -R $USERNAME:$GID /test
19+
20+
WORKDIR /test
21+
22+
USER runner
23+
24+
# and that's it, this image doesn't really need to do anything

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
# Docker_Container_3rdParty_Example
2-
Code Scanning on dockerfile container
1+
# testing-container-security
2+
3+
A `Dockerfile` using a really old and vulnerable base image, to test out container security tools.
4+
5+
I chose it based on [Security Issues in Popular Containers](https://containers.goodwith.tech/).

0 commit comments

Comments
 (0)