|
| 1 | +// This module is included in the following assembly: |
| 2 | +// |
| 3 | +// *cicd/pipelines/using-tekton-chains-for-pipelines-supply-chain-security.adoc |
| 4 | + |
| 5 | +:_content-type: PROCEDURE |
| 6 | +[id="creating-and-verifying-task-run-signatures-without-any-additional-authentication_{context}"] |
| 7 | +== Creating and verifying task run signatures without any additional authentication |
| 8 | + |
| 9 | +[role="_abstract"] |
| 10 | +To verify signatures of task runs using {tekton-chains} with any additional authentication, perform the following tasks: |
| 11 | + |
| 12 | +* Create an encrypted x509 key pair and save it as a Kubernetes secret. |
| 13 | +* Configure the {tekton-chains} backend storage. |
| 14 | +* Create a task run, sign it, and store the signature and the payload as annotations on the task run itself. |
| 15 | +* Retrieve the signature and payload from the signed task run. |
| 16 | +* Verify the signature of the task run. |
| 17 | +
|
| 18 | +[discrete] |
| 19 | +.Prerequisites |
| 20 | +Ensure that the following are installed on the cluster: |
| 21 | + |
| 22 | +* {pipelines-title} Operator |
| 23 | +* {tekton-chains} |
| 24 | +* link:https://docs.sigstore.dev/cosign/installation/[Cosign] |
| 25 | +
|
| 26 | +[discrete] |
| 27 | +.Procedure |
| 28 | + |
| 29 | +. Create an encrypted x509 key pair and save it as a Kubernetes secret: |
| 30 | ++ |
| 31 | +[source,terminal] |
| 32 | +---- |
| 33 | +$ cosign generate-key-pair k8s://openshift-pipelines/signing-secrets |
| 34 | +---- |
| 35 | ++ |
| 36 | +Provide a password when prompted. Cosign stores the resulting private key as part of the `signing-secrets` Kubernetes secret in the `openshift-pipelines` namespace. |
| 37 | + |
| 38 | +. In the {tekton-chains} configuration, disable the OCI storage, and set the task run storage and format to `tekton`. |
| 39 | ++ |
| 40 | +[source,terminal] |
| 41 | +---- |
| 42 | +$ oc patch configmap chains-config -n openshift-pipelines -p='{"data":{"artifacts.oci.storage": "", "artifacts.taskrun.format":"tekton", "artifacts.taskrun.storage": "tekton"}}' |
| 43 | +---- |
| 44 | + |
| 45 | +. Restart the {tekton-chains} controller to ensure that the modified configuration is applied. |
| 46 | ++ |
| 47 | +[source.terminal] |
| 48 | +---- |
| 49 | +$ oc delete po -n openshift-pipelines -l app=tekton-chains-controller |
| 50 | +---- |
| 51 | + |
| 52 | +. Create a task run. |
| 53 | ++ |
| 54 | +[source,terminal] |
| 55 | +---- |
| 56 | +$ oc create -f https://raw.githubusercontent.com/tektoncd/chains/main/examples/taskruns/task-output-image.yaml <1> |
| 57 | +taskrun.tekton.dev/build-push-run-output-image-qbjvh created |
| 58 | +---- |
| 59 | +<1> Substitute with the URI or file path pointing to your task run. |
| 60 | + |
| 61 | +. Check the status of the steps, and wait till the process finishes. |
| 62 | ++ |
| 63 | +[source,terminal] |
| 64 | +---- |
| 65 | +$ tkn tr describe --last |
| 66 | +[...truncated output...] |
| 67 | +NAME STATUS |
| 68 | +∙ create-dir-builtimage-9467f Completed |
| 69 | +∙ git-source-sourcerepo-p2sk8 Completed |
| 70 | +∙ build-and-push Completed |
| 71 | +∙ echo Completed |
| 72 | +∙ image-digest-exporter-xlkn7 Completed |
| 73 | +---- |
| 74 | + |
| 75 | +. Retrieve the signature and payload from the object stored as `base64` encoded annotations: |
| 76 | ++ |
| 77 | +[source,terminal] |
| 78 | +---- |
| 79 | +$ export TASKRUN_UID=$(tkn tr describe --last -o jsonpath='{.metadata.uid}') |
| 80 | +$ tkn tr describe --last -o jsonpath="{.metadata.annotations.chains\.tekton\.dev/signature-taskrun-$TASKRUN_UID}" > signature |
| 81 | +$ tkn tr describe --last -o jsonpath="{.metadata.annotations.chains\.tekton\.dev/payload-taskrun-$TASKRUN_UID}" | base64 -d > payload |
| 82 | +---- |
| 83 | + |
| 84 | +. Verify the signature. |
| 85 | ++ |
| 86 | +[source,terminal] |
| 87 | +---- |
| 88 | +$ cosign verify-blob --key k8s://openshift-pipelines/signing-secrets --signature ./signature ./payload |
| 89 | +Verified OK |
| 90 | +---- |
| 91 | + |
| 92 | + |
0 commit comments