-
Notifications
You must be signed in to change notification settings - Fork 5
207 lines (174 loc) · 5.95 KB
/
docker.yml
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
name: Docker
on:
workflow_call:
inputs:
tag:
required: true
type: string
platforms:
required: true
type: string
assert:
type: boolean
default: false
flow_name:
required: true
type: string
trail_name:
required: true
type: string
kosli_org:
required: true
type: string
secrets:
slack_channel:
required: true
slack_webhook:
required: true
kosli_api_token:
required: true
snyk_token:
required: true
env:
IMAGE: ghcr.io/kosli-dev/cli
# KOSLI_DRY_RUN: "True"
# Ordinarily we declare KOSLI_ORG and KOSLI_FLOW here but
# this interferes with the CLI integration tests
jobs:
docker:
name: Docker Build
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
attestations: write
packages: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 3
- uses: actions/setup-go@v5
with:
go-version: '1.22.0'
# Set up QEMU emulator to allow building multi-arch images
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
# This is the a separate action that sets up buildx (buildkit) runner
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: setup-kosli-cli
uses: kosli-dev/setup-cli-action@v2
with:
version:
${{ vars.KOSLI_CLI_VERSION }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Push image to the GHCR
- name: Build and push Docker image
id: docker_build
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ env.IMAGE }}:${{ inputs.tag }}
platforms: ${{ inputs.platforms }}
cache-from: type=registry,ref=${{ env.IMAGE }}:buildcache
cache-to: type=registry,ref=${{ env.IMAGE }}:buildcache,mode=max
- name: Make the image fingerprint available for following steps
run: |
ARTIFACT_SHA=$( echo ${{ steps.docker_build.outputs.digest }} | sed 's/.*://')
echo "FINGERPRINT=$ARTIFACT_SHA" >> ${GITHUB_ENV}
- name: Attest Build Provenance
uses: actions/attest-build-provenance@v1
with:
subject-name: ${{ env.IMAGE }}
subject-digest: ${{ steps.docker_build.outputs.digest }}
push-to-registry: true
- name: Generate SBOM for the docker image
uses: anchore/sbom-action@v0
with:
image: ${{ env.IMAGE }}:${{ inputs.tag }}
format: 'spdx-json'
output-file: 'sbom.spdx.json'
upload-artifact: false
- name: Attest SBOM to Github
uses: actions/attest-sbom@v1
with:
sbom-path: 'sbom.spdx.json'
subject-name: ${{ env.IMAGE }}
subject-digest: ${{ steps.docker_build.outputs.digest }}
push-to-registry: true
- name: setup Snyk
uses: snyk/actions/setup@master
- name: Report Docker image to Kosli
if: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/') }}
env:
KOSLI_API_TOKEN: ${{ secrets.kosli_api_token }}
run:
kosli attest artifact
${{ env.IMAGE }}:${{ inputs.tag }}
--flow ${{ inputs.flow_name }}
--trail ${{ inputs.trail_name }}
--name cli-docker
--fingerprint ${{ env.FINGERPRINT }}
--external-url sigstore=https://search.sigstore.dev/?hash=${{ env.FINGERPRINT }}
--org ${{ inputs.kosli_org }}
- name: Report SBOM to Kosli
if: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/') }}
env:
KOSLI_API_TOKEN: ${{ secrets.kosli_api_token }}
run:
kosli attest generic
--flow ${{ inputs.flow_name }}
--trail ${{ inputs.trail_name }}
--name container-sbom
--fingerprint ${{ env.FINGERPRINT }}
--attachments sbom.spdx.json
--org ${{ inputs.kosli_org }}
- name: Run Snyk to scan the Docker image for vulnerabilities
env:
SNYK_TOKEN: ${{ secrets.snyk_token }}
run:
snyk container test ${{ env.IMAGE }}:${{ inputs.tag }}
--file=Dockerfile
--sarif
--policy-path=.snyk
--sarif-file-output=snyk-docker.json
- name: Report Snyk Docker scan results attestation to Kosli
if: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/') && (success() || failure()) }}
env:
KOSLI_API_TOKEN: ${{ secrets.kosli_api_token }}
run:
kosli attest snyk
--flow ${{ inputs.flow_name }}
--trail ${{ inputs.trail_name }}
--fingerprint ${{ env.FINGERPRINT }}
--name snyk-container
--scan-results snyk-docker.json
--org ${{ inputs.kosli_org }}
- name: Smoke test the docker image to be sure it can connect to Kosli
id: smoke-test
env:
KOSLI_ORG: cyber-dojo
KOSLI_API_TOKEN: any-token-will-do
run:
docker run -e KOSLI_API_TOKEN
-e KOSLI_ORG --rm ${{ env.IMAGE }}:${{ inputs.tag }}
list environments
- name: Report Docker smoke test attestation to Kosli
if: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/') && (success() || failure()) }}
env:
KOSLI_API_TOKEN: ${{ secrets.kosli_api_token }}
SMOKE_TEST_OUTCOME: ${{ steps.smoke-test.outcome}}
run:
kosli attest generic
--flow ${{ inputs.flow_name }}
--trail ${{ inputs.trail_name }}
--fingerprint ${{ env.FINGERPRINT }}
--name smoke-test
--compliant=${{ steps.smoke-test.outcome == 'success' }}
--org ${{ inputs.kosli_org }}