Skip to content

Commit 2172464

Browse files
jagathprakashjerop
andcommitted
[TEP-0089] SPIRE for non-falsifiable provenance.
This PR is a part of a larger set of PRs to provide non-falsifiable provenance through SPIRE. In particular this PR uses the SPIRE infrastructure which has already been merged to sign TaskRunStatus. It also has support to verify if TaskRunStatus has been modified by another workload between reconciles. Update pkg/pod/pod.go Co-authored-by: Jerop Kipruto <[email protected]> Update pkg/pod/pod.go Co-authored-by: Jerop Kipruto <[email protected]> Update pkg/pod/pod.go Co-authored-by: Jerop Kipruto <[email protected]>
1 parent f69972a commit 2172464

25 files changed

+2358
-64
lines changed

docs/spire.md

Lines changed: 251 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,58 @@ weight: 1660
66
-->
77
⚠️ This is a work in progress: SPIRE support is not yet functional
88

9-
TaskRun result attestations is currently an alpha experimental feature. Currently all that is implemented is support for configuring Tekton to connect to SPIRE. See TEP-0089 for details on the overall design and feature set.
9+
TaskRun result attestations is currently an alpha experimental feature. Currently all that is implemented is support for configuring Tekton to connect to SPIRE and enabling TaskRun to sign and verify the TaskRunStatus. See [TEP-0089](https://github.com/tektoncd/community/blob/main/teps/0089-nonfalsifiable-provenance-support.md) for details on the overall design and feature set.
1010

1111
This being a large feature, this will be implemented in the following phases. This document will be updated as we implement new phases.
1212
1. Add a client for SPIRE (done).
13-
2. Add a configMap which initializes SPIRE (in progress).
14-
3. Modify TaskRun to sign and verify TaskRun Results using SPIRE.
15-
4. Modify Tekton Chains to verify the TaskRun Results.
13+
2. Add a configMap which initializes SPIRE (done).
14+
3. Modify TaskRun to sign and verify TaskRunStatus using SPIRE (done).
15+
4. Enabling Chains to verify the TaskRun Results.
16+
17+
When the TaskRun result attestations feature is [enabled](./spire.md#enabling-taskrun-result-attestations) all TaskRuns will produce a signature alongside its results, which can then be used to validate its provenance. For example, a TaskRun result that creates user-specified results `commit` and `url` would look like the following. `SVID`, `RESULT_MANIFEST`, `RESULT_MANIFEST.sig`, `commit.sig` and `url.sig` are generated attestations by the integration of SPIRE and Tekton Controller.
18+
19+
Parsed, the fields would be:
20+
```
21+
...
22+
<truncated>
23+
...
24+
📝 Results
25+
26+
NAME VALUE
27+
∙ RESULT_MANIFEST commit,url,SVID,commit.sig,url.sig
28+
∙ RESULT_MANIFEST.sig MEUCIQD55MMII9SEk/esQvwNLGC43y7efNGZ+7fsTdq+9vXYFAIgNoRW7cV9WKriZkcHETIaAKqfcZVJfsKbEmaDyohDSm4=
29+
∙ SVID -----BEGIN CERTIFICATE-----
30+
MIICGzCCAcGgAwIBAgIQH9VkLxKkYMidPIsofckRQTAKBggqhkjOPQQDAjAeMQsw
31+
CQYDVQQGEwJVUzEPMA0GA1UEChMGU1BJRkZFMB4XDTIyMDIxMTE2MzM1MFoXDTIy
32+
MDIxMTE3MzQwMFowHTELMAkGA1UEBhMCVVMxDjAMBgNVBAoTBVNQSVJFMFkwEwYH
33+
KoZIzj0CAQYIKoZIzj0DAQcDQgAEBRdg3LdxVAELeH+lq8wzdEJd4Gnt+m9G0Qhy
34+
NyWoPmFUaj9vPpvOyRgzxChYnW0xpcDWihJBkq/EbusPvQB8CKOB4TCB3jAOBgNV
35+
HQ8BAf8EBAMCA6gwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMCMAwGA1Ud
36+
EwEB/wQCMAAwHQYDVR0OBBYEFID7ARM5+vwzvnLPMO7Icfnj7l7hMB8GA1UdIwQY
37+
MBaAFES3IzpGDqgV3QcQNgX8b/MBwyAtMF8GA1UdEQRYMFaGVHNwaWZmZTovL2V4
38+
YW1wbGUub3JnL25zL2RlZmF1bHQvdGFza3J1bi9jYWNoZS1pbWFnZS1waXBlbGlu
39+
ZXJ1bi04ZHE5Yy1mZXRjaC1mcm9tLWdpdDAKBggqhkjOPQQDAgNIADBFAiEAi+LR
40+
JkrZn93PZPslaFmcrQw3rVcEa4xKmPleSvQaBoACIF1QB+q1uwH6cNvWdbLK9g+W
41+
T9Np18bK0xc6p5SuTM2C
42+
-----END CERTIFICATE-----
43+
∙ commit aa79de59c4bae24e32f15fda467d02ae9cd94b01
44+
∙ commit.sig MEQCIEJHk+8B+mCFozp0F52TQ1AadlhEo1lZNOiOnb/ht71aAiBCE0otKB1R0BktlPvweFPldfZfjG0F+NUSc2gPzhErzg==
45+
∙ url https://github.com/buildpacks/samples
46+
∙ url.sig MEUCIF0Fuxr6lv1MmkreqDKcPH3m+eXp+gY++VcxWgGCx7T1AiEA9U/tROrKuCGfKApLq2A9EModbdoGXyQXFOpAa0aMpOg=
47+
```
48+
49+
However, the verification materials are removed from the final results as part of the TaskRun status. It is stored in the termination messages (more details below):
50+
51+
```
52+
$ tkn tr describe cache-image-pipelinerun-8dq9c-fetch-from-git
53+
...
54+
<truncated>
55+
...
56+
📝 Results
57+
NAME VALUE
58+
∙ commit aa79de59c4bae24e32f15fda467d02ae9cd94b01
59+
∙ url https://github.com/buildpacks/samples
60+
```
1661

1762
## Architecture Overview
1863

@@ -64,7 +109,7 @@ When a TaskRun is created:
64109
## Enabling TaskRun result attestations
65110

66111
To enable TaskRun attestations:
67-
1. Make sure `enforce-nonfalsifiability` is set to `"spire"` in the `feature-flags` configmap, see [`install.md`](./install.md#customizing-the-pipelines-controller-behavior) for details
112+
1. Make sure `enforce-nonfalsifiability` is set to `"spire"` in the `feature-flags` configmap, see [`additional-configs.md`](./additional-configs.md#customizing-the-pipelines-controller-behavior) for details
68113
1. Create a SPIRE deployment containing a SPIRE server, SPIRE agents and the SPIRE CSI driver, for convenience, [this sample single cluster deployment](https://github.com/spiffe/spiffe-csi/tree/main/example/config) can be used.
69114
1. Register the SPIRE workload entry for Tekton with the "Admin" flag, which will allow the Tekton controller to communicate with the SPIRE server to manage the TaskRun identities dynamically.
70115
```
@@ -127,3 +172,204 @@ To enable TaskRun attestations:
127172
# spire-node-alias-prefix specifies the SPIRE node alias prefix to use.
128173
spire-node-alias-prefix: "/tekton-node/"
129174
```
175+
176+
## Sample TaskRun attestation
177+
178+
The following example shows how this feature works:
179+
180+
```yaml
181+
kind: TaskRun
182+
apiVersion: tekton.dev/v1beta1
183+
metadata:
184+
name: non-falsifiable-provenance
185+
spec:
186+
timeout: 60s
187+
taskSpec:
188+
steps:
189+
- name: non-falsifiable
190+
image: ubuntu
191+
script: |
192+
#!/usr/bin/env bash
193+
printf "%s" "hello" > "$(results.foo.path)"
194+
printf "%s" "world" > "$(results.bar.path)"
195+
results:
196+
- name: foo
197+
- name: bar
198+
```
199+
200+
201+
The termination message is:
202+
```
203+
message: '[{"key":"RESULT_MANIFEST","value":"foo,bar","type":1},{"key":"RESULT_MANIFEST.sig","value":"MEQCIB4grfqBkcsGuVyoQd9KUVzNZaFGN6jQOKK90p5HWHqeAiB7yZerDA+YE3Af/ALG43DQzygiBpKhTt8gzWGmpvXJFw==","type":1},{"key":"SVID","value":"-----BEGIN
204+
CERTIFICATE-----\nMIICCjCCAbCgAwIBAgIRALH94zAZZXdtPg97O5vG5M0wCgYIKoZIzj0EAwIwHjEL\nMAkGA1UEBhMCVVMxDzANBgNVBAoTBlNQSUZGRTAeFw0yMjAzMTQxNTUzNTlaFw0y\nMjAzMTQxNjU0MDlaMB0xCzAJBgNVBAYTAlVTMQ4wDAYDVQQKEwVTUElSRTBZMBMG\nByqGSM49AgEGCCqGSM49AwEHA0IABPLzFTDY0RDpjKb+eZCIWgUw9DViu8/pM8q7\nHMTKCzlyGqhaU80sASZfpkZvmi72w+gLszzwVI1ZNU5e7aCzbtSjgc8wgcwwDgYD\nVR0PAQH/BAQDAgOoMB0GA1UdJQQWMBQGCCsGAQUFBwMBBggrBgEFBQcDAjAMBgNV\nHRMBAf8EAjAAMB0GA1UdDgQWBBSsUvspy+/Dl24pA1f+JuNVJrjgmTAfBgNVHSME\nGDAWgBSOMyOHnyLLGxPSD9RRFL+Yhm/6qzBNBgNVHREERjBEhkJzcGlmZmU6Ly9l\neGFtcGxlLm9yZy9ucy9kZWZhdWx0L3Rhc2tydW4vbm9uLWZhbHNpZmlhYmxlLXBy\nb3ZlbmFuY2UwCgYIKoZIzj0EAwIDSAAwRQIhAM4/bPAH9dyhBEj3DbwtJKMyEI56\n4DVrP97ps9QYQb23AiBiXWrQkvRYl0h4CX0lveND2yfqLrGdVL405O5NzCcUrA==\n-----END
205+
CERTIFICATE-----\n","type":1},{"key":"bar","value":"world","type":1},{"key":"bar.sig","value":"MEUCIQDOtg+aEP1FCr6/FsHX+bY1d5abSQn2kTiUMg4Uic2lVQIgTVF5bbT/O77VxESSMtQlpBreMyw2GmKX2hYJlaOEH1M=","type":1},{"key":"foo","value":"hello","type":1},{"key":"foo.sig","value":"MEQCIBr+k0i7SRSyb4h96vQE9hhxBZiZb/2PXQqReOKJDl/rAiBrjgSsalwOvN0zgQay0xQ7PRbm5YSmI8tvKseLR8Ryww==","type":1}]'
206+
```
207+
208+
Parsed, the fields are:
209+
- `RESULT_MANIFEST`: List of results that should be present, to prevent pick and choose attacks
210+
- `RESULT_MANIFEST.sig`: The signature of the result manifest
211+
- `SVID`: The x509 certificate that will be used to verify the signature trust chain to the authority
212+
- `*.sig`: The signature of each individual result output
213+
```
214+
∙ RESULT_MANIFEST foo,bar
215+
∙ RESULT_MANIFEST.sig MEQCIB4grfqBkcsGuVyoQd9KUVzNZaFGN6jQOKK90p5HWHqeAiB7yZerDA+YE3Af/ALG43DQzygiBpKhTt8gzWGmpvXJFw==
216+
∙ SVID -----BEGIN CERTIFICATE-----
217+
MIICCjCCAbCgAwIBAgIRALH94zAZZXdtPg97O5vG5M0wCgYIKoZIzj0EAwIwHjEL
218+
MAkGA1UEBhMCVVMxDzANBgNVBAoTBlNQSUZGRTAeFw0yMjAzMTQxNTUzNTlaFw0y
219+
MjAzMTQxNjU0MDlaMB0xCzAJBgNVBAYTAlVTMQ4wDAYDVQQKEwVTUElSRTBZMBMG
220+
ByqGSM49AgEGCCqGSM49AwEHA0IABPLzFTDY0RDpjKb+eZCIWgUw9DViu8/pM8q7
221+
HMTKCzlyGqhaU80sASZfpkZvmi72w+gLszzwVI1ZNU5e7aCzbtSjgc8wgcwwDgYD
222+
VR0PAQH/BAQDAgOoMB0GA1UdJQQWMBQGCCsGAQUFBwMBBggrBgEFBQcDAjAMBgNV
223+
HRMBAf8EAjAAMB0GA1UdDgQWBBSsUvspy+/Dl24pA1f+JuNVJrjgmTAfBgNVHSME
224+
GDAWgBSOMyOHnyLLGxPSD9RRFL+Yhm/6qzBNBgNVHREERjBEhkJzcGlmZmU6Ly9l
225+
eGFtcGxlLm9yZy9ucy9kZWZhdWx0L3Rhc2tydW4vbm9uLWZhbHNpZmlhYmxlLXBy
226+
b3ZlbmFuY2UwCgYIKoZIzj0EAwIDSAAwRQIhAM4/bPAH9dyhBEj3DbwtJKMyEI56
227+
4DVrP97ps9QYQb23AiBiXWrQkvRYl0h4CX0lveND2yfqLrGdVL405O5NzCcUrA==
228+
-----END CERTIFICATE-----
229+
∙ bar world
230+
∙ bar.sig MEUCIQDOtg+aEP1FCr6/FsHX+bY1d5abSQn2kTiUMg4Uic2lVQIgTVF5bbT/O77VxESSMtQlpBreMyw2GmKX2hYJlaOEH1M=
231+
∙ foo hello
232+
∙ foo.sig MEQCIBr+k0i7SRSyb4h96vQE9hhxBZiZb/2PXQqReOKJDl/rAiBrjgSsalwOvN0zgQay0xQ7PRbm5YSmI8tvKseLR8Ryww==
233+
```
234+
235+
236+
However, the verification materials are removed from the results as part of the TaskRun status:
237+
```console
238+
$ tkn tr describe non-falsifiable-provenance
239+
Name: non-falsifiable-provenance
240+
Namespace: default
241+
Service Account: default
242+
Timeout: 1m0s
243+
Labels:
244+
app.kubernetes.io/managed-by=tekton-pipelines
245+
246+
🌡️ Status
247+
248+
STARTED DURATION STATUS
249+
38 seconds ago 36 seconds Succeeded
250+
251+
📝 Results
252+
253+
NAME VALUE
254+
∙ bar world
255+
∙ foo hello
256+
257+
🦶 Steps
258+
259+
NAME STATUS
260+
∙ non-falsifiable Completed
261+
```
262+
263+
## How is the result being verified
264+
265+
The signatures are being verified by the Tekton controller, the process of verification is as follows:
266+
267+
- Verifying the SVID
268+
- Obtain the trust bundle from the SPIRE server
269+
- Verify the SVID with the trust bundle
270+
- Verify that the SVID spiffe ID is for the correct TaskRun
271+
- Verifying the result manifest
272+
- Verify the content of `RESULT_MANIFEST` with the field `RESULT_MANIFEST.sig` with the SVID public key
273+
- Verify that there is a corresponding field for all items listed in `RESULT_MANIFEST` (besides SVID and `*.sig` fields)
274+
- Verify individual result fields
275+
- For each of the items in the results, verify its content against its associated `.sig` field
276+
277+
278+
# TaskRun Status attestations
279+
280+
Each TaskRun status that is written by the tekton-pipelines-controller will be signed to ensure that there is no external
281+
tampering of the TaskRun status. Upon each retrieval of the TaskRun, the tekton-pipelines-controller checks if the status is initialized,
282+
and that the signature validates the current status.
283+
The signature and SVID will be stored as annotations on the TaskRun Status field, and can be verified by a client.
284+
285+
The verification is done on every consumption of the TaskRun except when the TaskRun is uninitialized. When uninitialized, the
286+
tekton-pipelines-controller is not influenced by fields in the status and thus will not sign incorrect reflections of the TaskRun.
287+
288+
The spec and TaskRun annotations/labels are not signed when there are valid interactions from other controllers or users (i.e. cancelling taskrun).
289+
Editing the object annotations/labels or spec will not result in any unverifiable outcome of the status field.
290+
291+
As the TaskRun progresses, the Pipeline Controller will reconcile the TaskRun object and continually verify the current hash against the `tekton.dev/status-hash-sig` before updating the hash to match the new status and creating a new signature.
292+
293+
An example TaskRun annotations would be:
294+
295+
```console
296+
$ tkn tr describe non-falsifiable-provenance -oyaml
297+
apiVersion: tekton.dev/v1beta1
298+
kind: TaskRun
299+
metadata:
300+
annotations:
301+
pipeline.tekton.dev/release: 3ee99ec
302+
creationTimestamp: "2022-03-04T19:10:46Z"
303+
generation: 1
304+
labels:
305+
app.kubernetes.io/managed-by: tekton-pipelines
306+
name: non-falsifiable-provenance
307+
namespace: default
308+
resourceVersion: "23088242"
309+
uid: 548ebe99-d40b-4580-a9bc-afe80915e22e
310+
spec:
311+
serviceAccountName: default
312+
taskSpec:
313+
results:
314+
- description: ""
315+
name: foo
316+
- description: ""
317+
name: bar
318+
steps:
319+
- image: ubuntu
320+
name: non-falsifiable
321+
resources: {}
322+
script: |
323+
#!/usr/bin/env bash
324+
sleep 30
325+
printf "%s" "hello" > "$(results.foo.path)"
326+
printf "%s" "world" > "$(results.bar.path)"
327+
timeout: 1m0s
328+
status:
329+
annotations:
330+
tekton.dev/controller-svid: |
331+
-----BEGIN CERTIFICATE-----
332+
MIIB7jCCAZSgAwIBAgIRAI8/08uXSn9tyv7cRN87uvgwCgYIKoZIzj0EAwIwHjEL
333+
MAkGA1UEBhMCVVMxDzANBgNVBAoTBlNQSUZGRTAeFw0yMjAzMDQxODU0NTlaFw0y
334+
MjAzMDQxOTU1MDlaMB0xCzAJBgNVBAYTAlVTMQ4wDAYDVQQKEwVTUElSRTBZMBMG
335+
ByqGSM49AgEGCCqGSM49AwEHA0IABL+e9OjkMv+7XgMWYtrzq0ESzJi+znA/Pm8D
336+
nvApAHg3/rEcNS8c5LgFFRzDfcs9fxGSSkL1JrELzoYul1Q13XejgbMwgbAwDgYD
337+
VR0PAQH/BAQDAgOoMB0GA1UdJQQWMBQGCCsGAQUFBwMBBggrBgEFBQcDAjAMBgNV
338+
HRMBAf8EAjAAMB0GA1UdDgQWBBR+ma+yZfo092FKIM4F3yhEY8jgDDAfBgNVHSME
339+
GDAWgBRKiCg5+YdTaQ+5gJmvt2QcDkQ6KjAxBgNVHREEKjAohiZzcGlmZmU6Ly9l
340+
eGFtcGxlLm9yZy90ZWt0b24vY29udHJvbGxlcjAKBggqhkjOPQQDAgNIADBFAiEA
341+
8xVWrQr8+i6yMLDm9IUjtvTbz9ofjSsWL6c/+rxmmRYCIBTiJ/HW7di3inSfxwqK
342+
5DKyPrKoR8sq8Ne7flkhgbkg
343+
-----END CERTIFICATE-----
344+
tekton.dev/status-hash: 76692c9dcd362f8a6e4bda8ccb4c0937ad16b0d23149ae256049433192892511
345+
tekton.dev/status-hash-sig: MEQCIFv2bW0k4g0Azx+qaeZjUulPD8Ma3uCUn0tXQuuR1FaEAiBHQwN4XobOXmC2nddYm04AZ74YubUyNl49/vnbnR/HcQ==
346+
completionTime: "2022-03-04T19:11:22Z"
347+
conditions:
348+
- lastTransitionTime: "2022-03-04T19:11:22Z"
349+
message: All Steps have completed executing
350+
reason: Succeeded
351+
status: "True"
352+
type: Succeeded
353+
- lastTransitionTime: "2022-03-04T19:11:22Z"
354+
message: Spire verified
355+
reason: TaskRunResultsVerified
356+
status: "True"
357+
type: SignedResultsVerified
358+
podName: non-falsifiable-provenance-pod
359+
startTime: "2022-03-04T19:10:46Z"
360+
steps:
361+
...
362+
<TRUNCATED>
363+
```
364+
365+
## How is the status being verified
366+
367+
The signature are being verified by the Tekton controller, the process of verification is as follows:
368+
369+
- Verify status-hash fields
370+
- verify `tekton.dev/status-hash` content against its associated `tekton.dev/status-hash-sig` field. If status hash does
371+
not match invalidate the `tekton.dev/verified = no` annotation will be added
372+
373+
## Further Details
374+
375+
To learn more about SPIRE attestations, check out the [TEP](https://github.com/tektoncd/community/blob/main/teps/0089-nonfalsifiable-provenance-support.md).

examples/v1beta1/pipelineruns/4808-regression.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,4 @@ spec:
9292
name: result-test
9393
params:
9494
- name: RESULT_STRING_LENGTH
95-
value: "3000"
95+
value: "2000"

pkg/apis/config/feature_flags.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,11 @@ func CheckAlphaOrBetaAPIFields(ctx context.Context) bool {
316316
return cfg.FeatureFlags.EnableAPIFields == AlphaAPIFields || cfg.FeatureFlags.EnableAPIFields == BetaAPIFields
317317
}
318318

319+
// IsSpireEnabled checks if non-falsifiable provenance is enforced through SPIRE
320+
func IsSpireEnabled(ctx context.Context) bool {
321+
return FromContextOrDefaults(ctx).FeatureFlags.EnforceNonfalsifiability == EnforceNonfalsifiabilityWithSpire
322+
}
323+
319324
func setEnableAPIFields(ctx context.Context, want string) context.Context {
320325
featureFlags, _ := NewFeatureFlagsFromMap(map[string]string{
321326
"enable-api-fields": want,

pkg/apis/config/feature_flags_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,28 @@ func TestCheckAlphaOrBetaAPIFields(t *testing.T) {
305305
}
306306
}
307307

308+
func TestIsSpireEnabled(t *testing.T) {
309+
ctx := context.Background()
310+
if config.IsSpireEnabled(ctx) {
311+
t.Errorf("IsSpireEnabled got true but expected to be false")
312+
}
313+
store := config.NewStore(logging.FromContext(ctx).Named("config-store"))
314+
featureflags := &corev1.ConfigMap{
315+
ObjectMeta: metav1.ObjectMeta{
316+
Name: "feature-flags",
317+
},
318+
Data: map[string]string{
319+
"enable-api-fields": "alpha",
320+
"enforce-nonfalsifiability": config.EnforceNonfalsifiabilityWithSpire,
321+
},
322+
}
323+
store.OnConfigChanged(featureflags)
324+
ctx = store.ToContext(ctx)
325+
if !config.IsSpireEnabled(ctx) {
326+
t.Errorf("IsSpireEnabled got false but expected to be true")
327+
}
328+
}
329+
308330
func verifyConfigFileWithExpectedFeatureFlagsConfig(t *testing.T, fileName string, expectedConfig *config.FeatureFlags) {
309331
t.Helper()
310332
cm := test.ConfigMapFromTestFile(t, fileName)

pkg/pod/pod.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
3232
"github.com/tektoncd/pipeline/pkg/internal/computeresources/tasklevel"
3333
"github.com/tektoncd/pipeline/pkg/names"
34+
"github.com/tektoncd/pipeline/pkg/spire"
3435
corev1 "k8s.io/api/core/v1"
3536
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3637
"k8s.io/apimachinery/pkg/runtime/schema"
@@ -132,6 +133,10 @@ func (b *Builder) Build(ctx context.Context, taskRun *v1beta1.TaskRun, taskSpec
132133
// Secrets, along with any arguments needed by Step entrypoints to process
133134
// those secrets.
134135
commonExtraEntrypointArgs := []string{}
136+
// Entrypoint arg to enable or disable spire
137+
if config.IsSpireEnabled(ctx) {
138+
commonExtraEntrypointArgs = append(commonExtraEntrypointArgs, "-enable_spire")
139+
}
135140
credEntrypointArgs, credVolumes, credVolumeMounts, err := credsInit(ctx, taskRun.Spec.ServiceAccountName, taskRun.Namespace, b.KubeClient)
136141
if err != nil {
137142
return nil, err
@@ -322,6 +327,39 @@ func (b *Builder) Build(ctx context.Context, taskRun *v1beta1.TaskRun, taskSpec
322327
return nil, err
323328
}
324329

330+
readonly := true
331+
if config.IsSpireEnabled(ctx) {
332+
// add SPIRE's CSI volume to the explicitly declared use volumes
333+
volumes = append(volumes, corev1.Volume{
334+
Name: spire.WorkloadAPI,
335+
VolumeSource: corev1.VolumeSource{
336+
CSI: &corev1.CSIVolumeSource{
337+
Driver: "csi.spiffe.io",
338+
ReadOnly: &readonly,
339+
},
340+
},
341+
})
342+
343+
// mount SPIRE's CSI volume to each Step Container
344+
for i := range stepContainers {
345+
c := &stepContainers[i]
346+
c.VolumeMounts = append(c.VolumeMounts, corev1.VolumeMount{
347+
Name: spire.WorkloadAPI,
348+
MountPath: spire.VolumeMountPath,
349+
ReadOnly: true,
350+
})
351+
}
352+
for i := range initContainers {
353+
// mount SPIRE's CSI volume to each Init Container
354+
c := &initContainers[i]
355+
c.VolumeMounts = append(c.VolumeMounts, corev1.VolumeMount{
356+
Name: spire.WorkloadAPI,
357+
MountPath: spire.VolumeMountPath,
358+
ReadOnly: true,
359+
})
360+
}
361+
}
362+
325363
mergedPodContainers := stepContainers
326364

327365
// Merge sidecar containers with step containers.

0 commit comments

Comments
 (0)