-
Notifications
You must be signed in to change notification settings - Fork 30
/
verify-enterprise-contract.yaml
318 lines (282 loc) · 10.4 KB
/
verify-enterprise-contract.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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
---
# Copyright The Enterprise Contract Contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
apiVersion: tekton.dev/v1
kind: Task
metadata:
name: verify-enterprise-contract
annotations:
tekton.dev/displayName: Verify Enterprise Contract
tekton.dev/pipelines.minVersion: "0.19"
tekton.dev/tags: ec, chains, signature, conftest
labels:
app.kubernetes.io/version: "0.1"
spec:
description: Verify the enterprise contract is met
params:
- name: IMAGES
type: string
description: |
Spec section of an ApplicationSnapshot resource. Not all fields of the
resource are required. A minimal example:
```json
{
"components": [
{
"containerImage": "quay.io/example/repo:latest"
}
]
}
```
Each `containerImage` in the `components` array is validated.
- name: POLICY_CONFIGURATION
type: string
description: |
Name of the policy configuration (EnterpriseContractPolicy
resource) to use. `namespace/name` or `name` syntax supported. If
namespace is omitted the namespace where the task runs is used.
You can also specify a policy configuration using a git url, e.g.
`github.com/enterprise-contract/config//slsa3`.
default: "enterprise-contract-service/default"
- name: PUBLIC_KEY
type: string
description: >-
Public key used to verify signatures. Must be a valid k8s cosign
reference, e.g. k8s://my-space/my-secret where my-secret contains
the expected cosign.pub attribute.
default: ""
- name: REKOR_HOST
type: string
description: Rekor host for transparency log lookups
default: ""
- name: IGNORE_REKOR
type: string
description: >-
Skip Rekor transparency log checks during validation.
default: "false"
- name: TUF_MIRROR
type: string
description: TUF mirror URL. Provide a value when NOT using public sigstore deployment.
default: ""
- name: SSL_CERT_DIR
type: string
description: |
Path to a directory containing SSL certs to be used when communicating
with external services. This is useful when using the integrated registry
and a local instance of Rekor on a development cluster which may use
certificates issued by a not-commonly trusted root CA. In such cases,
`/var/run/secrets/kubernetes.io/serviceaccount` is a good value. Multiple
paths can be provided by using the `:` separator.
default: ""
- name: CA_TRUST_CONFIGMAP_NAME
type: string
description: The name of the ConfigMap to read CA bundle data from.
default: trusted-ca
- name: CA_TRUST_CONFIG_MAP_KEY
type: string
description: The name of the key in the ConfigMap that contains the CA bundle data.
default: ca-bundle.crt
- name: INFO
type: string
description: Include rule titles and descriptions in the output. Set to `"false"` to disable it.
default: "true"
- name: STRICT
type: string
description: Fail the task if policy fails. Set to `"false"` to disable it.
default: "true"
- name: HOMEDIR
type: string
description: Value for the HOME environment variable.
default: /tekton/home
- name: EFFECTIVE_TIME
type: string
description: Run policy checks with the provided time.
default: "now"
- name: EXTRA_RULE_DATA
type: string
description: Merge additional Rego variables into the policy data. Use syntax "key=value,key2=value2..."
default: ""
- name: TIMEOUT
type: string
description: Timeout setting for `ec validate`.
default: "5m0s"
- name: WORKERS
type: string
description: Number of parallel workers to use for policy evaluation.
default: "1"
- name: SINGLE_COMPONENT
description: Reduce the Snapshot to only the component whose build caused the Snapshot to be created
type: string
default: "false"
- name: SINGLE_COMPONENT_CUSTOM_RESOURCE
description: >
Name, including kind, of the Kubernetes resource to query for labels when single
component mode is enabled, e.g. pr/somepipeline.
type: string
default: "unknown"
- name: SINGLE_COMPONENT_CUSTOM_RESOURCE_NS
description: >
Kubernetes namespace where the SINGLE_COMPONENT_NAME is found. Only used
when single component mode is enabled.
type: string
default: ""
workspaces:
- name: data
description: The workspace where the snapshot spec json file resides
optional: true
results:
- name: TEST_OUTPUT
description: Short summary of the policy evaluation for each image
stepTemplate:
env:
- name: HOME
value: "$(params.HOMEDIR)"
steps:
- name: initialize-tuf
image: quay.io/enterprise-contract/ec-cli:snapshot
script: |-
set -euo pipefail
if [[ -z "${TUF_MIRROR:-}" ]]; then
echo 'TUF_MIRROR parameter not provided. Skipping TUF root initialization.'
exit
fi
echo 'Initializing TUF root...'
ec sigstore initialize --mirror "${TUF_MIRROR}" --root "${TUF_MIRROR}/root.json"
echo 'Done!'
env:
- name: TUF_MIRROR
value: "$(params.TUF_MIRROR)"
- name: reduce
env:
- name: SNAPSHOT
value: $(params.IMAGES)
- name: SINGLE_COMPONENT
value: $(params.SINGLE_COMPONENT)
- name: CUSTOM_RESOURCE
value: $(params.SINGLE_COMPONENT_CUSTOM_RESOURCE)
- name: CUSTOM_RESOURCE_NAMESPACE
value: $(params.SINGLE_COMPONENT_CUSTOM_RESOURCE_NS)
- name: SNAPSHOT_PATH
value: $(params.HOMEDIR)/snapshot.json
image: quay.io/enterprise-contract/ec-cli:snapshot
onError: continue # progress even if the step fails so we can see the debug logs
command: [reduce-snapshot.sh]
- name: validate
image: quay.io/enterprise-contract/ec-cli:snapshot
onError: continue # progress even if the step fails so we can see the debug logs
command: [ec]
args:
- validate
- image
- "--verbose"
- "--images"
- "/tekton/home/snapshot.json"
- "--policy"
- "$(params.POLICY_CONFIGURATION)"
- "--public-key"
- "$(params.PUBLIC_KEY)"
- "--rekor-url"
- "$(params.REKOR_HOST)"
- "--ignore-rekor=$(params.IGNORE_REKOR)"
- "--workers"
- "$(params.WORKERS)"
# NOTE: The syntax below is required to negate boolean parameters
- "--info=$(params.INFO)"
- "--timeout=$(params.TIMEOUT)"
- "--strict=false"
- "--show-successes"
- "--effective-time=$(params.EFFECTIVE_TIME)"
- "--extra-rule-data=$(params.EXTRA_RULE_DATA)"
- "--output"
- "text?show-successes=false"
- "--output"
- "appstudio=$(results.TEST_OUTPUT.path)"
- "--output"
- "json=$(params.HOMEDIR)/report-json.json"
- "--logfile=$(params.HOMEDIR)/debug.log"
env:
- name: SSL_CERT_DIR
# The Tekton Operator automatically sets the SSL_CERT_DIR env to the value below but,
# of course, without the $(param.SSL_CERT_DIR) bit. When a Task Step sets it to a
# value, the Tekton Operator does not do any processing of the value. However, Tekton
# Pipelines will fail to execute because some of these values are required for its
# execution. As a workaround, append the SSL_CERT_DIR value from params to the default
# value expected by Tekton Pipelines. NOTE: If params.SSL_CERT_DIR is empty, the value
# will contain a trailing ":" - this is ok.
value: "/tekton-custom-certs:/etc/ssl/certs:/etc/pki/tls/certs:/system/etc/security/cacerts:$(params.SSL_CERT_DIR)"
# The EC cache is used to avoid fetching the same image layers from the registry more than
# once. However, this is not thread safe. This results in inconsistencies when extracting
# files from an image, see https://github.com/enterprise-contract/ec-cli/issues/1109
- name: EC_CACHE
value: "false"
computeResources:
requests:
cpu: 250m
memory: 2Gi
limits:
memory: 2Gi
volumeMounts:
- name: trusted-ca
mountPath: /etc/pki/tls/certs/ca-custom-bundle.crt
subPath: ca-bundle.crt
readOnly: true
- name: report-json
image: quay.io/enterprise-contract/ec-cli:snapshot
onError: continue # progress even if the step fails so we can see the debug logs
command: [cat]
args:
- "$(params.HOMEDIR)/report-json.json"
- name: summary
image: quay.io/enterprise-contract/ec-cli:snapshot
onError: continue # progress even if the step fails so we can see the debug logs
command: [jq]
args:
- "."
- "$(results.TEST_OUTPUT.path)"
- name: info
image: quay.io/enterprise-contract/ec-cli:snapshot
command: [printf]
args:
- "----- DEBUG OUTPUT -----\n"
- name: version
image: quay.io/enterprise-contract/ec-cli:snapshot
command: [ec]
args:
- version
- name: debug-log
image: quay.io/enterprise-contract/ec-cli:snapshot
command: [cat]
args:
- "$(params.HOMEDIR)/debug.log"
- name: assert
image: quay.io/enterprise-contract/ec-cli:snapshot
command: [jq]
args:
- "--argjson"
- "strict"
- "$(params.STRICT)"
- "-e"
- >
.result == "SUCCESS" or .result == "WARNING" or ($strict | not)
- "$(results.TEST_OUTPUT.path)"
volumes:
- name: trusted-ca
configMap:
name: $(params.CA_TRUST_CONFIGMAP_NAME)
items:
- key: $(params.CA_TRUST_CONFIG_MAP_KEY)
path: ca-bundle.crt
optional: true