Prepare Git Credential
This guide shows you how to create a git credential Secret that help you run your Tekton Tasks and Pipelines.
This document will use the configuration of a git-clone Task as an example.
If you are using a different Task, you can refer to the steps here and modify the taskRef.name and workspaces to match those defined in your Task.
TOC
PrerequisitesStepsOptional 1: Using ssh CredentialsOptional 2: Using basic-auth CredentialsOptional 3: Using Git ConnectorPrerequisites
- kubectl installed and configured to access the cluster.
- Permissions to read and write Secrets.
Steps
Optional 1: Using ssh Credentials
This Task supports fetching private repositories. There are three ways to authenticate:
-
The simplest approach is to bind an
ssh-directoryworkspace to this Task. The workspace should contain private keys (e.g.id_rsa),configandknown_hostsfiles - anything you need to interact with your git remote via SSH. It's strongly recommended that you use KubernetesSecretsto hold your credentials and bind to this workspace.In a TaskRun that would look something like this:
And in a Pipeline and PipelineRun it would look like this:
The
Secretwould appear the same in both cases - structured like a.sshdirectory:Including
known_hostsis optional but strongly recommended. Without it thegit-cloneTask will blindly accept the remote server's identity. -
Another approach is to bind an
ssl-ca-directoryworkspace to this Task. The workspace should contain crt keys (e.g.ca-bundle.crt)files - anything you need to interact with your git remote via custom CA . It's strongly recommended that you use KubernetesSecretsto hold your credentials and bind to this workspace.In a TaskRun that would look something like this:
And in a Pipeline and PipelineRun it would look like this:
The
Secretwould appear like below:
Optional 2: Using basic-auth Credentials
Note: It is strongly advised that you use ssh credentials when the option
is available to you before using basic auth. You can generate a short
lived token from WebVCS platforms (Github, Gitlab, Bitbucket etc..) to be used
as a password and generally be able to use git as the username.
On bitbucket server the token may have a / into it so you would need
to urlquote them before in the Secret, see this stackoverflow answer :
https://stackoverflow.com/a/24719496
To support basic-auth this Task exposes an optional basic-auth Workspace.
The bound Workspace should contain a .gitconfig or .git-credentials file.
Any other files on this Workspace are ignored. A typical Secret containing
these credentials looks as follows:
Optional 3: Using Git Connector
The task can be used with Git Connector to enhance security.
You need to create the Git Connector first, then in the TaskRun, use CSI to configure the basic-auth workspace.
Git Connector currently only supports cloning with basic-auth, not with ssh.
Here is an example of how to use Git Connector in git-clone TaskRun:
Create Git Connector
Create TaskRun
More about Connector, please refer to Alauda DevOps Connectors Doc.