链配置

目录

概述

Tekton Chains 是一个 Kubernetes 自定义资源定义(CRD)控制器,允许您管理 Tekton 中的供应链安全。本文档介绍如何配置 Tekton Chains。

配置

Chains 的配置存储在 tekton-pipelinestekton-chains 命名空间中的名为 chains-config 的 ConfigMap 中。您可以修改此 ConfigMap 来更改 Chains 的行为。

默认情况下,Tekton Chains 通过 TektonConfig 资源自动部署。您可以修改 TektonConfig 资源来配置 Chains。

本质上,Tekton Operator 会将 Chains 的配置从 TektonConfig 资源同步到 TektonChains 资源,最终反映在 chains-config ConfigMap 中。

WARNING

如果您通过 TektonConfig 部署 Chains,则必须通过 TektonConfig 配置 Chains

如果您仅修改 chains-config ConfigMap 中的配置,且未同步到 TektonChains 资源,配置可能会丢失。

TektonConfig 中的配置发生变化,或因其他原因触发调和时,chains-config ConfigMap 中的配置将被覆盖。

TIP

但是,某些高级配置仅支持在 chains-config ConfigMap 中配置,且由于验证 webhook 的限制,无法在 TektonConfig 中配置。

如果遇到此问题,您需要禁用 TektonConfigChains 的自动部署,并手动创建 TektonHub 资源。

下面是配置 Chains 的不同方式的简单示例。

chains-config ConfigMap 中配置

以下是 chains-config ConfigMap 的示例:

apiVersion: v1
data:
  artifacts.oci.format: simplesigning
  artifacts.oci.storage: oci
  artifacts.pipelinerun.format: in-toto
  artifacts.pipelinerun.storage: oci
  artifacts.taskrun.format: in-toto
  artifacts.taskrun.storage: oci
  transparency.enabled: "false"
kind: ConfigMap
metadata:
  name: chains-config
TIP

布尔值是字符串类型,如 "true""false"

YAML 字段说明
  • artifacts.oci.format:证明格式。
  • artifacts.oci.storage:证明的存储后端。
  • artifacts.pipelinerun.format:PipelineRun 证明的格式。
  • artifacts.pipelinerun.storage:PipelineRun 证明的存储后端。
  • artifacts.taskrun.format:TaskRun 证明的格式。
  • artifacts.taskrun.storage:TaskRun 证明的存储后端。

在 TektonConfig 中配置

TektonConfig 资源中,Chains 的配置大致如下:

apiVersion: operator.tekton.dev/v1alpha1
kind: TektonConfig
metadata:
  name: config
spec:
  chain:
    disabled: false
    generateSigningSecret: false
    controllerEnvs:
      - name: SIGSTORE_ID_TOKEN
        value: "<your-id-token>"

    artifacts.oci.format: simplesigning
    artifacts.oci.storage: oci
    artifacts.pipelinerun.format: in-toto
    artifacts.pipelinerun.storage: oci
    artifacts.taskrun.format: in-toto
    artifacts.taskrun.storage: oci

    signers.x509.fulcio.enabled: <false>
    signers.x509.fulcio.address: <ttps://fulcio.sigstore.dev>
    signers.x509.fulcio.issuer: <https://oauth2.sigstore.dev/auth>
    transparency.enabled: <false>
    transparency.url: <https://rekor.sigstore.dev>

    storage.oci.repository.insecure: true

    options:
      deployments:
        tekton-chains-controller:
          spec:
            template:
              spec:
                containers:
                - name: tekton-chains-controller
                  env:
                    - name: SIGSTORE_ID_TOKEN
                      value: "<your-id-token>"
                  resources: {}
TIP

布尔值为原始类型,如 truefalse

YAML 字段说明
  • spec.chain:包含 Chains 的配置。
    • disabled:是否禁用 Chains。
      • 此配置仅存在于 TektonConfig 中,TektonChains 中不存在。
    • generateSigningSecret:是否生成签名密钥。
      • 此配置仅存在于 TektonConfig 中,TektonChains 中不存在。
    • controllerEnvs:Tekton Chains 控制器的环境变量。
      • 此配置仅存在于 TektonConfig 中,TektonChains 中不存在。
      • name:环境变量名称。
      • value:环境变量值。
    • options:Tekton Chains 控制器的选项。
      • 此配置仅存在于 TektonConfig 中,TektonChains 中不存在。
      • deployments.tekton-chains-controller:Tekton Chains 控制器的部署选项。
        • spec.template.spec.containers.env.SIGSTORE_ID_TOKEN:Tekton Chains 控制器的 ID 令牌。
      • 更多详细支持请参见 Additional fields as options
    • 以下配置也存在于 TektonChains 中,最终会同步到 chains-config ConfigMap。
      • artifacts.oci.format
      • artifacts.oci.storage
      • artifacts.pipelinerun.format
      • artifacts.pipelinerun.storage
      • artifacts.taskrun.format
      • artifacts.taskrun.storage
      • storage.oci.repository.insecure
      • signers.x509.fulcio.address
      • signers.x509.fulcio.issuer
      • transparency.enabled
      • transparency.url

