Skip to content

Commit 6013c5e

Browse files
Add SBOM and sign image
Sign the image with cosign using the OIDC token. Add Software Bill of Materials with trivy as signed cosign attestations. This informatin is needed for securing the supply chain. You can verify the image with cosign. You can get the SBOM from the attestations and then use trivy to check for vulnerabilities. Signed-off-by: Jordi Massaguer Pla <[email protected]>
1 parent 2da3adb commit 6013c5e

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

.github/workflows/build_and_push_models.yml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# This workflow will install Python dependencies, build the latest models as containers, and push to the registry the resulting containers
22
# TODO: Use cache for caching the docker images, to speed up the build
33
# TODO: Can we have the dependencies stored somehow (predownloaded, a custom image, a container registry, our artifact server...) so this will always be reproduceable?
4-
# TODO: Can we have some kind of Bill Of Materials of the resulting image? What packages are in there? What python "modules" ? Code version of monai?
54

65
name: build_and_push_models
76

@@ -37,6 +36,7 @@ jobs:
3736
permissions:
3837
contents: read
3938
packages: write
39+
id-token: write
4040
steps:
4141
- uses: actions/checkout@v2
4242
- name: Disclaimers
@@ -67,7 +67,7 @@ jobs:
6767
- name: Add fixed libseccomp package
6868
run: ssh -i /tmp/ssh_id_gh adminuser@${AZURE_IPADDRESS} "sudo zypper ar -G https://download.opensuse.org/repositories/home:/jordimassaguerpla:/branches:/openSUSE:/Leap:/15.5:/Update/pool-leap-15.5/home:jordimassaguerpla:branches:openSUSE:Leap:15.5:Update.repo && sudo zypper ref && sudo zypper -n install --from home_jordimassaguerpla_branches_openSUSE_Leap_15.5_Update --allow-vendor-change libseccomp"
6969
- name: Install Deps
70-
run: ssh -i /tmp/ssh_id_gh adminuser@${AZURE_IPADDRESS} "sudo zypper ar -G https://developer.download.nvidia.com/compute/cuda/repos/opensuse15/x86_64/ nvidia && sudo zypper ref && sudo zypper --non-interactive install patch python39 docker-buildx nvidia-container-toolkit nvidia-computeG05 cuda-cudart-devel-11-0 libyaml-cpp0_6 && wget -c https://bootstrap.pypa.io/get-pip.py && python3.9 get-pip.py && python3.9 --version"
70+
run: ssh -i /tmp/ssh_id_gh adminuser@${AZURE_IPADDRESS} "sudo zypper ar -G https://developer.download.nvidia.com/compute/cuda/repos/opensuse15/x86_64/ nvidia && sudo zypper ref && sudo zypper --non-interactive install patch python39 docker-buildx nvidia-container-toolkit nvidia-computeG05 cuda-cudart-devel-11-0 libyaml-cpp0_6 trivy && wget -c https://bootstrap.pypa.io/get-pip.py && python3.9 get-pip.py && python3.9 --version"
7171
- name: Setup Nvidia container
7272
run: ssh -i /tmp/ssh_id_gh adminuser@${AZURE_IPADDRESS} "sudo usermod -G docker,video adminuser && sudo nvidia-ctk runtime configure --runtime=docker && sudo nvidia-ctk runtime configure --runtime=containerd && sudo systemctl start docker && sudo systemctl start containerd && sudo sed -e \"s/user = \\\"\\\"/user = \\\"adminuser:video\\\"/g \" -i /etc/nvidia-container-runtime/config.toml && sudo modprobe nvidia"
7373
- name: Check nvidia
@@ -88,6 +88,8 @@ jobs:
8888
run: scp -i /tmp/ssh_id_gh -r * adminuser@${AZURE_IPADDRESS}:/home/adminuser/work
8989
- name: Monai Deploy package
9090
run: ssh -i /tmp/ssh_id_gh adminuser@${AZURE_IPADDRESS} "mkdir /home/adminuser/work/output && cd /home/adminuser/work && monai-deploy package --no-cache /home/adminuser/work/$APP -c /home/adminuser/work/$APP/app.yaml -t $APP_IMAGE_NAME:$DOCKER_IMAGE_TAG --platform $PLATFORM -l DEBUG --holoscan-sdk-file=/home/adminuser/work/holoscan-$VERSION-cp$CP_VERSION-cp$CP_VERSION-manylinux2014_x86_64.whl --monai-deploy-sdk-file=/home/adminuser/work/monai_deploy_app_sdk-$VERSION-py3-none-any.whl --platform-config dgpu --gid 1000 --output /home/adminuser/work/output"
91+
- name: Build SBOM
92+
run: ssh -i /tmp/ssh_id_gh adminuser@${AZURE_IPADDRESS} "trivy image --format spdx-json --input /home/adminuser/work/output/$DOCKER_IMAGE_NAME.tar > /home/adminuser/work/output/sbom.spdx.json"
9193
- name: Size of docker image
9294
run: ssh -i /tmp/ssh_id_gh adminuser@${AZURE_IPADDRESS} "du -hs /home/adminuser/work/output/*"
9395
- name: Compress docker image
@@ -98,6 +100,10 @@ jobs:
98100
run: df -h
99101
- name: Load docker image
100102
run: ssh -i /tmp/ssh_id_gh adminuser@${AZURE_IPADDRESS} "cat /home/adminuser/work/output/$DOCKER_IMAGE_NAME.tar.gz" | docker load
103+
- name: Get digest
104+
run: echo "IMAGE_DIGEST=$(docker images --no-trunc -q $DOCKER_IMAGE_NAME_SHORT:$DOCKER_IMAGE_TAG)" >> $GITHUB_ENV
105+
- name: Copy SBOM
106+
run: scp -i /tmp/ssh_id_gh adminuser@${AZURE_IPADDRESS}:/home/adminuser/work/output/sbom.spdx.json .
101107
- name: Log in to the Container registry
102108
uses: docker/login-action@v3
103109
with:
@@ -108,6 +114,16 @@ jobs:
108114
run: docker tag $DOCKER_IMAGE_NAME_SHORT:$DOCKER_IMAGE_TAG $REGISTRY/$IMAGE_NAME/$DOCKER_IMAGE_NAME_SHORT:$DOCKER_IMAGE_TAG
109115
- name: Push Docker image
110116
run: docker push $REGISTRY/$IMAGE_NAME/$DOCKER_IMAGE_NAME_SHORT:$DOCKER_IMAGE_TAG
117+
- name: Install sigstore cosign
118+
uses: sigstore/cosign-installer@main
119+
- name: Sign image
120+
env:
121+
COSIGN_EXPERIMENTAL: "true"
122+
run: cosign sign --yes ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ env.IMAGE_DIGEST }}
123+
- name: Sign attestations
124+
env:
125+
COSIGN_EXPERIMENTAL: "true"
126+
run: cosign attest --yes --type spdx --predicate sbom.spdx.json ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ env.IMAGE_DIGEST }}
111127
- name: Terraform Destroy
112128
if: ${{ always() }}
113129
run: terraform destroy -auto-approve

0 commit comments

Comments
 (0)