forked from containerd/runwasi
-
Notifications
You must be signed in to change notification settings - Fork 0
83 lines (71 loc) · 2.35 KB
/
sbom.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
name: Generate SBOMs
on:
workflow_call:
inputs:
image-name:
type: string
required: true
image-digest:
type: string
required: true
jobs:
sbom:
name: Generate SBOM, sign and attach them to OCI image
permissions:
packages: write
id-token: write
runs-on: ubuntu-latest
steps:
- name: Sanitize image name
run: |
image="${{ inputs.image-name }}"
image="${image//_/-}"
echo "image=$image" >> $GITHUB_ENV
- name: Install cosign
uses: sigstore/cosign-installer@59acb6260d9c0ba8f4a2f9d9b48431a222b68e20 # v3.5.0
- name: Install syft
uses: anchore/sbom-action/download-syft@e8d2a6937ecead383dfe75190d104edd1f9c5751 # v0.16.0
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Find repository name
shell: bash
run: |
set -e
IMG_REPOSITORY_NAME=$( echo ${{ github.repository }} | awk '{print tolower($0)}' )
echo IMG_REPOSITORY_NAME=${IMG_REPOSITORY_NAME} >> $GITHUB_ENV
- name: Create SBOM file
shell: bash
run: |
SYFT=$(which syft)
sudo $SYFT \
-o spdx-json \
--file $image-sbom.spdx \
ghcr.io/${{ env.IMG_REPOSITORY_NAME }}/$image@${{ inputs.image-digest }}
- name: Sign SBOM file
run: |
cosign sign-blob --yes \
--output-certificate $image-sbom.spdx.cert \
--output-signature $image-sbom.spdx.sig \
$image-sbom.spdx
- name: Attach SBOM to container image
shell: bash
run: |
cosign attach \
sbom --sbom $image-sbom.spdx \
ghcr.io/${{ env.IMG_REPOSITORY_NAME }}/$image@${{ inputs.image-digest }}
- name: Sign SBOM file pushed to OCI registry
shell: bash
run: |
set -e
SBOM_TAG="$(echo ${{ inputs.image-digest }} | sed -e 's/:/-/g').sbom"
cosign sign --yes \
ghcr.io/${{ env.IMG_REPOSITORY_NAME }}/$image:${SBOM_TAG}
- name: Upload SBOMs as artifacts
uses: actions/upload-artifact@v4
with:
name: sbom
path: $image-sbom-*