Chapter 3. Authenticate to an OCI registry
Configure a service account with the necessary credentials to enable Tekton Chains to push signatures to an OCI registry.
The Tekton Chains controller uses the same service account that starts task runs. To configure authentication with an OCI registry, create the required credentials and associate them with this service account.
Procedure
Set the namespace and name of the Kubernetes service account.
$ export NAMESPACE=<namespace> $ export SERVICE_ACCOUNT_NAME=<service_account><namespace>- The namespace associated with the service account.
<service_account>- The name of the service account.
Create a Kubernetes secret.
$ oc create secret registry-credentials \ --from-file=.dockerconfigjson \ --type=kubernetes.io/dockerconfigjson \ -n $NAMESPACE--from-file-
Substitute with the path to your Docker config file. Default path is
~/.docker/config.json.
Give the service account access to the secret.
$ oc patch serviceaccount $SERVICE_ACCOUNT_NAME \ -p "{\"imagePullSecrets\": [{\"name\": \"registry-credentials\"}]}" -n $NAMESPACEIf you patch the default
pipelineservice account that Red Hat OpenShift Pipelines assigns to all task runs, the Red Hat OpenShift Pipelines Operator will override the service account. As a best practice, you can perform the following steps:Create a separate service account to assign to user’s task runs.
$ oc create serviceaccount <service_account_name>Associate the service account to the task runs by setting the value of the
serviceaccountnamefield in the task run template.apiVersion: tekton.dev/v1 kind: TaskRun metadata: name: build-push-task-run-2 spec: taskRunTemplate: serviceAccountName: build-bot taskRef: name: build-push ...serviceAccountName- Substitute with the name of the newly created service account.
Verification
Verify that the service account has the registry secret:
$ oc describe serviceaccount $SERVICE_ACCOUNT_NAME -n $NAMESPACEThe output shows the registry secret in the
SecretsorImage pull secretslist.