1.2. 对 Git 存储库进行身份验证
您可以为 Git 存储库定义以下类型的身份验证:
- 基本身份验证(Basic authentication)
- Secure Shell (SSH)身份验证
您还可以在 Build CR 中使用两种类型的身份验证配置 Git secret。
1.2.1. 基本身份验证(Basic authentication) 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
使用基本身份验证时,您必须配置 Git 存储库的用户名和密码。以下示例显示了对 Git 使用基本身份验证:
apiVersion: v1
kind: Secret
metadata:
name: secret-git-basic-auth
annotations:
build.shipwright.io/referenced.secret: "true"
type: kubernetes.io/basic-auth
stringData:
username: <cleartext_username>
password: <cleartext_password>
1.2.2. SSH 身份验证 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
通过 SSH 身份验证,您必须配置 Tekton 注解来指定 Git 存储库供应商的主机名。例如,用于 GitHub 的 github.com 或用于 GitLab 的 gitlab.com。
以下示例显示了对 Git 使用 SSH 身份验证:
apiVersion: v1
kind: Secret
metadata:
name: secret-git-ssh-auth
annotations:
build.shipwright.io/referenced.secret: "true"
type: kubernetes.io/ssh-auth
data:
ssh-privatekey: |
# Insert ssh private key, base64 encoded
1.2.3. 使用 Git secret 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
在相关命名空间中创建 secret 后,您可以在 Build 自定义资源(CR)中引用它。您可以使用两种类型的身份验证配置 Git secret。
以下示例显示了使用带有 SSH 身份验证类型的 Git secret:
apiVersion: shipwright.io/v1beta1
kind: Build
metadata:
name: buildah-golang-build
spec:
source:
git:
url: git@gitlab.com:userjohn/newtaxi.git
cloneSecret: secret-git-ssh-auth
以下示例显示了使用带有基本身份验证类型的 Git secret:
apiVersion: shipwright.io/v1beta1
kind: Build
metadata:
name: buildah-golang-build
spec:
source:
git:
url: https://gitlab.com/userjohn/newtaxi.git
cloneSecret: secret-git-basic-auth