Skip to content

Commit a2606fc

Browse files
oarbusiCopilot
andauthored
chore: Generate augmented SBOM on demand (#3384)
* generate augmented SBOM on demand * Update .github/workflows/generate-augmented-sbom.yml Co-authored-by: Copilot <[email protected]> * remove unncessary step name * unify into a script --------- Co-authored-by: Copilot <[email protected]>
1 parent 28824a1 commit a2606fc

File tree

8 files changed

+182
-5
lines changed

8 files changed

+182
-5
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Augment SBOM
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
release_version:
7+
description: "Release version (e.g. 1.35.1)"
8+
required: true
9+
type: string
10+
11+
permissions:
12+
id-token: write
13+
contents: read
14+
15+
jobs:
16+
augment-sbom:
17+
runs-on: ubuntu-latest
18+
19+
env:
20+
KONDUKTO_TOKEN: ${{ secrets.KONDUKTO_TOKEN }}
21+
KONDUKTO_REPO: ${{ vars.KONDUKTO_REPO }}
22+
KONDUKTO_BRANCH_PREFIX: ${{ vars.KONDUKTO_BRANCH_PREFIX }}
23+
SILKBOMB_IMG: ${{ vars.SILKBOMB_IMG }}
24+
25+
steps:
26+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
27+
28+
- uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5
29+
with:
30+
go-version-file: 'go.mod'
31+
32+
- name: Generate PURLs from release artifacts
33+
run: |
34+
./scripts/generate-purls-from-release.sh "${{ inputs.release_version }}"
35+
36+
- name: Generate SBOM with Silkbomb
37+
run: |
38+
make generate-sbom
39+
cat "compliance/sbom.json"
40+
41+
- name: Get current date
42+
id: date
43+
run: |
44+
echo "date=$(date +'%Y-%m-%d')" >> "$GITHUB_ENV"
45+
46+
- name: Augment SBOM with Kondukto
47+
env:
48+
DATE: ${{ env.date }}
49+
RELEASE_VERSION: ${{ inputs.release_version }}
50+
run: |
51+
make augment-sbom
52+
53+
- name: Generate SSDLC report
54+
env:
55+
AUTHOR: ${{ github.actor }}
56+
VERSION: ${{ inputs.release_version }}
57+
AUGMENTED_REPORT: "true"
58+
run: ./scripts/gen-ssdlc-report.sh
59+
60+
- name: Upload augmented SBOM as artifact
61+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
62+
with:
63+
name: augmented_sbom_and_ssdlc_report
64+
path: |
65+
compliance/augmented-sbom-v${{ inputs.release_version }}-${{ env.date }}.json
66+
compliance/ssdlc-compliance-${{ inputs.release_version }}-${{ env.date }}.md
67+
if-no-files-found: error

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ jobs:
175175
KONDUKTO_TOKEN: ${{ secrets.KONDUKTO_TOKEN }}
176176
KONDUKTO_REPO: ${{ vars.KONDUKTO_REPO }}
177177
KONDUKTO_BRANCH_PREFIX: ${{ vars.KONDUKTO_BRANCH_PREFIX }}
178-
- name: Upload SBOM as release asset
178+
- name: Upload SBOM as release artifact
179179
uses: softprops/action-gh-release@da05d552573ad5aba039eaac05058a918a7bf631
180180
with:
181181
files: compliance/sbom.json

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ bin
1010
__debug_*
1111
*~
1212
compliance/sbom.json
13+
compliance/augmented-sbom-v*.json
1314

1415
#used for schema code generation but is not commited to avoid constant updates
1516
tools/codegen/open-api-spec.yml

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,4 +236,8 @@ generate-sbom: ## Generate SBOM
236236

237237
.PHONY: upload-sbom
238238
upload-sbom: ## Upload SBOM
239-
./scripts/upload-sbom.sh
239+
./scripts/upload-sbom.sh
240+
241+
.PHONY: augment-sbom
242+
augment-sbom: ## Augment SBOM
243+
./scripts/augment-sbom.sh

scripts/augment-sbom.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
: "${RELEASE_VERSION:?RELEASE_VERSION environment variable not set}"
5+
DATE=$(date +'%Y-%m-%d')
6+
7+
echo "Augmenting SBOM..."
8+
docker run \
9+
--pull=always \
10+
--platform="linux/amd64" \
11+
--rm \
12+
-v "${PWD}:/pwd" \
13+
-e KONDUKTO_TOKEN \
14+
"$SILKBOMB_IMG" \
15+
augment \
16+
--sbom-in "/pwd/compliance/sbom.json" \
17+
--repo "$KONDUKTO_REPO" \
18+
--branch "$KONDUKTO_BRANCH_PREFIX-linux-arm64" \
19+
--sbom-out "/pwd/compliance/augmented-sbom-v${RELEASE_VERSION}-${DATE}.json"

scripts/extract-purls.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
if [ "$#" -ne 2 ]; then
5+
echo "Usage: $0 <binary_path> <output_file>"
6+
exit 1
7+
fi
8+
9+
BINARY_PATH="$1"
10+
OUTPUT_FILE="$2"
11+
12+
go version -m "$BINARY_PATH" | \
13+
awk '$1 == "dep" || $1 == "=>" { print "pkg:golang/" $2 "@" $3 }' | \
14+
LC_ALL=C sort > "$OUTPUT_FILE"
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
if [ "$#" -ne 1 ]; then
5+
echo "Usage: $0 <release_version>"
6+
exit 1
7+
fi
8+
9+
RELEASE_VERSION="$1"
10+
OUT_DIR="compliance"
11+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
12+
EXTRACT_PURL_SCRIPT="${SCRIPT_DIR}/extract-purls.sh"
13+
14+
if [ ! -x "$EXTRACT_PURL_SCRIPT" ]; then
15+
echo "extract-purls.sh not found or not executable"
16+
exit 1
17+
fi
18+
19+
mkdir -p "$OUT_DIR"
20+
21+
# Define platforms and temp files
22+
PLATFORMS=(
23+
"linux_amd64"
24+
"darwin_amd64"
25+
"windows_amd64"
26+
)
27+
BIN_PATHS=()
28+
PURL_FILES=()
29+
30+
for PLATFORM in "${PLATFORMS[@]}"; do
31+
ZIP_FILE="release-${PLATFORM}.zip"
32+
case "$PLATFORM" in
33+
linux_amd64)
34+
BIN_PATH="./terraform-provider-mongodbatlas_v${RELEASE_VERSION}"
35+
;;
36+
darwin_amd64)
37+
BIN_PATH="./terraform-provider-mongodbatlas_v${RELEASE_VERSION}"
38+
;;
39+
windows_amd64)
40+
BIN_PATH="./terraform-provider-mongodbatlas_v${RELEASE_VERSION}.exe"
41+
;;
42+
esac
43+
PURL_FILE="${OUT_DIR}/purls-${PLATFORM}.txt"
44+
BIN_PATHS+=("$BIN_PATH")
45+
PURL_FILES+=("$PURL_FILE")
46+
47+
# Download
48+
curl -L "https://github.com/mongodb/terraform-provider-mongodbatlas/releases/download/v${RELEASE_VERSION}/terraform-provider-mongodbatlas_${RELEASE_VERSION}_${PLATFORM}.zip" \
49+
-o "$ZIP_FILE"
50+
# Extract
51+
unzip -o "$ZIP_FILE"
52+
# Extract PURLs
53+
"$EXTRACT_PURL_SCRIPT" "$BIN_PATH" "$PURL_FILE"
54+
# Clean up zip and extracted bin after use
55+
rm -f "$ZIP_FILE"
56+
rm -f "$BIN_PATH"
57+
done
58+
59+
# Combine, sort, and deduplicate
60+
cat "${PURL_FILES[@]}" | LC_ALL=C sort | uniq > "${OUT_DIR}/purls.txt"
61+
cat "${OUT_DIR}/purls.txt"
62+
63+
# Clean up temp purl files
64+
rm -f "${PURL_FILES[@]}"

