Skip to content

Commit 5f6187d

Browse files
Merge pull request #219 from DefGuard/sbom-into-main
Merge SBOM CI pipelines into main
2 parents d996c17 + 509a543 commit 5f6187d

File tree

5 files changed

+138
-1
lines changed

5 files changed

+138
-1
lines changed

.github/workflows/build-docker.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ jobs:
7474
cache-to: type=registry,mode=max,ref=${{ env.GHCR_REPO }}:cache-${{ matrix.tag }}-${{ env.SAFE_REF }}
7575

7676
- name: Scan image with Trivy
77-
uses: aquasecurity/trivy-action@0.32.0
77+
uses: aquasecurity/trivy-action@0.33.1
7878
with:
7979
image-ref: "${{ env.GHCR_REPO }}:${{ github.sha }}-${{ matrix.tag }}"
8080
format: "table"

.github/workflows/ci.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ jobs:
3333
with:
3434
submodules: recursive
3535

36+
- name: Scan code with Trivy
37+
uses: aquasecurity/[email protected]
38+
with:
39+
scan-type: 'fs'
40+
scan-ref: '.'
41+
exit-code: "1"
42+
ignore-unfixed: true
43+
severity: "CRITICAL,HIGH,MEDIUM"
44+
scanners: "vuln"
45+
3646
- name: Cache
3747
uses: Swatinem/rust-cache@v2
3848
with:

.github/workflows/release.yml

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

54+
create-sbom:
55+
needs: [create-release, build-docker-release]
56+
uses: ./.github/workflows/sbom.yml
57+
with:
58+
upload_url: ${{ needs.create-release.outputs.upload_url }}
59+
5460
build-release:
5561
name: Release ${{ matrix.build }}
5662
needs: [create-release]
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
25+
regenerate-for-release:
26+
name: Regenerate SBOM for release
27+
needs: list-releases
28+
# Don't run if no releases were found.
29+
if: needs.list-releases.outputs.releases != '[]'
30+
strategy:
31+
fail-fast: false
32+
matrix:
33+
release: ${{ fromJson(needs.list-releases.outputs.releases) }}
34+
uses: ./.github/workflows/sbom.yml
35+
with:
36+
upload_url: ${{ matrix.release.uploadUrl }}
37+
tag: ${{ matrix.release.tagName }}
38+
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/[email protected]
37+
with:
38+
scan-type: 'fs'
39+
format: 'spdx-json'
40+
output: "defguard-gateway-${{ 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/[email protected]
47+
with:
48+
image-ref: "ghcr.io/defguard/gateway:${{ steps.vars.outputs.VERSION }}"
49+
scan-type: 'image'
50+
format: 'spdx-json'
51+
output: "defguard-gateway-${{ 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/[email protected]
57+
with:
58+
scan-type: 'fs'
59+
format: 'json'
60+
output: "defguard-gateway-${{ 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/[email protected]
67+
with:
68+
image-ref: "ghcr.io/defguard/gateway:${{ steps.vars.outputs.VERSION }}"
69+
scan-type: 'image'
70+
format: 'json'
71+
output: "defguard-gateway-${{ 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

0 commit comments

Comments
 (0)