-
Notifications
You must be signed in to change notification settings - Fork 3
294 lines (266 loc) · 12.2 KB
/
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
name: Docker build
on:
workflow_dispatch:
push:
branches:
- "**"
tags:
- "v*"
pull_request:
branches:
- "main"
permissions:
contents: read
jobs:
docker:
name: Docker build
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write
security-events: write
pull-requests: write
attestations: write
outputs:
digest: ${{ steps.build-and-push.outputs.digest }}
steps:
- name: Harden runner
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
with:
disable-sudo: true
egress-policy: block
allowed-endpoints: >
api.dso.docker.com:443
api.github.com:443
api.scout.docker.com:443
auth.docker.io:443
cdn03.quay.io:443
files.pythonhosted.org:443
fulcio.sigstore.dev:443
ghcr.io:443
github.com:443
grype.anchore.io:443
hub.docker.com:443
index.docker.io:443
nodejs.org:443
objects.githubusercontent.com:443
pkg-containers.githubusercontent.com:443
production.cloudflare.docker.com:443
pypi.org:443
quay.io:443
raw.githubusercontent.com:443
registry-1.docker.io:443
registry.npmjs.org:443
rekor.sigstore.dev:443
toolbox-data.anchore.io:443
tuf-repo-cdn.sigstore.dev:443
uploads.github.com:443
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false
- name: Install Cosign
uses: sigstore/cosign-installer@dc72c7d5c4d10cd6bcb8cf6e3fd625a9e5e537da # v3.7.0
- name: Docker meta
id: docker-meta
uses: docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96 # v5.6.1
with:
images: |
${{ vars.DOCKERHUB_USERNAME }}/cf-ips-to-hcloud-fw
quay.io/${{ vars.QUAY_USERNAME }}/cf-ips-to-hcloud-fw
ghcr.io/${{ github.repository_owner }}/cf-ips-to-hcloud-fw
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
env:
DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest${{ github.event_name != 'pull_request' && github.actor != 'dependabot[bot]' && ',index' || '' }}
- name: Set up QEMU
uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf # v3.2.0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 # v3.7.1
- name: Login to DockerHub
if: ${{ (github.event_name != 'pull_request' || !github.event.pull_request.head.repo.fork) && github.actor != 'dependabot[bot]' }}
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to Quay
if: ${{ github.event_name != 'pull_request' && github.actor != 'dependabot[bot]' }}
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
registry: quay.io
username: ${{ vars.QUAY_ROBOT }}
password: ${{ secrets.QUAY_TOKEN }}
- name: Login to GitHub Container Registry
if: ${{ github.event_name != 'pull_request' && github.actor != 'dependabot[bot]' }}
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
id: build-and-push
uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75 # v6.9.0
with:
context: .
platforms: ${{ github.event_name != 'pull_request' && github.actor != 'dependabot[bot]' && 'linux/amd64,linux/arm64' || '' }}
push: ${{ github.event_name != 'pull_request' && github.actor != 'dependabot[bot]' }}
load: ${{ github.event_name == 'pull_request' || github.actor == 'dependabot[bot]' }}
sbom: ${{ github.event_name != 'pull_request' && github.actor != 'dependabot[bot]' && 'generator=docker/scout-sbom-indexer:1.15.0@sha256:4fa68d539eb5a99e75a93dfbefe5a4dfacd9c90c4577925f492670c6a1b06894' || '' }}
tags: ${{ steps.docker-meta.outputs.tags }}
labels: ${{ steps.docker-meta.outputs.labels }}
annotations: ${{ steps.docker-meta.outputs.annotations }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Generate SBOM
if: ${{ github.event_name != 'pull_request' && github.actor != 'dependabot[bot]' }}
uses: anchore/sbom-action@fc46e51fd3cb168ffb36c6d1915723c47db58abb # v0.17.7
with:
image: ${{ vars.DOCKERHUB_USERNAME }}/cf-ips-to-hcloud-fw
format: spdx-json
artifact-name: sbom-docker.spdx.json
output-file: sbom-docker.spdx.json
- name: Generate SBOM attestation for DockerHub
if: ${{ github.event_name != 'pull_request' && github.actor != 'dependabot[bot]' }}
uses: actions/attest-sbom@5026d3663739160db546203eeaffa6aa1c51a4d6 # v1.4.1
with:
subject-name: index.docker.io/${{ vars.DOCKERHUB_USERNAME }}/cf-ips-to-hcloud-fw
subject-digest: ${{ steps.build-and-push.outputs.digest }}
sbom-path: sbom-docker.spdx.json
push-to-registry: true
- name: Generate SBOM attestation for Quay
if: ${{ github.event_name != 'pull_request' && github.actor != 'dependabot[bot]' }}
uses: actions/attest-sbom@5026d3663739160db546203eeaffa6aa1c51a4d6 # v1.4.1
with:
subject-name: quay.io/${{ vars.QUAY_USERNAME }}/cf-ips-to-hcloud-fw
subject-digest: ${{ steps.build-and-push.outputs.digest }}
sbom-path: sbom-docker.spdx.json
push-to-registry: true
- name: Generate SBOM attestation for GitHub Container Registry
if: ${{ github.event_name != 'pull_request' && github.actor != 'dependabot[bot]' }}
uses: actions/attest-sbom@5026d3663739160db546203eeaffa6aa1c51a4d6 # v1.4.1
with:
subject-name: ghcr.io/${{ github.repository_owner }}/cf-ips-to-hcloud-fw
subject-digest: ${{ steps.build-and-push.outputs.digest }}
sbom-path: sbom-docker.spdx.json
push-to-registry: true
- name: Generate artifact attestation for DockerHub
if: ${{ github.event_name != 'pull_request' && github.actor != 'dependabot[bot]' }}
uses: actions/attest-build-provenance@ef244123eb79f2f7a7e75d99086184180e6d0018 # v1.4.4
with:
subject-name: index.docker.io/${{ vars.DOCKERHUB_USERNAME }}/cf-ips-to-hcloud-fw
subject-digest: ${{ steps.build-and-push.outputs.digest }}
push-to-registry: true
- name: Generate artifact attestation for Quay
if: ${{ github.event_name != 'pull_request' && github.actor != 'dependabot[bot]' }}
uses: actions/attest-build-provenance@ef244123eb79f2f7a7e75d99086184180e6d0018 # v1.4.4
with:
subject-name: quay.io/${{ vars.QUAY_USERNAME }}/cf-ips-to-hcloud-fw
subject-digest: ${{ steps.build-and-push.outputs.digest }}
push-to-registry: true
- name: Generate artifact attestation for GitHub Container Registry
if: ${{ github.event_name != 'pull_request' && github.actor != 'dependabot[bot]' }}
uses: actions/attest-build-provenance@ef244123eb79f2f7a7e75d99086184180e6d0018 # v1.4.4
with:
subject-name: ghcr.io/${{ github.repository_owner }}/cf-ips-to-hcloud-fw
subject-digest: ${{ steps.build-and-push.outputs.digest }}
push-to-registry: true
- name: Sign the images with GitHub OIDC Token
if: ${{ github.event_name != 'pull_request' && github.actor != 'dependabot[bot]' }}
run: |
images=""
for tag in ${TAGS}; do
images+="${tag}@${DIGEST} "
done
cosign sign --recursive --yes ${images}
env:
DIGEST: ${{ steps.build-and-push.outputs.digest }}
TAGS: ${{ steps.docker-meta.outputs.tags }}
- name: Analyze for critical and high CVEs with Docker Scout
if: ${{ (github.event_name != 'pull_request' || !github.event.pull_request.head.repo.fork) && github.actor != 'dependabot[bot]' }}
id: docker-scout-cves
continue-on-error: true
uses: docker/scout-action@6ac950eb733f8b2811f25c05d97bfb3d181b8026 # v1.15.1
with:
command: cves${{ !startsWith(github.ref, 'refs/tags/') && ',recommendations,compare' || '' }}
image: ${{ vars.DOCKERHUB_USERNAME }}/cf-ips-to-hcloud-fw:${{ steps.docker-meta.outputs.version }}
sarif-file: sarif.output.json
organization: ${{ vars.DOCKERHUB_USERNAME }}
to: registry://${{ vars.DOCKERHUB_USERNAME }}/cf-ips-to-hcloud-fw:1
- name: Upload Docker Scout scan result to GitHub Security tab
if: ${{ (github.event_name != 'pull_request' || !github.event.pull_request.head.repo.fork) && github.actor != 'dependabot[bot]' }}
continue-on-error: true
uses: github/codeql-action/upload-sarif@396bb3e45325a47dd9ef434068033c6d5bb0d11a # v3.27.3
with:
sarif_file: sarif.output.json
- name: Scan image with Grype
uses: anchore/scan-action@f2ba85e044c8f5e5014c9a539328a9c78d3bfa49 # v5.2.1
id: grype-scan
continue-on-error: true
with:
image: ${{ vars.DOCKERHUB_USERNAME }}/cf-ips-to-hcloud-fw:${{ steps.docker-meta.outputs.version }}
only-fixed: true
add-cpes-if-none: true
- name: Upload Grype scan result to GitHub Security tab
uses: github/codeql-action/upload-sarif@396bb3e45325a47dd9ef434068033c6d5bb0d11a # v3.27.3
continue-on-error: true
with:
sarif_file: ${{ steps.grype-scan.outputs.sarif }}
provenance-docker:
name: Generate SLSA Provenance for DockerHub
if: ${{ github.event_name != 'pull_request' && github.actor != 'dependabot[bot]' }}
needs:
- docker
permissions:
actions: read
id-token: write
packages: write
# Can't pin with hash due to how this workflow works.
uses: slsa-framework/slsa-github-generator/.github/workflows/[email protected]
with:
image: ${{ vars.DOCKERHUB_USERNAME }}/cf-ips-to-hcloud-fw
digest: ${{ needs.docker.outputs.digest }}
private-repository: true
registry-username: ${{ vars.DOCKERHUB_USERNAME }}
secrets:
registry-password: ${{ secrets.DOCKERHUB_TOKEN }}
provenance-quay:
name: Generate SLSA Provenance for Quay
if: ${{ github.event_name != 'pull_request' && github.actor != 'dependabot[bot]' }}
needs:
- docker
permissions:
actions: read
id-token: write
packages: write
# Can't pin with hash due to how this workflow works.
uses: slsa-framework/slsa-github-generator/.github/workflows/[email protected]
with:
image: quay.io/${{ vars.QUAY_USERNAME }}/cf-ips-to-hcloud-fw
digest: ${{ needs.docker.outputs.digest }}
private-repository: true
registry-username: ${{ vars.QUAY_ROBOT }}
secrets:
registry-password: ${{ secrets.QUAY_TOKEN }}
provenance-ghcr:
name: Generate SLSA Provenance for GitHub Container Registry
if: ${{ github.event_name != 'pull_request' && github.actor != 'dependabot[bot]' }}
needs:
- docker
permissions:
actions: read
id-token: write
packages: write
# Can't pin with hash due to how this workflow works.
uses: slsa-framework/slsa-github-generator/.github/workflows/[email protected]
with:
image: ghcr.io/${{ github.repository_owner }}/cf-ips-to-hcloud-fw
digest: ${{ needs.docker.outputs.digest }}
private-repository: true
registry-username: ${{ github.repository_owner }}
secrets:
registry-password: ${{ secrets.GITHUB_TOKEN }}