scripts/generate-purls.sh

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
set -euo pipefail
33
: "${LINKER_FLAGS:=}"
44

5+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6+
EXTRACT_PURL_SCRIPT="${SCRIPT_DIR}/extract-purls.sh"
7+
8+
if [ ! -x "$EXTRACT_PURL_SCRIPT" ]; then
9+
echo "extract-purls.sh not found or not executable"
10+
exit 1
11+
fi
12+
513
echo "==> Generating purls"
614

715
# Define output and temp files
@@ -16,15 +24,15 @@ PURL_ALL="${OUT_DIR}/purls.txt"
1624

1725
# Build and extract for Linux
1826
GOOS=linux GOARCH=amd64 go build -ldflags "${LINKER_FLAGS}" -o "${LINUX_BIN}"
19-
go version -m "${LINUX_BIN}" | awk '$1 == "dep" || $1 == "=>" { print "pkg:golang/" $2 "@" $3 }' | LC_ALL=C sort > "${PURL_LINUX}"
27+
"$EXTRACT_PURL_SCRIPT" "${LINUX_BIN}" "${PURL_LINUX}"
2028

2129
# Build and extract for Darwin
2230
GOOS=darwin GOARCH=amd64 go build -ldflags "${LINKER_FLAGS}" -o "${DARWIN_BIN}"
23-
go version -m "${DARWIN_BIN}" | awk '$1 == "dep" || $1 == "=>" { print "pkg:golang/" $2 "@" $3 }' | LC_ALL=C sort > "${PURL_DARWIN}"
31+
"$EXTRACT_PURL_SCRIPT" "${DARWIN_BIN}" "${PURL_DARWIN}"
2432

2533
# Build and extract for Windows
2634
GOOS=windows GOARCH=amd64 go build -ldflags "${LINKER_FLAGS}" -o "${WIN_BIN}"
27-
go version -m "${WIN_BIN}" | awk '$1 == "dep" || $1 == "=>" { print "pkg:golang/" $2 "@" $3 }' | LC_ALL=C sort > "${PURL_WIN}"
35+
"$EXTRACT_PURL_SCRIPT" "${WIN_BIN}" "${PURL_WIN}"
2836

2937
# Combine, sort, and deduplicate
3038
cat "${PURL_LINUX}" "${PURL_DARWIN}" "${PURL_WIN}" | LC_ALL=C sort | uniq > "${PURL_ALL}"

0 commit comments

Comments
 (0)