Skip to content

Commit 11fdd93

Browse files
Merge pull request #178 from DefGuard/sbom-into-main
Merge SBOM CI pipelines into main
2 parents 19e6fb7 + 57e898e commit 11fdd93

File tree

5 files changed

+136
-1
lines changed

5 files changed

+136
-1
lines changed

.github/workflows/build-docker.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ jobs:
6969
cache-to: type=gha,mode=max
7070

7171
- name: Scan image with Trivy
72-
uses: aquasecurity/trivy-action@0.32.0
72+
uses: aquasecurity/trivy-action@0.33.1
7373
with:
7474
image-ref: "${{ env.GHCR_REPO }}:${{ github.sha }}-${{ matrix.tag }}"
7575
format: "table"

.github/workflows/release.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ jobs:
5252
draft: true
5353
generate_release_notes: true
5454

55+
create-sbom:
56+
needs: [create-release, build-docker-release]
57+
uses: ./.github/workflows/sbom.yml
58+
with:
59+
upload_url: ${{ needs.create-release.outputs.upload_url }}
60+
5561
build-binaries:
5662
needs: [create-release]
5763
runs-on:
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Periodic SBOM Regeneration
2+
3+
on:
4+
schedule:
5+
- cron: '30 2 * * *' # 2:30 AM UTC
6+
7+
jobs:
8+
list-releases:
9+
name: List releases
10+
runs-on: ubuntu-latest
11+
outputs:
12+
releases: ${{ steps.get-releases.outputs.releases }}
13+
steps:
14+
- name: Get list of releases
15+
id: get-releases
16+
env:
17+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18+
run: |
19+
RELEASES_JSON=$(gh api repos/${{ github.repository }}/releases \
20+
--jq '[.[]
21+
| select(.draft == false and (.tag_name | test("^v[0-9]+\\.[0-9]+\\.[0-9]+$")))
22+
| {tagName: .tag_name, uploadUrl: .upload_url}][:1]')
23+
echo "releases=$RELEASES_JSON" >> $GITHUB_OUTPUT
24+
regenerate-for-release:
25+
name: Regenerate SBOM for release
26+
needs: list-releases
27+
# Don't run if no releases were found.
28+
if: needs.list-releases.outputs.releases != '[]'
29+
strategy:
30+
fail-fast: false
31+
matrix:
32+
release: ${{ fromJson(needs.list-releases.outputs.releases) }}
33+
uses: ./.github/workflows/sbom.yml
34+
with:
35+
upload_url: ${{ matrix.release.uploadUrl }}
36+
tag: ${{ matrix.release.tagName }}
37+
secrets: inherit

.github/workflows/sbom.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Create SBOM files
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
upload_url:
7+
description: "Release assets upload URL"
8+
required: true
9+
type: string
10+
tag:
11+
description: "The git tag to generate SBOM for - used in scheduled runs"
12+
required: false
13+
type: string
14+
15+
jobs:
16+
create-sbom:
17+
runs-on: [self-hosted, Linux, X64]
18+
19+
steps:
20+
- name: Determine release tag and version
21+
id: vars
22+
# Uses inputs.tag for scheduled runs, otherwise github.ref_name.
23+
run: |
24+
TAG_NAME=${{ inputs.tag || github.ref_name }}
25+
VERSION=${TAG_NAME#v}
26+
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_OUTPUT
27+
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
28+
29+
- name: Checkout
30+
uses: actions/checkout@v4
31+
with:
32+
ref: ${{ steps.vars.outputs.TAG_NAME }}
33+
submodules: recursive
34+
35+
- name: Create SBOM with Trivy
36+
uses: aquasecurity/trivy-action@0.33.1
37+
with:
38+
scan-type: 'fs'
39+
format: 'spdx-json'
40+
output: "defguard-proxy-${{ steps.vars.outputs.VERSION }}.sbom.json"
41+
scan-ref: '.'
42+
severity: "CRITICAL,HIGH,MEDIUM,LOW"
43+
scanners: "vuln"
44+
45+
- name: Create docker image SBOM with Trivy
46+
uses: aquasecurity/trivy-action@0.33.1
47+
with:
48+
image-ref: "ghcr.io/defguard/defguard-proxy:${{ steps.vars.outputs.VERSION }}"
49+
scan-type: 'image'
50+
format: 'spdx-json'
51+
output: "defguard-proxy-${{ steps.vars.outputs.VERSION }}-docker.sbom.json"
52+
severity: "CRITICAL,HIGH,MEDIUM,LOW"
53+
scanners: "vuln"
54+
55+
- name: Create security advisory file with Trivy
56+
uses: aquasecurity/trivy-action@0.33.1
57+
with:
58+
scan-type: 'fs'
59+
format: 'json'
60+
output: "defguard-proxy-${{ steps.vars.outputs.VERSION }}.advisories.json"
61+
scan-ref: '.'
62+
severity: "CRITICAL,HIGH,MEDIUM,LOW"
63+
scanners: "vuln"
64+
65+
- name: Create docker image security advisory file with Trivy
66+
uses: aquasecurity/trivy-action@0.33.1
67+
with:
68+
image-ref: "ghcr.io/defguard/defguard-proxy:${{ steps.vars.outputs.VERSION }}"
69+
scan-type: 'image'
70+
format: 'json'
71+
output: "defguard-proxy-${{ steps.vars.outputs.VERSION }}-docker.advisories.json"
72+
severity: "CRITICAL,HIGH,MEDIUM,LOW"
73+
scanners: "vuln"
74+
75+
- name: Upload SBOMs and advisories
76+
uses: shogo82148/actions-upload-release-asset@v1
77+
env:
78+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
79+
with:
80+
upload_url: ${{ inputs.upload_url }}
81+
asset_path: "defguard-*.json"
82+
asset_content_type: application/octet-stream
83+
overwrite: true

.github/workflows/test.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ jobs:
3434
uses: actions/checkout@v4
3535
with:
3636
submodules: recursive
37+
- name: Scan code with Trivy
38+
uses: aquasecurity/trivy-action@0.33.1
39+
with:
40+
scan-type: 'fs'
41+
scan-ref: '.'
42+
exit-code: "1"
43+
ignore-unfixed: true
44+
severity: "CRITICAL,HIGH,MEDIUM"
45+
scanners: "vuln"
3746
- name: Cache
3847
uses: Swatinem/rust-cache@v2
3948
- name: Install protoc

0 commit comments

Comments
 (0)