Skip to content

Commit b774013

Browse files
authored
feat: add sboms and vuln scanning (#157)
1 parent bc367e7 commit b774013

File tree

6 files changed

+139
-7
lines changed

6 files changed

+139
-7
lines changed

.github/workflows/commit.yml

+61-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,14 @@ jobs:
3939
path: ~/.local/share/virtualenvs
4040
key: ${{ runner.os }}-python-${{ env.python_version }}-pipenv-${{ hashFiles('Pipfile.lock') }}
4141
- name: Install the dependencies
42-
run: python -m pip install --upgrade pipenv
42+
run: |
43+
python -m pip install --upgrade pipenv
44+
mkdir "${RUNNER_TEMP}/bin"
45+
curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b "${RUNNER_TEMP}/bin"
46+
chmod +x "${RUNNER_TEMP}/bin/syft"
47+
curl -sSfL https://raw.githubusercontent.com/anchore/grype/main/install.sh | sh -s -- -b "${RUNNER_TEMP}/bin"
48+
chmod +x "${RUNNER_TEMP}/bin/grype"
49+
echo "${RUNNER_TEMP}/bin" >> "${GITHUB_PATH}"
4350
- name: Install Task
4451
uses: arduino/setup-task@v1
4552
- name: Initialize the repo
@@ -54,6 +61,26 @@ jobs:
5461
run: task -v test -- debug
5562
env:
5663
PLATFORM: ${{ matrix.platform }}
64+
- name: Generate the SBOMs
65+
run: task -v sbom
66+
env:
67+
PLATFORM: ${{ matrix.platform }}
68+
- name: Upload the SBOMs to GitHub
69+
uses: actions/upload-artifact@v3
70+
with:
71+
name: SBOM
72+
path: sbom.*.json
73+
if-no-files-found: error
74+
- name: Generate vuln scan results
75+
run: task -v vulnscan
76+
env:
77+
PLATFORM: ${{ matrix.platform }}
78+
- name: Upload the vuln scan results to GitHub
79+
uses: actions/upload-artifact@v3
80+
with:
81+
name: Vulns
82+
path: vulns.*.json
83+
if-no-files-found: error
5784
distribute:
5885
name: Distribute
5986
needs: [test]
@@ -65,7 +92,7 @@ jobs:
6592
- name: Checkout the repository
6693
uses: actions/checkout@v3
6794
with:
68-
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
95+
token: ${{ secrets.SEISO_AUTOMATION_PAT }}
6996
fetch-depth: 0
7097
- name: Setup python
7198
uses: actions/setup-python@v4
@@ -76,7 +103,14 @@ jobs:
76103
path: ~/.local/share/virtualenvs
77104
key: ${{ runner.os }}-python-${{ env.python_version }}-pipenv-${{ hashFiles('Pipfile.lock') }}
78105
- name: Install the dependencies
79-
run: python -m pip install --upgrade pipenv
106+
run: |
107+
python -m pip install --upgrade pipenv
108+
mkdir "${RUNNER_TEMP}/bin"
109+
curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b "${RUNNER_TEMP}/bin"
110+
chmod +x "${RUNNER_TEMP}/bin/syft"
111+
curl -sSfL https://raw.githubusercontent.com/anchore/grype/main/install.sh | sh -s -- -b "${RUNNER_TEMP}/bin"
112+
chmod +x "${RUNNER_TEMP}/bin/grype"
113+
echo "${RUNNER_TEMP}/bin" >> "${GITHUB_PATH}"
80114
- name: Install Task
81115
uses: arduino/setup-task@v1
82116
- name: Initialize the repo
@@ -97,6 +131,26 @@ jobs:
97131
run: task -v publish
98132
env:
99133
PLATFORM: all
134+
- name: Generate the SBOMs
135+
run: task -v sbom
136+
env:
137+
PLATFORM: all
138+
- name: Upload the SBOMs to GitHub
139+
uses: actions/upload-artifact@v3
140+
with:
141+
name: SBOM
142+
path: sbom.*.json
143+
if-no-files-found: error
144+
- name: Generate vuln scan results
145+
run: task -v vulnscan
146+
env:
147+
PLATFORM: all
148+
- name: Upload the vuln scan results to GitHub
149+
uses: actions/upload-artifact@v3
150+
with:
151+
name: Vulns
152+
path: vulns.*.json
153+
if-no-files-found: error
100154
- name: Publish the release README to Docker Hub
101155
uses: peter-evans/dockerhub-description@v3
102156
with:
@@ -115,5 +169,9 @@ jobs:
115169
with:
116170
name: ${{ env.TAG }}
117171
tag_name: ${{ env.TAG }}
172+
generate_release_notes: true
173+
files: |
174+
vulns.*.json
175+
sbom.*.json
118176
draft: false
119177
prerelease: false

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
*.tar
22
.ruff_cache
33
.task/*
4+
sbom.*.json
5+
vulns.*.json
46

57
# Created by https://www.toptal.com/developers/gitignore/api/vim,emacs,vs,python,node,macos
68
# Edit at https://www.toptal.com/developers/gitignore?templates=vim,emacs,vs,python,node,macos

Task/Taskfile.yml

+44-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ tasks:
8080
- pipenv run pre-commit validate-manifest .pre-commit-hooks.yaml
8181
status:
8282
- '! test -f .pre-commit-hooks.yaml'
83-
83+
8484
build:
8585
desc: Build the project; docker images, compiled binaries, etc.
8686
platforms: [linux, darwin]
@@ -89,7 +89,7 @@ tasks:
8989
vars: ['VERSION']
9090
vars:
9191
VERSION: '{{.VERSION}}'
92-
PLATFORM: '{{.PLATFORM | default .LOCAL_PLATFORM}}'
92+
PLATFORM: '{{if eq .PLATFORM "all"}}{{.SUPPORTED_PLATFORMS}}{{else if .PLATFORM}}{{.PLATFORM}}{{else}}{{.LOCAL_PLATFORM}}{{end}}'
9393
PUBLISH: '{{.PUBLISH | default "false"}}'
9494
DOCKER_BUILDX_CUSTOM_ARGS: '{{.DOCKER_BUILDX_CUSTOM_ARGS | default ""}}'
9595
TAG_COMMIT_HASH:
@@ -239,3 +239,45 @@ tasks:
239239
- find {{.ROOT_DIR}} -type f -name '*.pyc' -delete
240240
- find {{.ROOT_DIR}} -type d -name '.ruff_cache' -exec rm -rf {} +
241241
- find {{.ROOT_DIR}} -type d -name '.task' -exec rm -rf {} +
242+
- find {{.ROOT_DIR}} -type f -name 'sbom.*.json' -delete
243+
- find {{.ROOT_DIR}} -type f -name 'vulns.*.json' -delete
244+
245+
sbom:
246+
desc: Generate project SBOMs
247+
dir: ../../..
248+
preconditions:
249+
- sh: which syft
250+
msg: "Syft must be installed and reasonably current"
251+
vars:
252+
IMAGE_AND_TAG: '{{.IMAGE_NAME}}:{{.VERSION}}'
253+
PLATFORM: '{{if eq .PLATFORM "all"}}{{.SUPPORTED_PLATFORMS}}{{else if .PLATFORM}}{{.PLATFORM}}{{else}}{{.LOCAL_PLATFORM}}{{end}}'
254+
cmds:
255+
- for:
256+
var: PLATFORM
257+
split: ','
258+
as: platform
259+
cmd: |
260+
export sanitized_platform=$(echo "{{.platform}}" | sed "s%/%_%g") \
261+
&& syft docker:{{.IMAGE_AND_TAG}} --platform {{.platform}} \
262+
-o json=sbom.{{.PROJECT_SLUG}}.{{.VERSION}}.${sanitized_platform}.json \
263+
-o spdx-json=sbom.{{.PROJECT_SLUG}}.{{.VERSION}}.${sanitized_platform}.spdx.json \
264+
-o cyclonedx-json=sbom.{{.PROJECT_SLUG}}.{{.VERSION}}.${sanitized_platform}.cyclonedx.json
265+
266+
vulnscan:
267+
desc: Vuln scan the SBOM
268+
dir: ../../..
269+
vars:
270+
PLATFORM: '{{if eq .PLATFORM "all"}}{{.SUPPORTED_PLATFORMS}}{{else if .PLATFORM}}{{.PLATFORM}}{{else}}{{.LOCAL_PLATFORM}}{{end}}'
271+
preconditions:
272+
- sh: which grype
273+
msg: "Grype must be installed and reasonably current"
274+
cmds:
275+
- for:
276+
var: PLATFORM
277+
split: ','
278+
as: platform
279+
cmd: |
280+
export sanitized_platform=$(echo "{{.platform}}" | sed "s%/%_%g") \
281+
&& grype sbom:sbom.{{.PROJECT_SLUG}}.{{.VERSION}}.${sanitized_platform}.json \
282+
--output json \
283+
--file vulns.{{.PROJECT_SLUG}}.{{.VERSION}}.${sanitized_platform}.json

Task/bash/Taskfile.yml

+10
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,13 @@ tasks:
7272
desc: Clean up build artifacts, cache files/directories, temp files, etc.
7373
cmds:
7474
- task: base:clean
75+
76+
sbom:
77+
desc: Generate project SBOMs
78+
cmds:
79+
- task: base:sbom
80+
81+
vulnscan:
82+
desc: Vuln scan the SBOM
83+
cmds:
84+
- task: base:vulnscan

Task/python/Taskfile.yml

+10
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,13 @@ tasks:
8080
- task: base:clean
8181
- find {{.ROOT_DIR}} -type d -name 'coverage-reports' -exec rm -rf {} +
8282
- find {{.ROOT_DIR}} -type f -name '.coverage' -delete
83+
84+
sbom:
85+
desc: Generate project SBOMs
86+
cmds:
87+
- task: base:sbom
88+
89+
vulnscan:
90+
desc: Vuln scan the SBOM
91+
cmds:
92+
- task: base:vulnscan

Taskfile.yml

+12-2
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ tasks:
102102
cmds:
103103
- task: bash:build
104104
vars:
105-
PLATFORM: '{{if eq .PLATFORM "all"}}{{.SUPPORTED_PLATFORMS}}{{else if .PLATFORM}}{{.PLATFORM}}{{else}}{{.LOCAL_PLATFORM}}{{end}}'
105+
PLATFORM: '{{.PLATFORM | default .LOCAL_PLATFORM}}'
106106

107107
test:
108108
desc: Run the project tests
@@ -149,9 +149,19 @@ tasks:
149149
# We call into the bash:publish instead of across to build to simplify centralized policy assessments (i.e. "is the project using a goat-provided task?")
150150
- task: bash:publish
151151
vars:
152-
PLATFORM: '{{if eq .PLATFORM "all"}}{{.SUPPORTED_PLATFORMS}}{{else if .PLATFORM}}{{.PLATFORM}}{{else}}{{.LOCAL_PLATFORM}}{{end}}'
152+
PLATFORM: '{{.PLATFORM | default .LOCAL_PLATFORM}}'
153153

154154
update:
155155
desc: Update the project dev and runtime dependencies, and pre-commit hash
156156
cmds:
157157
- task: bash:update
158+
159+
sbom:
160+
desc: Generate project SBOMs
161+
cmds:
162+
- task: bash:sbom
163+
164+
vulnscan:
165+
desc: Vuln scan the SBOM
166+
cmds:
167+
- task: bash:vulnscan

0 commit comments

Comments
 (0)