Questo contenuto non è disponibile nella lingua selezionata.
Chapter 2. Secrets for signing data in Tekton Chains
Cluster administrators can generate a key pair and use Tekton Chains to sign artifacts by using a Kubernetes secret. For Tekton Chains to work, a private key and a password for encrypted keys must exist as part of the signing-secrets secret in the openshift-pipelines namespace.
Currently, Tekton Chains supports the x509 and cosign signature schemes.
Use only one of the supported signature schemes.
To use the
x509signing scheme with Tekton Chains, you must fulfill the following requirements:-
Store the private key in the
signing-secretswith thex509.pemstructure. -
Store the private key as an unencrypted
PKCS #8Privacy-Enhanced Mail (PEM) file. -
The key is of
ed25519orecdsatype.
-
Store the private key in the
To use the
cosignsigning scheme with Tekton Chains, you must fulfill the following requirements:-
Store the private key in the
signing-secretswith thecosign.keystructure. -
Store the password in the
signing-secretswith thecosign.passwordstructure. -
Store the private key as an encrypted PEM file of type
ENCRYPTED COSIGN PRIVATE KEY.
-
Store the private key in the
2.1. Generating the cosign key pair by using the TektonConfig CR Copia collegamentoCollegamento copiato negli appunti!
To use the cosign signing scheme for Tekton Chains secrets, you can generate a cosign key pair that uses Elliptic Curve Digital Signature Algorithm (ECDSA) encryption by setting the generateSigningSecret field in the TektonConfig custom resource (CR) to true.
Prerequisites
-
You installed the OpenShift CLI (
oc) utility. -
You logged in to your OpenShift Container Platform cluster with administrative rights for the
openshift-pipelinesnamespace.
Procedure
Edit the
TektonConfigCR by running the following command:$ oc edit TektonConfig configIn the
TektonConfigCR, set thegenerateSigningSecretvalue totrue:Example of creating an ECDSA cosign key pair by using the
TektonConfigCRapiVersion: operator.tekton.dev/v1 kind: TektonConfig metadata: name: config spec: # ... chain: disabled: false generateSigningSecret: true # ...generateSigningSecret-
The default value is
false. Setting the value totruegenerates theecdsakey pair.
After a few minutes, extract the public key from the secret and store it, so that you can use it to verify artifact attestations. Run the following command to extract the key:
$ oc extract -n openshift-pipelines secret/signing-secrets --keys=cosign.pubThe OpenShift Pipelines Operator generates an
ecdsatypecosignkey pair and stores it in thesigning-secretssecret in theopenshift-pipelinesnamespace. The secret includes the following files:-
cosign.key: The private key -
cosign.password: The password for decrypting the private key cosign.pubThe public keyIf a
signing-secretssecret already exists, the Operator does not overwrite the secret.The
cosign.pubfile in your current directory has the public key extracted from the secret.WarningIf you set the
generateSigningSecretfield fromtruetofalse, the Red Hat OpenShift Pipelines Operator overrides and empties any value in thesigning-secretssecret.The Red Hat OpenShift Pipelines Operator does not offer the following security functions:
- Key rotation
- Auditing key usage
- Proper access control to the key
-
2.2. Manually generating signing secrets with the cosign tool Copia collegamentoCollegamento copiato negli appunti!
You can use the cosign signing scheme with Tekton Chains using the cosign tool.
Prerequisites
- You installed the Cosign tool. For information about installing the Cosign tool, see the Sigstore documentation for Cosign.
Procedure
Generate the
cosign.keyandcosign.pubkey pairs by running the following command:$ cosign generate-key-pair k8s://openshift-pipelines/signing-secretsCosign prompts you for a password and then creates a Kubernetes secret.
-
Store the encrypted
cosign.keyprivate key and thecosign.passworddecryption password in thesigning-secretsKubernetes secret. Ensure that you store the private key as an encrypted Privacy Enhanced Mail (PEM) file of theENCRYPTED COSIGN PRIVATE KEYtype.
2.3. Manually generating signing secrets with the skopeo tool Copia collegamentoCollegamento copiato negli appunti!
You can generate keys by using the skopeo tool and use them in the cosign signing scheme with Tekton Chains.
Prerequisites
-
You installed the
skopeopackage on your Linux system.
Procedure
Generate a public/private key pair by running the following command:
$ skopeo generate-sigstore-key --output-prefix <mykey><mykey>Replace
<mykey>with a key name of your choice.Skopeo prompts you for a passphrase for the private key and then creates the key files named
<mykey>.privateand<mykey>.pub.
Encode the
<mykey>.pubfile by using thebase64tool and running the following command:$ base64 -w 0 <mykey>.pub > b64.pubEncode the
<mykey>.privatefile by using thebase64tool and running the following command:$ base64 -w 0 <mykey>.private > b64.privateEncode the passphrase using the
base64tool by running the following command:$ echo -n '<passphrase>' | base64 -w 0 > b64.passphrase<passphrase>-
Replace
<passphrase>with the passphrase that you used for the key pair.
Create the
signing-secretssecret in theopenshift-pipelinesnamespace by running the following command:$ oc create secret generic signing-secrets -n openshift-pipelinesEdit the
signing-secretssecret by running the following command:$ oc edit secret -n openshift-pipelines signing-secretsAdd the encoded keys in the data of the secret in the following way:
apiVersion: v1 data: cosign.key: <Encoded <mykey>.private> cosign.password: <Encoded passphrase> cosign.pub: <Encoded <mykey>.pub> immutable: true kind: Secret metadata: name: signing-secrets # ... type: Opaque<Encoded <mykey>.private>-
Replace with the content of the
b64.privatefile. <Encoded passphrase>-
Replace with the content of the
b64.passphrasefile. <Encoded <mykey>.pub>-
Replace with the content of the
b64.pubfile.
2.4. Resolving the "secret already exists" error Copia collegamentoCollegamento copiato negli appunti!
If the signing-secret secret is already populated, the command to create this secret might output the following error message:
Error from server (AlreadyExists): secrets "signing-secrets" already exists
You can resolve this error by deleting the secret.
Procedure
Delete the
signing-secretsecret by running the following command:$ oc delete secret signing-secrets -n openshift-pipelines- Re-create the key pairs and store them in the secret using your preferred signing scheme.