Skip to content

Commit

Permalink
SBOM file generation.
Browse files Browse the repository at this point in the history
Adds new steps in the build and release workflow to generate, sign and
publish a SBOM file for Policy Server.
  • Loading branch information
jvanz committed Aug 31, 2022
1 parent 965b714 commit e916777
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 18 deletions.
34 changes: 31 additions & 3 deletions .github/workflows/container-image.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build container image
name: Build policy server
on:
push:
branches:
Expand Down Expand Up @@ -28,6 +28,9 @@ jobs:
needs:
- ci
steps:
- name: Install cosign
uses: sigstore/cosign-installer@main

- name: Configure Ubuntu repositories
run: |
sudo dpkg --add-architecture arm64
Expand Down Expand Up @@ -82,11 +85,36 @@ jobs:
cargo build --release --target ${{ matrix.targetarch }}-unknown-linux-musl
mv target/${{ matrix.targetarch }}-unknown-linux-musl/release/policy-server policy-server-${{ matrix.targetarch }}
- name: Upload policy-server
- name: Generate SBOM
run: |
make download-spdx-sbom-generator sbom
# SBOM files should have "sbom" in the name due the CLO monitor
# https://clomonitor.io/docs/topics/checks/#software-bill-of-materials-sbom
mv bom-cargo.json policy-server-${{ matrix.targetarch }}-sbom.spdx.json
- name: Sign BOM file
run: |
cosign sign-blob --output-certificate policy-server-${{ matrix.targetarch }}-sbom.spdx.cert \
--output-signature policy-server-${{ matrix.targetarch }}-sbom.spdx.sig \
policy-server-${{ matrix.targetarch }}-sbom.spdx.json
env:
COSIGN_EXPERIMENTAL: 1

- name: Upload policy-server binary
uses: actions/upload-artifact@v2
with:
name: policy-server-${{ matrix.targetarch }}
path: policy-server-${{ matrix.targetarch }}
path: |
policy-server-${{ matrix.targetarch }}
- name: Upload policy-server SBOM files
uses: actions/upload-artifact@v2
with:
name: policy-server-${{ matrix.targetarch }}-sbom
path: |
policy-server-${{ matrix.targetarch }}-sbom.spdx.json
policy-server-${{ matrix.targetarch }}-sbom.spdx.cert
policy-server-${{ matrix.targetarch }}-sbom.spdx.sig
build-container-image:
name: Build policy server container image
Expand Down
50 changes: 38 additions & 12 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,49 @@
name: policy-server release
name: Release policy server
on:
push:
tags:
- 'v*'
workflow_run:
workflows: ["Build policy server"]
types:
- completed
branches:
- "v*"
jobs:
ci:
uses: kubewarden/policy-server/.github/workflows/tests.yml@main
release:
name: Create release
runs-on: ubuntu-latest
needs:
- ci
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Download build artifacts
uses: actions/github-script@v6
with:
script: |
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
const matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
return artifact.name.startsWith("policy-server")
});
for (const artifact of matchArtifact) {
let download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: artifact.id,
archive_format: 'zip',
});
let fs = require('fs');
file_path = `${process.env.GITHUB_WORKSPACE}/${artifact.name}.zip`;
fs.writeFileSync(file_path, Buffer.from(download.data));
}
- name: Create release
uses: actions/create-release@v1
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release policy-server ${{ github.ref }}
tag_name: ${{ github.event.workflow_run.head_branch }}
name: Release policy-server ${{ github.event.workflow_run.head_branch }}
draft: false
prerelease: ${{ contains(github.ref, '-alpha') || contains(github.ref, '-beta') || contains(github.ref, '-rc') }}
prerelease: ${{ contains(github.event.workflow_run.head_branch, '-alpha') || contains(github.event.workflow_run.head_branch, '-beta') || contains(github.event.workflow_run.head_branch, '-rc') }}
files: |
policy-server*
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/target
/target
bom-cargo.json
/bin
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
name = "policy-server"
version = "1.1.2"
authors = [
"Kubewarden Developers <kubewarden@suse.de>",
"Flavio Castelli <fcastelli@suse.com>",
"Rafael Fernández López <rfernandezlopez@suse.com>",
"Víctor Cuadrado Juan <vcuadradojuan@suse.de>"
"Víctor Cuadrado Juan <vcuadradojuan@suse.de>",
"José Guilherme Vanz <jguilhermevanz@suse.com>"
]
edition = "2018"

Expand Down
16 changes: 15 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
HYPERFINE := $(shell command -v hyperfine 2> /dev/null)
IMG ?= policy-server:latest
BINDIR ?= bin
SBOM_GENERATOR_TOOL_VERSION ?= v0.0.15

.PHONY: build
build:
Expand Down Expand Up @@ -31,3 +32,16 @@ tag:
.PHONY: docker-build
docker-build: test ## Build docker image with the manager.
docker build -t ${IMG} .

bin:
mkdir $(BINDIR)

.PHONY: download-spdx-sbom-generator
download-spdx-sbom-generator: bin
curl -L -o $(BINDIR)/spdx-sbom-generator-$(SBOM_GENERATOR_TOOL_VERSION)-linux-amd64.tar.gz https://github.com/opensbom-generator/spdx-sbom-generator/releases/download/$(SBOM_GENERATOR_TOOL_VERSION)/spdx-sbom-generator-$(SBOM_GENERATOR_TOOL_VERSION)-linux-amd64.tar.gz
tar -xf ./$(BINDIR)/spdx-sbom-generator-$(SBOM_GENERATOR_TOOL_VERSION)-linux-amd64.tar.gz --directory $(BINDIR)


.PHONY: sbom
sbom:
./$(BINDIR)/spdx-sbom-generator -f json
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,10 @@ Alternatively, the `policy-server` binary can be built in this way:
```shell
$ make build
```

# Software bill of materials

Policy server has its software bill of materials (SBOM) published every release.
It follows the [SPDX](https://spdx.dev/) version 2.2 format and it can be found
together with the signature and certificate used to signed it in the
[release assets](https://github.com/kubewarden/policy-server/releases)
Binary file added spdx-sbom-generator
Binary file not shown.
Binary file added spdx-sbom-generator-v0.0.15-linux-amd64.tar.gz
Binary file not shown.

0 comments on commit e916777

Please sign in to comment.