Skip to content

Commit 9466eb9

Browse files
committed
Periodic sbom regeneration (#176)
* periodic sbom and advisories regeneration * fix advisories upload * remove branch push trigger
1 parent 18015f4 commit 9466eb9

2 files changed

Lines changed: 76 additions & 13 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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 '[.[] | select(.draft == false) | {tagName: .tag_name, uploadUrl: .upload_url}][:1]')
21+
echo "releases=$RELEASES_JSON" >> $GITHUB_OUTPUT
22+
regenerate-for-release:
23+
name: Regenerate SBOM for release
24+
needs: list-releases
25+
# Don't run if no releases were found.
26+
if: needs.list-releases.outputs.releases != '[]'
27+
strategy:
28+
fail-fast: false
29+
matrix:
30+
release: ${{ fromJson(needs.list-releases.outputs.releases) }}
31+
uses: ./.github/workflows/sbom.yml
32+
with:
33+
upload_url: ${{ matrix.release.uploadUrl }}
34+
tag: ${{ matrix.release.tagName }}
35+
secrets: inherit

.github/workflows/sbom.yml

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,49 +7,77 @@ on:
77
description: "Release assets upload URL"
88
required: true
99
type: string
10+
tag:
11+
description: "The git tag to generate SBOM for - used in scheduled runs"
12+
required: false
13+
type: string
1014

1115
jobs:
1216
create-sbom:
13-
runs-on: self-hosted
17+
runs-on: [self-hosted, Linux, X64]
1418

1519
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+
1629
- name: Checkout
1730
uses: actions/checkout@v4
1831
with:
32+
ref: ${{ steps.vars.outputs.TAG_NAME }}
1933
submodules: recursive
2034

21-
# Store the version, stripping any v-prefix
22-
- name: Write release version
23-
run: |
24-
VERSION=${GITHUB_REF_NAME#v}
25-
echo Version: $VERSION
26-
echo "VERSION=$VERSION" >> $GITHUB_ENV
27-
2835
- name: Create SBOM with Trivy
2936
uses: aquasecurity/trivy-action@0.33.1
3037
with:
3138
scan-type: 'fs'
3239
format: 'spdx-json'
33-
output: "defguard-proxy-${{ env.VERSION }}.sbom.json"
40+
output: "defguard-proxy-${{ steps.vars.outputs.VERSION }}.sbom.json"
3441
scan-ref: '.'
3542
severity: "CRITICAL,HIGH,MEDIUM,LOW"
3643
scanners: "vuln"
3744

3845
- name: Create docker image SBOM with Trivy
3946
uses: aquasecurity/trivy-action@0.33.1
4047
with:
41-
image-ref: "ghcr.io/defguard/defguard-proxy:${{ env.VERSION }}"
48+
image-ref: "ghcr.io/defguard/defguard-proxy:${{ steps.vars.outputs.VERSION }}"
4249
scan-type: 'image'
4350
format: 'spdx-json'
44-
output: "defguard-proxy-${{ env.VERSION }}-docker.sbom.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"
4572
severity: "CRITICAL,HIGH,MEDIUM,LOW"
4673
scanners: "vuln"
4774

48-
- name: Upload SBOM
75+
- name: Upload SBOMs and advisories
4976
uses: shogo82148/actions-upload-release-asset@v1
5077
env:
5178
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5279
with:
5380
upload_url: ${{ inputs.upload_url }}
54-
asset_path: "defguard-*.sbom.json"
81+
asset_path: "defguard-*.json"
5582
asset_content_type: application/octet-stream
83+
overwrite: true

0 commit comments

Comments
 (0)