Skip to content

Commit cbac34b

Browse files
authored
Merge pull request #76 from krancour/image-signing
release: sign images
2 parents b3a3bb4 + 55a2f26 commit cbac34b

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

.brigade/brigade.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ class BuildImageJob extends JobWithSource {
7878
let registryOrg: string
7979
let registryUsername: string
8080
let registryPassword: string
81+
let signingSetupCommands = ""
82+
let signingCommand = ""
8183
if (!version) { // This is where we'll push potentially unstable images
8284
registry = secrets.unstableImageRegistry
8385
registryOrg = secrets.unstableImageRegistryOrg
@@ -90,6 +92,16 @@ class BuildImageJob extends JobWithSource {
9092
registryPassword = secrets.stableImageRegistryPassword
9193
// Since it's defined, the make target will want this env var
9294
env["VERSION"] = version
95+
env["BASE64_IMAGE_SIGNING_KEY"] = secrets.base64ImageSigningKey
96+
// This env var is documented here:
97+
// https://docs.docker.com/engine/security/trust/trust_automation/
98+
env["DOCKER_CONTENT_TRUST_REPOSITORY_PASSPHRASE"] = secrets.imageSigningKeyPassphrase
99+
const keyDir = "~/.docker/trust/private"
100+
const keyFile = `${keyDir}/${secrets.imageSigningKeyHash}.key`
101+
signingSetupCommands = `mkdir -p ${keyDir} && chmod 700 ${keyDir} && ` +
102+
`printf $BASE64_IMAGE_SIGNING_KEY | base64 -d > ${keyFile} && chmod 600 ${keyFile} && ` +
103+
`docker trust key load --name ${registryUsername} ${keyFile} && `
104+
signingCommand = ` && make sign-${image}`
93105
}
94106
if (registry) {
95107
// Since it's defined, the make target will want this env var
@@ -118,9 +130,11 @@ class BuildImageJob extends JobWithSource {
118130
// probably up and running.
119131
"sleep 20 && " +
120132
`${registriesLoginCmd} && ` +
133+
signingSetupCommands +
121134
"docker buildx create --name builder --use && " +
122135
"docker info && " +
123-
`make push-${image}`
136+
`make push-${image}` +
137+
signingCommand
124138
]
125139
this.sidecarContainers.dind = new Container(dindImg)
126140
this.sidecarContainers.dind.privileged = true

Makefile

+9
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,15 @@ push-%:
180180
--push \
181181
.
182182

183+
.PHONY: sign-%
184+
sign-%:
185+
docker pull $(DOCKER_IMAGE_PREFIX)$*:$(IMMUTABLE_DOCKER_TAG)
186+
docker pull $(DOCKER_IMAGE_PREFIX)$*:$(MUTABLE_DOCKER_TAG)
187+
docker trust sign $(DOCKER_IMAGE_PREFIX)$*:$(IMMUTABLE_DOCKER_TAG)
188+
docker trust sign $(DOCKER_IMAGE_PREFIX)$*:$(MUTABLE_DOCKER_TAG)
189+
docker trust inspect --pretty $(DOCKER_IMAGE_PREFIX)$*:$(IMMUTABLE_DOCKER_TAG)
190+
docker trust inspect --pretty $(DOCKER_IMAGE_PREFIX)$*:$(MUTABLE_DOCKER_TAG)
191+
183192
.PHONY: publish-chart
184193
publish-chart:
185194
$(HELM_DOCKER_CMD) sh -c ' \

0 commit comments

Comments
 (0)