Skip to content

Commit 5c3db0e

Browse files
Sign container images with cosign (#223)
* Add encrypted Travis env vars Signed-off-by: Victoria Miltcheva <[email protected]> * Decrypt encrypted cosign keys in build Signed-off-by: Victoria Miltcheva <[email protected]> * Sign container images with cosign Signed-off-by: Victoria Miltcheva <[email protected]> * Re-encrypt cosign keys for Travis Signed-off-by: Victoria Miltcheva <[email protected]> * Make cosign executable Signed-off-by: Victoria Miltcheva <[email protected]> * Parenthesis Signed-off-by: Victoria Miltcheva <[email protected]> * Use secure env vars instead Signed-off-by: Victoria Miltcheva <[email protected]> * Remove outdated comments Signed-off-by: Victoria Miltcheva <[email protected]> --------- Signed-off-by: Victoria Miltcheva <[email protected]>
1 parent 03780cf commit 5c3db0e

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,7 @@ venv.bak/
115115
# sample file
116116
sample.csv
117117
.envrc
118+
119+
# cosign
120+
cosign.pub
121+
cosign.key

.travis.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,24 @@ python:
44
- "3.9.7" # Matches version in Dockerfiles/Dockerfile.dss
55
dist: bionic
66
group: beta
7-
87
services:
98
- docker
10-
119
before_install:
1210
- test -z "$TRAVIS_TAG" && export VERSION=github-travis-$TRAVIS_BUILD_NUMBER-$(date +%Y%m%d-%H%M%S) || export VERSION=$TRAVIS_TAG
1311
- echo "Build Version=$VERSION"
1412
install:
1513
- make setup
16-
1714
script:
1815
- make travis-test
19-
2016
deploy:
2117
provider: script
2218
script: make travis-deploy
2319
cleanup: false
2420
on:
2521
all_branches: true
2622
condition: $TRAVIS_BRANCH = main || ! -z $TRAVIS_TAG
27-
2823
cache:
2924
directories:
3025
- $HOME/.cache/trivy
3126
- $HOME/.cache/pre-commit
27+
- $HOME/.cache/cosign

Makefile

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,22 @@ COVERAGE := pipenv run coverage
4343
# Only set if not defined
4444
VERSION ?= dev
4545

46+
# Docker related
47+
DOCKER_REGISTRY_ICR := icr.io
48+
DOCKER_USER_ICR := iamapikey
49+
DOCKER_PASS_ICR := $(IBM_CLOUD_API_KEY)
50+
4651
# Trivy related
4752
TRIVY ?= trivy
4853
TRIVY_VERSION := $(shell curl -s "https://api.github.com/repos/aquasecurity/trivy/releases/latest" | grep '"tag_name":' | sed -E 's/.*"v([^"]+)".*/\1/')
4954
TRIVY_OS := $(shell uname | sed 's/Darwin/macOS/' )
5055
TRIVY_ARCH := $(shell uname -m | cut -d_ -f2 )
5156

57+
# Cosign related
58+
COSIGN ?= /tmp/cosign
59+
COSIGN_VERSION := $(shell curl -s "https://api.github.com/repos/sigstore/cosign/releases/latest" | grep '"tag_name":' | sed -E 's/.*"v([^"]+)".*/\1/')
60+
61+
5262
.PHONY: setup-trivy
5363
setup-trivy:
5464
curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/master/contrib/install.sh | sudo sh -s -- -b /usr/local/bin
@@ -57,6 +67,11 @@ ifdef TRAVIS
5767
sudo apt update && sudo apt install rpm -y
5868
endif
5969

70+
.PHONY: setup-cosign
71+
setup-cosign:
72+
curl -sSfL https://github.com/sigstore/cosign/releases/download/v$(COSIGN_VERSION)/cosign-linux-amd64 -o $(COSIGN)
73+
chmod +x $(COSIGN)
74+
6075
.PHONY: setup-deploy-tools
6176
setup-deploy-tools:
6277
curl -Lo container-structure-test https://storage.googleapis.com/container-structure-test/latest/container-structure-test-$(shell uname | tr '[:upper:]' '[:lower:]')-amd64 && sudo install container-structure-test /usr/local/bin/
@@ -68,7 +83,7 @@ setup-deploy-tools:
6883
kustomize version
6984

7085
.PHONY: setup
71-
setup: setup-trivy setup-deploy-tools
86+
setup: setup-trivy setup-cosign setup-deploy-tools
7287
pip install --upgrade pip
7388
pip install "setuptools>=65.5.1" pipenv
7489
PIP_IGNORE_INSTALLED=1 pipenv install --dev --deploy --ignore-pipfile
@@ -163,6 +178,8 @@ endif
163178
# login to cr and set region
164179
@ibmcloud cr region-set global
165180
@ibmcloud cr login
181+
# login to cosign
182+
@echo $(DOCKER_PASS_ICR) | $(COSIGN) login -u $(DOCKER_USER_ICR) --password-stdin $(DOCKER_REGISTRY_ICR)
166183

167184
.PHONY: build-images
168185
build-images:
@@ -182,6 +199,13 @@ quality-images:
182199
.PHONY: deploy
183200
deploy:
184201
skaffold build
202+
for image in $(shell skaffold build -q --dry-run | jq -r .builds[].tag); do \
203+
@echo "Signing image $${image}"; \
204+
$(COSIGN) sign --key env://COSIGN_PRIVATE_KEY --yes $${image}; \
205+
206+
@echo "Verifying image $${image}; \
207+
$(COSIGN) verify --key env://COSIGN_PUBLIC_KEY $${image}; \
208+
done;
185209

186210
.PHONY: clean
187211
clean:

0 commit comments

Comments
 (0)