TaskRun 配置

描述支持的值默认值
artifacts.taskrun.format存储 TaskRun 负载的格式。in-toto, slsa/v1, slsa/v2alpha3, slsa/v2alpha4in-toto
artifacts.taskrun.storage存储 TaskRun 签名的存储后端。可用多个后端,用逗号分隔(如 "tekton,oci")。要禁用 TaskRun 产物输入,使用空字符串 ("")。tekton, oci, gcs, docdb, grafeas, archivistatekton
artifacts.taskrun.signer用于签署 TaskRun 负载的签名后端。x509, kmsx509

说明

  • slsa/v1in-toto 的别名,用于向后兼容。
  • 如果存储为 oci,证明将与存储的 OCI 产物一起存储。更多信息请参见 cosign documentation
  • 如果存储为 tekton,证明将存储在 Tekton TaskRun 的注解中。

PipelineRun 配置

与 TaskRun 类似,您可以配置 PipelineRun 的签名和存储。

描述支持的值默认值
artifacts.pipelinerun.format存储 PipelineRun 负载的格式。in-toto, slsa/v1, slsa/v2alpha3, slsa/v2alpha4in-toto
artifacts.pipelinerun.storage存储 PipelineRun 签名的存储后端。可用多个后端,用逗号分隔(如 "tekton,oci")。要禁用 PipelineRun 产物输入,使用空字符串 ("")。tekton, oci, gcs, docdb, grafeas, archivistatekton
artifacts.pipelinerun.signer用于签署 PipelineRun 负载的签名后端。x509, kmsx509
artifacts.pipelinerun.enable-deep-inspection该布尔选项配置 Chains 是否应检查子 taskrun,以捕获 pipelinerun 中的输入/输出。设置为 "false" 表示 Chains 仅检查 pipeline 级别结果,"true" 表示 Chains 检查 pipeline 级别和 task 级别结果。"true", "false""false"
  • 如果存储为 oci,证明将与存储的 OCI 产物一起存储。更多信息请参见 cosign documentation
  • 如果存储为 tekton,证明将存储在 Tekton PipelineRun 的注解中。

OCI 配置

描述支持的值默认值
artifacts.oci.format存储 OCI 负载的格式。simplesigningsimplesigning
artifacts.oci.storage存储 OCI 签名的存储后端。可用多个后端,用逗号分隔(如 "oci,tekton")。要禁用 OCI 产物输入,使用空字符串 ("")。tekton, ocioci
artifacts.oci.signer用于签署 OCI 负载的签名后端。x509, kmsx509
  • 如果存储为 oci,证明将与存储的 OCI 产物一起存储。更多信息请参见 cosign documentation
  • 如果存储为 tekton,证明将存储在 Tekton TaskRunPipelineRun 的注解中。

存储配置

Chains 支持多种存储后端用于存储证明和签名。 下面列出了一些常见的存储后端,更多详细配置请参见 Storage Configuration

描述支持的值默认值
storage.oci.repository用于存储 OCI 签名和证明的 OCI 仓库如果未定义且 artifacts.{oci,taskrun}.storage 中包含 oci 存储,则证明将与存储的 OCI 产物一起存储。(GCP 上的示例)定义此值后,OCI 包将存储在指定位置,而非与镜像并存。更多信息请参见 cosign 文档。
storage.oci.repository.insecure连接 OCI 仓库时是否使用不安全连接true, falsefalse

说明

  • 如果您的 OCI 仓库使用自签名证书,您需要将 storage.oci.repository.insecure 设置为 true,以允许不安全连接。

Sigstore 功能配置

透明日志

描述支持的值默认值
transparency.enabled是否启用透明日志。"true", "false""false"
transparency.url透明日志的 URL。"https://rekor.sigstore.dev"

注意: 如果 transparency.enabled 设置为 manual,则只有带有以下注解的 TaskRuns 和 PipelineRuns 会上传到透明日志:

chains.tekton.dev/transparency-upload: "true"

使用 Fulcio 的无密钥签名

描述支持的值默认值
signers.x509.fulcio.enabled是否启用来自 fulcio 的自动证书。"true", "false""false"
signers.x509.fulcio.address启用时请求证书的 Fulcio 地址。"https://fulcio.sigstore.dev"
signers.x509.fulcio.issuer预期的 OIDC 发行者。"https://oauth2.sigstore.dev/auth"
signers.x509.fulcio.provider请求 ID 令牌的提供者"google", "spiffe", "github", "filesystem"未设置时将尝试所有提供者。
signers.x509.identity.token.file包含 ID 令牌的文件路径。
signers.x509.tuf.mirror.urlTUF 服务器 URL。期望存在 $TUF_URL/root.json。"https://sigstore-tuf-root.storage.googleapis.com"

参考资料