搜索

1.2. 对 Git 存储库进行身份验证

download PDF

您可以为 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 1
stringData: 2
  username: <cleartext_username>
  password: <cleartext_password>
1
Kubernetes secret 的类型。
2
以明文形式存储您的用户名和密码的字段。

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 1
data:
  ssh-privatekey: |   2
    # Insert ssh private key, base64 encoded
1
Kubernetes secret 的类型。
2
用于在 Git 中进行身份验证的 SSH 密钥的 Base64 编码。您可以使用 base64 ~/.ssh/id_rsa.pub 命令来生成此密钥,其中 ~/.ssh/id_rsa.pub 表示密钥的默认位置,它们通常用于向 Git 进行身份验证。

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
Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.