-
-
Notifications
You must be signed in to change notification settings - Fork 1
173 lines (141 loc) · 6.37 KB
/
release-docker.yaml
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
name: Release Docker
on:
push:
tags:
- v**
env:
COSIGN_EXPERIMENTAL: 1
IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/slsa-workflow-examples-docker
jobs:
docker:
runs-on: ubuntu-20.04
permissions:
packages: write
outputs:
image-digest: ${{ steps.container_info.outputs.image-digest }}
image-tags: ${{ steps.container_info.outputs.image-tags }}
steps:
- name: Checkout
uses: actions/[email protected]
- name: Login to ghcr.io
uses: docker/[email protected]
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build Docker images
run: |
revision="$(git rev-parse "${GITHUB_REF_NAME:-HEAD}")"
docker build \
-t "${IMAGE_NAME}:latest" \
-t "${IMAGE_NAME}:${GITHUB_REF_NAME}" \
-t "${IMAGE_NAME}:${revision}" \
--label "org.opencontainers.image.source=https://github.com/marcofranssen/slsa-workflow-examples" \
--label "org.opencontainers.image.created=$(date --iso-8601=seconds)" \
--label "org.opencontainers.image.title=slsa-workflow-examples-docker" \
--label "org.opencontainers.image.revision=${revision}" \
--label "org.opencontainers.image.version=${GITHUB_REF_NAME}" \
--label "org.opencontainers.image.licenses=MIT" \
--label "org.opencontainers.image.vendor=Marco Franssen" \
.
- name: Publish Docker images
run: docker push "${IMAGE_NAME}" --all-tags
- name: Get container info
id: container_info
run: |
image_digest="$(docker inspect "${IMAGE_NAME}:latest" --format '{{ index .RepoDigests 0 }}' | awk -F '@' '{ print $2 }')"
image_tags="latest,${GITHUB_REF_NAME},$(git rev-parse "${GITHUB_REF_NAME:-HEAD}")"
echo "::set-output name=image-digest::${image_digest}"
echo "::set-output name=image-tags::${image_tags}"
sign:
runs-on: ubuntu-20.04
needs: [docker]
permissions:
packages: write
id-token: write
env:
IMAGE_DIGEST: ${{ needs.docker.outputs.image-digest }}
steps:
- name: Install cosign
uses: sigstore/[email protected]
with:
cosign-release: v1.6.0
- name: Login to ghcr.io
uses: docker/[email protected]
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Sign image
run: |
cosign sign "${IMAGE_NAME}@${IMAGE_DIGEST}"
echo "::notice title=Verify signature::COSIGN_EXPERIMENTAL=1 cosign verify ${IMAGE_NAME}:${GITHUB_REF_NAME} | jq '.[0]'"
echo "::notice title=Download signatures::COSIGN_EXPERIMENTAL=1 cosign download signature ${IMAGE_NAME}:${GITHUB_REF_NAME} | jq -s ."
echo "::notice title=Inspect signature bundle::COSIGN_EXPERIMENTAL=1 cosign download signature ${IMAGE_NAME}:${GITHUB_REF_NAME} | jq -s '.Bundle.Payload.body |= @base64d | .[0].Bundle.Payload.body | fromjson'"
echo "::notice title=Inspect certificates::COSIGN_EXPERIMENTAL=1 cosign download signature ${IMAGE_NAME}:${GITHUB_REF_NAME} | jq -r '.Bundle.Payload.body |= @base64d | .Bundle.Payload.body | fromjson | .spec.signature.publicKey.content |= @base64d | .spec.signature.publicKey.content' | openssl x509 -text"
sbom:
runs-on: ubuntu-20.04
needs: [docker]
permissions:
packages: write
id-token: write
env:
IMAGE_DIGEST: ${{ needs.docker.outputs.image-digest }}
steps:
- name: Install cosign
uses: sigstore/[email protected]
with:
cosign-release: v1.6.0
- name: Install Syft
uses: anchore/sbom-action/[email protected]
- name: Install Grype
uses: anchore/scan-action/download-grype@v3
- name: Login to ghcr.io
uses: docker/[email protected]
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Attach SBOM to image
run: |
syft "${IMAGE_NAME}@${IMAGE_DIGEST}" -o spdx-json=sbom-spdx.json
grype sbom:sbom-spdx.json
cosign attest --predicate sbom-spdx.json --type spdx "${IMAGE_NAME}@${IMAGE_DIGEST}"
echo "::notice title=Verify SBOM attestation::COSIGN_EXPERIMENTAL=1 cosign verify-attestation ${IMAGE_NAME}@${IMAGE_DIGEST}"
echo "::notice title=Download SBOM attestation::COSIGN_EXPERIMENTAL=1 cosign download attestation ${IMAGE_NAME}@${IMAGE_DIGEST} | jq '.payload |= @base64d | .payload | fromjson | select(.predicateType == \"https://spdx.dev/Document\") | .predicate.Data | fromjson'"
provenance:
runs-on: ubuntu-20.04
needs: [docker]
permissions:
packages: write
id-token: write
env:
IMAGE_DIGEST: ${{ needs.docker.outputs.image-digest }}
PROVENANCE_FILE: provenance.att
steps:
- name: Install cosign
uses: sigstore/[email protected]
with:
cosign-release: v1.6.0
- name: Generate provenance
uses: philips-labs/[email protected]
with:
command: generate
subcommand: container
arguments: --repository "${IMAGE_NAME}" --output-path "${PROVENANCE_FILE}" --digest "${IMAGE_DIGEST}" --tags "${IMAGE_TAGS}"
env:
COSIGN_EXPERIMENTAL: 0
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
IMAGE_TAGS: ${{ needs.docker.outputs.image-tags }}
- name: Login to ghcr.io
uses: docker/[email protected]
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Attach provenance
run: |
jq '.predicate' "${PROVENANCE_FILE}" > provenance-predicate.att
cosign attest --predicate provenance-predicate.att --type slsaprovenance "${IMAGE_NAME}@${IMAGE_DIGEST}"
echo "::notice title=Verify provenance attestation::COSIGN_EXPERIMENTAL=1 cosign verify-attestation ${IMAGE_NAME}@${IMAGE_DIGEST}"
echo "::notice title=Download provenance attestation::COSIGN_EXPERIMENTAL=1 cosign download attestation ${IMAGE_NAME}@${IMAGE_DIGEST} | jq '.payload |= @base64d | .payload | fromjson | select(.predicateType == \"https://slsa.dev/provenance/v0.2\")'"