Skip to content
This repository was archived by the owner on Mar 14, 2024. It is now read-only.

Commit d5b8144

Browse files
authored
Use FOSSA for SBOM generation (#287)
Syft does not generate a full SBOM report with all transitive dependencies. FOSSA does, so we now use a custom script to generate the SBOM from a FOSSA report and upload to Azure when we release.
1 parent d910080 commit d5b8144

File tree

6 files changed

+58
-19
lines changed

6 files changed

+58
-19
lines changed

.github/scripts/generate-sbom.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
3+
ID=custom%2B5618%2Fgithub.com%2Fnginxinc%2Fnginx-service-mesh
4+
5+
get_revision() {
6+
curl -s "https://app.fossa.com/api/revisions?projectId=${ID}" -H "Authorization: Bearer ${FOSSA_TOKEN}" | jq -ec ".[] | select(.locator | contains(\"${COMMIT_SHA}\"))"
7+
}
8+
9+
echo -n "waiting for revision ${COMMIT_SHA} to exist..."
10+
until get_revision > /dev/null; do
11+
sleep 10
12+
done
13+
echo "done"
14+
15+
REV_ID="${ID}%24${COMMIT_SHA}"
16+
17+
get_attributions() {
18+
curl -s "https://app.fossa.com/api/revisions/${REV_ID}/attribution/full/SPDX_JSON" -H "Authorization: Bearer ${FOSSA_TOKEN}"
19+
}
20+
21+
echo -n "waiting for attributions to be populated..."
22+
while
23+
OUTPUT=$(get_attributions)
24+
LEN=$(jq '.packages | length' <<< "$OUTPUT")
25+
[[ $LEN -le 1 ]]
26+
do
27+
sleep 10
28+
done
29+
echo "done"
30+
31+
echo $OUTPUT | jq > nsm.sbom.json
32+
echo "SBOM report generated"

.github/workflows/ci.yml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ on:
44
push:
55
pull_request:
66

7-
defaults:
8-
run:
9-
shell: bash
10-
117
env:
128
HELM_CHART_DIR: helm-chart
139
GIT_NAME: NGINX Kubernetes Team
@@ -35,7 +31,7 @@ jobs:
3531
version: v1.52
3632
args: --timeout 10m
3733
- name: Lint Helm
38-
run: helm lint ${{ env.HELM_CHART_DIR }}
34+
run: helm lint ${{ env.HELM_CHART_DIR }}
3935

4036
unit-tests:
4137
name: Unit Tests
@@ -68,10 +64,6 @@ jobs:
6864
go-version-file: go.mod
6965
cache: true
7066

71-
- name: Download Syft
72-
uses: anchore/sbom-action/download-syft@422cb34a0f8b599678c41b21163ea6088edb2624 # v0.14.1
73-
if: startsWith(github.ref, 'refs/tags/')
74-
7567
- name: Build binary
7668
uses: goreleaser/goreleaser-action@f82d6c1c344bcacabba2c841718984797f664a6b # v4.2.0
7769
with:

.github/workflows/docs.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@ on:
44
push:
55
pull_request:
66

7-
defaults:
8-
run:
9-
shell: bash
10-
117
concurrency:
128
group: ${{ github.ref_name }}-docs
139
cancel-in-progress: true
1410

11+
permissions:
12+
contents: read
13+
1514
jobs:
1615
markdown-lint:
1716
name: Markdown Lint

.github/workflows/fossa.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ on:
55
branches:
66
- main
77
- release-*
8+
tags:
9+
- '*'
810
paths-ignore:
911
- docs/**
1012
- examples/**
@@ -21,6 +23,7 @@ jobs:
2123
scan:
2224
name: Fossa
2325
runs-on: ubuntu-22.04
26+
timeout-minutes: 30
2427
if: ${{ github.event.repository.fork == false }}
2528
steps:
2629
- name: Checkout Repository
@@ -29,3 +32,19 @@ jobs:
2932
uses: fossas/fossa-action@f61a4c0c263690f2ddb54b9822a719c25a7b608f # v1.3.1
3033
with:
3134
api-key: ${{ secrets.FOSSA_TOKEN }}
35+
- name: Generate SBOM
36+
if: startsWith(github.ref, 'refs/tags/')
37+
env:
38+
COMMIT_SHA: ${{ github.sha }}
39+
FOSSA_TOKEN: ${{ secrets.FOSSA_TOKEN }}
40+
run: .github/scripts/generate-sbom.sh
41+
- name: Upload SBOM
42+
if: startsWith(github.ref, 'refs/tags/')
43+
uses: azure/CLI@fa0f960f00db49b95fdb54328a767aee31e80105 # v1.0.7
44+
env:
45+
AZURE_STORAGE_ACCOUNT: ${{ secrets.AZURE_STORAGE_ACCOUNT }}
46+
AZURE_STORAGE_KEY: ${{ secrets.AZURE_STORAGE_KEY }}
47+
with:
48+
inlineScript: |
49+
az storage blob upload -c ${{ secrets.AZURE_SBOM_BUCKET_NAME }} -f nsm.sbom.json \
50+
-n product/nginx-service-mesh/${{ github.ref_name }}/nginx-service-mesh-${{ github.ref_name }}.sbom.json

.github/workflows/mend.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ on:
55
branches:
66
- main
77
- release-*
8+
tags:
9+
- '*'
810
paths-ignore:
911
- docs/**
1012
- examples/**

.goreleaser.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ changelog:
2121
checksum:
2222
name_template: checksums.txt
2323

24-
sboms:
25-
- artifacts: archive
26-
2724
release:
2825
ids: [nginx-meshctl]
2926
header: |
@@ -34,13 +31,11 @@ release:
3431
archives:
3532
- id: nginx-meshctl
3633
builds: [nginx-meshctl]
37-
name_template: nginx-meshctl_{{ .Version }}_{{ .Os }}_{{ .Arch }}
34+
name_template: nginx-meshctl_{{.Version}}_{{.Os}}_{{.Arch}}
3835
format_overrides:
3936
- goos: windows
4037
format: zip
4138

4239
blobs:
4340
- provider: azblob
4441
bucket: '{{.Env.AZURE_BUCKET_NAME}}'
45-
extra_files:
46-
- glob: ./dist/**.sbom

0 commit comments

Comments
 (0)