Chains 配置

概述

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 中的配置发生变化,或者其他原因触发 reconciliation 时,chains-config ConfigMap 中的配置将被覆盖。

TIP

不过,某些高级配置只支持在 chains-config ConfigMap 中配置,由于 validation 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

提示: 布尔值是字符串,例如 "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: {}

提示: 布尔值使用原始类型,例如 truefalse

YAML 字段说明:

  • spec.chain:此部分包含 Chains 的配置。
    • disabled:是否禁用 Chains。
      • 这是 TektonConfig 独有的配置,在 TektonChains 中不存在。
    • generateSigningSecret:是否生成签名 secret。
      • 这是 TektonConfig 独有的配置,在 TektonChains 中不存在。
    • controllerEnvs:Tekton Chains controller 的环境变量。
      • 这是 TektonConfig 独有的配置,在 TektonChains 中不存在。
      • name:环境变量名称。
      • value:环境变量值。
    • options:Tekton Chains controller 的选项。
      • 这是 TektonConfig 独有的配置,在 TektonChains 中不存在。
      • deployments.tekton-chains-controller:Tekton Chains controller 的部署选项。
        • spec.template.spec.containers.env.SIGSTORE_ID_TOKEN:Tekton Chains controller 的 ID token。
      • 更详细的支持信息可以在 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 配置

KeyDescriptionSupported ValuesDefault
artifacts.taskrun.format存储 TaskRun payload 的格式。in-toto, slsa/v1, slsa/v2alpha3, slsa/v2alpha4in-toto
artifacts.taskrun.storage用于存储 TaskRun 签名的后端。可以使用以逗号分隔的列表指定多个后端("tekton,oci")。要禁用 TaskRun artifact 输入,请输入空字符串("")。tekton, oci, gcs, docdb, grafeas, archivistatekton
artifacts.taskrun.signer用于对 TaskRun payload 进行签名的签名后端。x509, kmsx509

说明

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

PipelineRun 配置

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

KeyDescriptionSupported ValuesDefault
artifacts.pipelinerun.format存储 PipelineRun payload 的格式。in-toto, slsa/v1, slsa/v2alpha3, slsa/v2alpha4in-toto
artifacts.pipelinerun.storage用于存储 PipelineRun 签名的后端。可以使用以逗号分隔的列表指定多个后端("tekton,oci")。要禁用 PipelineRun artifact 输入,请输入空字符串("")。tekton, oci, gcs, docdb, grafeas, archivistatekton
artifacts.pipelinerun.signer用于对 PipelineRun payload 进行签名的签名后端。x509, kmsx509
artifacts.pipelinerun.enable-deep-inspection此布尔选项用于配置 Chains 是否应检查子 taskrun,以捕获 pipelinerun 中的输入/输出。"false" 表示 Chains 只检查 pipeline 级别的结果,而 "true" 表示 Chains 同时检查 pipeline 级别和 task 级别的结果。"true", "false""false"
  • 如果存储为 oci,证明材料将与存储的 OCI artifact 本身一起存储。更多信息请参见 cosign documentation
  • 如果存储为 tekton,证明材料将存储在 Tekton PipelineRun 的 annotations 中。

OCI 配置

KeyDescriptionSupported ValuesDefault
artifacts.oci.format存储 OCI payload 的格式。simplesigningsimplesigning
artifacts.oci.storage用于存储 OCI 签名的后端。可以使用以逗号分隔的列表指定多个后端("oci,tekton")。要禁用 OCI artifact 输入,请输入空字符串("")。tekton, ocioci
artifacts.oci.signer用于对 OCI payload 进行签名的签名后端。x509, kmsx509
  • 如果存储为 oci,证明材料将与存储的 OCI artifact 本身一起存储。更多信息请参见 cosign documentation
  • 如果存储为 tekton,证明材料将存储在 Tekton TaskRunPipelineRun 的 annotations 中。

存储配置

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

KeyDescriptionSupported ValuesDefault
storage.oci.repository用于存储 OCI 签名和证明材料的 OCI repository如果未定义该值,并且 artifacts.{oci,taskrun}.storage 中包含 oci 存储,则证明材料将与存储的 OCI artifact 本身一起存储。(GCP 上的示例)定义此值后,OCI bundle 将存储在指定位置,而不是与 image 一起存储。更多信息请参见 cosign documentation。
storage.oci.repository.insecure连接 OCI repository 时是否使用不安全连接true, falsefalse

说明

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

Sigstore 特性配置

Transparency Log

KeyDescriptionSupported ValuesDefault
transparency.enabled是否启用透明日志。"true", "false""false"
transparency.url透明日志的 URL。"https://rekor.sigstore.dev"

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

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

使用 Fulcio 的无密钥签名

KeyDescriptionSupported ValuesDefault
signers.x509.fulcio.enabled是否启用来自 fulcio 的自动证书。"true", "false""false"
signers.x509.fulcio.address如果启用,则用于请求证书的 Fulcio 地址。"https://fulcio.sigstore.dev"
signers.x509.fulcio.issuer预期的 OIDC issuer。"https://oauth2.sigstore.dev/auth"
signers.x509.fulcio.provider用于请求 ID Token 的 provider"google", "spiffe", "github", "filesystem"Unset,会依次尝试每个 provider。
signers.x509.identity.token.file包含 ID Token 的文件路径。
signers.x509.tuf.mirror.urlTUF server URL。预期存在 $TUF_URL/root.json。"https://sigstore-tuf-root.storage.googleapis.com"

参考