slsa-framework/slsa-verifier

GitHub: slsa-framework/slsa-verifier

一个用于验证软件制品来源(Provenance)的 CLI 工具,确保其符合 SLSA 框架标准且未被篡改。

Stars: 318 | Forks: 63

# SLSA 来源验证 [![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/slsa-framework/slsa-verifier/badge)](https://api.securityscorecards.dev/projects/github.com/slsa-framework/slsa-verifier) [![OpenSSF 最佳实践](https://bestpractices.coreinfrastructure.org/projects/6729/badge)](https://bestpractices.coreinfrastructure.org/projects/6729) [![Go 报告卡](https://goreportcard.com/badge/github.com/slsa-framework/slsa-verifier)](https://goreportcard.com/report/github.com/slsa-framework/slsa-verifier) [![Slack](https://img.shields.io/static/v1?label=openssf.slack.com&message=%23slsa-tooling&color=4A154B&logo=slack)](https://slack.openssf.org/) [![SLSA 3](https://slsa.dev/images/gh-badge-level3.svg)](https://slsa.dev) - [概述](#overview) - [什么是 SLSA?](#what-is-slsa) - [什么是 provenance?](#what-is-provenance) - [什么是 slsa-verifier?](#what-is-slsa-verifier) - [安装](#installation) - [从源码编译](#compilation-from-source) - [选项 1:通过 go 安装](#option-1-install-via-go) - [选项 2:手动编译](#option-2-compile-manually) - [在 GitHub Actions 上使用安装程序 Action](#use-the-installer-action-on-github-actions) - [下载二进制文件](#download-the-binary) - [在 macOS 上使用 Homebrew](#use-homebrew-on-macos) - [可用选项](#available-options) - [选项列表](#option-list) - [选项详情](#option-details) - [GitHub 构建器的验证](#verification-for-github-builders) - [Artifacts (构件)](#artifacts) - [容器](#containers) - [verify-image 命令](#the-verify-image-command) - [npm 包](#npm-packages) - [verify-npm-package 命令](#the-verify-npm-package-command) - [使用 SLSA3 Node.js builder 构建的 npm 包](#npm-packages-built-using-the-slsa3-nodejs-builder) - [使用 npm CLI 构建的 npm 包](#npm-packages-built-using-the-npm-cli) - [基于容器的构建](#container-based-builds) - [GitHub `attest-build-provenance` Attestations 的验证](#verification-for-github-attest-build-provenance-attestations) - [Google Cloud Build 的验证](#verification-for-google-cloud-build) - [Artifacts (构件)](#artifacts-1) - [容器](#containers-1) - [验证摘要证明 (VSA)](#verification-summary-attestations-vsa) - [注意事项](#caveats) - [Sigstore](#sigstore) - [主体资源描述符](#subject-resource-descriptors) - [已知问题](#known-issues) - [tuf: invalid key](#tuf-invalid-key) - [panic: assignment to entry in nil map](#panic-assignment-to-entry-in-nil-map) - [技术设计](#technical-design) - [博客文章](#blog-post) - [规范](#specifications) - [TOCTOU 攻击](#toctou-attacks) ## 概述 ### 什么是 SLSA? [软件构件供应链级别](https://slsa.dev),即 SLSA (salsa), 是一个安全框架,提供了一份标准和控制措施清单,旨在防止篡改, 提高完整性,并保护您的项目、企业或公司中的包和基础设施。 SLSA 定义了一组可渐进采用的级别,这些级别是根据 逐渐提高的合规性和保证来定义的。SLSA 级别就像一种通用 语言,用于讨论软件、供应链及其组件的安全性究竟如何。 ### 什么是 provenance? Provenance 是关于软件构件如何被创建的信息或元数据。 这可能包括关于使用了什么源代码、构建系统和 构建步骤的信息,以及由谁和为何发起构建。 Provenance 可用于确定您所使用的 软件构件的真实性和可信度。 作为框架的一部分,SLSA 定义了一种 [provenance 格式](https://slsa.dev/provenance/),可用于保存此 元数据。 ### 什么是 slsa-verifier? slsa-verifier 是一个用于验证由 CI/CD 构建器生成的 [SLSA provenance](https://slsa.dev/provenance/) 的工具。slsa-verifier 通过验证 provenance 上的加密签名来验证 provenance, 以确保它是由预期的构建器创建的。 然后,它验证各种值,例如构建器 ID、源代码 仓库、ref (分支或标签) 是否与预期值匹配。 它目前支持验证由以下生成的 provenance: 1. [SLSA generator](https://github.com/slsa-framework/slsa-github-generator) 2. [Google Cloud Build (GCB)](https://cloud.google.com/build/docs/securing-builds/view-build-provenance)。 ## 安装 您有两种安装验证器的选项。 ### 从源码编译 #### 选项 1:通过 go 安装 如果您想安装验证器,可以运行以下命令: ``` $ go install github.com/slsa-framework/slsa-verifier/v2/cli/slsa-verifier@v2.7.1 $ slsa-verifier ``` 诸如 [dependabot](https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuring-dependabot-version-updates) 或 [renovate](https://github.com/renovatebot/renovate) 之类的工具使用您项目的 go.mod 来识别 Go 依赖项的版本。 如果您在 CI 中安装验证器二进制文件,我们强烈建议您创建一个包含 slsa-verifier 作为依赖项的占位符 `go.mod`,以接收更新并保持二进制文件处于最新状态。请使用以下步骤: 1. 创建一个包含以下内容的 tooling/tooling_test.go 文件: ``` //go:build tools // +build tools package main import ( _ "github.com/slsa-framework/slsa-verifier/v2/cli/slsa-verifier" ) ``` 1. 在 tooling 目录中运行以下命令。(它将创建一个 go.sum 文件。) ``` $ go mod init -tooling $ go mod tidy ``` 1. 将 tooling 文件夹(包含 3 个文件 tooling_test.go、go.mod 和 go.sum)提交到仓库。 2. 要在 CI 中安装验证器,请运行以下命令: ``` $ cd tooling $ grep _ tooling_test.go | cut -f2 -d '"' | xargs -n1 -t go install ``` 或者,如果您的项目不依赖其他工具且仅使用 slsa-verifier,您可以改为运行以下命令: ``` $ cd tooling $ go install github.com/slsa-framework/slsa-verifier/v2/cli/slsa-verifier ``` #### 选项 2:手动编译 ``` $ git clone git@github.com:slsa-framework/slsa-verifier.git $ cd slsa-verifier && git checkout v2.7.1 $ go run ./cli/slsa-verifier ``` ### 在 GitHub Actions 上使用安装程序 Action 如果您需要安装验证器以在 GitHub workflow 中运行,请按照 [actions/installer/README.md](./actions/installer/README.md) 中的说明使用安装程序 Action。 ### 下载二进制文件 从 [https://github.com/slsa-framework/slsa-verifier/releases/tag/v2.7.1](https://github.com/slsa-framework/slsa-verifier/releases/tag/v2.7.1) 的最新版本下载二进制文件 下载 [SHA256SUM.md](https://github.com/slsa-framework/slsa-verifier/blob/main/SHA256SUM.md)。 验证校验和: ``` $ sha256sum -c --strict SHA256SUM.md slsa-verifier-linux-amd64: OK ``` ### 在 macOS 上使用 Homebrew 如果您使用的是 macOS 和 Homebrew,则可以使用此社区维护的 [formula](https://formulae.brew.sh/formula/slsa-verifier) 安装验证器。 ## 可用选项 我们目前支持构件验证(针对二进制 blob)和容器镜像。 ## 选项列表 以下是当前针对二进制 blob 和容器镜像支持的选项列表。请注意,签名验证是无缝处理的,无需开发人员操作公钥。有关公开用于验证 provenance 的选项的详细信息,请参阅 [可用选项](#available-options)。 ``` $ git clone git@github.com:slsa-framework/slsa-verifier.git $ go run ./cli/slsa-verifier/ verify-artifact --help Verifies SLSA provenance on artifact blobs given as arguments (assuming same provenance) Usage: slsa-verifier verify-artifact [flags] artifact [artifact..] Flags: --build-workflow-input map[] [optional] a workflow input provided by a user at trigger time in the format 'key=value'. (Only for 'workflow_dispatch' events on GitHub Actions). (default map[]) --builder-id string [optional] the unique builder ID who created the provenance -h, --help help for verify-artifact --print-provenance [optional] print the verified provenance to stdout --provenance-path string path to a provenance file --source-branch string [optional] expected branch the binary was compiled from --source-tag string [optional] expected tag the binary was compiled from --source-uri string expected source repository that should have produced the binary, e.g. github.com/some/repo --source-versioned-tag string [optional] expected version the binary was compiled from. Uses semantic version to match the tag ``` 可以将多个构件传递给 `verify-artifact`。只要它们都被同一个 provenance 文件覆盖,验证就会成功。 ### 选项详情 以下选项可用: | 选项 | 描述 | 支持 | | ---------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | | `source-uri` | 期望一个源,例如 `github.com/org/repo`。 | 所有构建器 | | `source-branch` | 期望一个 `branch` (分支),如 `main` 或 `dev`。并非所有 GitHub Workflow 触发器都支持。 | [GitHub builders](https://github.com/slsa-framework/slsa-github-generator#generation-of-provenance) | | `source-tag` | 期望一个 `tag` (标签),如 `v0.0.1`。验证用于创建二进制文件的确切标签。支持新的 [tag](https://github.com/slsa-framework/example-package/blob/main/.github/workflows/e2e.go.tag.main.config-ldflags-assets-tag.slsa3.yml#L5) 和 [release](https://github.com/slsa-framework/example-package/blob/main/.github/workflows/e2e.go.release.main.config-ldflags-assets-tag.slsa3.yml) 触发器。 | [GitHub builders](https://github.com/slsa-framework/slsa-github-generator#generation-of-provenance) | | `source-versioned-tag` | 类似于 `tag`,但使用语义版本控制进行验证。 | [GitHub builders](https://github.com/slsa-framework/slsa-github-generator#generation-of-provenance) | | `build-workflow-input` | 期望键值对(如 `key=value`)以匹配 GitHub Actions `workflow_dispatch` 触发器的 [inputs](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#onworkflow_dispatchinputs)。 | [GitHub builders](https://github.com/slsa-framework/slsa-github-generator#generation-of-provenance) | ## GitHub 构建器的验证 ### Artifacts (构件) 要验证构件,请运行以下命令: ``` $ slsa-verifier verify-artifact slsa-test-linux-amd64 \ --provenance-path slsa-test-linux-amd64.intoto.jsonl \ --source-uri github.com/slsa-framework/slsa-test \ --source-tag v1.0.3 Verified signature against tlog entry index 3189970 at URL: https://rekor.sigstore.dev/api/v1/log/entries/206071d5ca7a2346e4db4dcb19a648c7f13b4957e655f4382b735894059bd199 Verified build using builder https://github.com/slsa-framework/slsa-github-generator/.github/workflows/builder_go_slsa3.yml@refs/tags/v1.2.0 at commit 5bb13ef508b2b8ded49f9264d7712f1316830d10 PASSED: Verified SLSA provenance ``` 已验证的 in-toto 语句可以使用 `--print-provenance` 标志写入 stdout,以便通过管道传输到策略引擎。 `--source-uri` 标志仅支持 GitHub URI。不应指定标签,即使 provenance 是在某个标签下构建的。如果您打算进行源版本验证,可以使用 `--source-tag` 来验证发布标签。对于 commit SHA 验证,请使用 `--print-provenance` 并检查配置源或材料的 commit SHA。 通过在同一命令行中将多个构件作为参数传递,可以在同一命令中验证从同一 GitHub 构建器构建的多个构件: ``` $ slsa-verifier verify-artifact \ --provenance-path /tmp/demo/multiple.intoto.jsonl \ --source-uri github.com/mihaimaruseac/example \ /tmp/demo/fib /tmp/demo/hello Verified signature against tlog entry index 9712459 at URL: https://rekor.sigstore.dev/api/v1/log/entries/24296fb24b8ad77a1544828b67bb5a2335f7e0d01c504a32ceb6f3a8814ed12c8f1b222d308bd9e8 Verified build using builder https://github.com/slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@refs/tags/v1.4.0 at commit 11fab87c5ee6f46c6f5e68f6c5378c62ce1ca77c Verifying artifact /tmp/demo/fib: PASSED Verified signature against tlog entry index 9712459 at URL: https://rekor.sigstore.dev/api/v1/log/entries/24296fb24b8ad77a1544828b67bb5a2335f7e0d01c504a32ceb6f3a8814ed12c8f1b222d308bd9e8 Verified build using builder https://github.com/slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@refs/tags/v1.4.0 at commit 11fab87c5ee6f46c6f5e68f6c5378c62ce1ca77c Verifying artifact /tmp/demo/hello: PASSED PASSED: Verified SLSA provenance ``` 唯一的要求是 provenance 文件覆盖命令行中作为参数传递的所有构件(即,它们是 provenance 文件中 `subject` 字段的子集)。 ### 容器 要验证容器镜像,您需要通过提供其摘要来传递一个 _不可变_ 的容器镜像名称,以避免 [TOCTOU 攻击](#toctou-attacks)。 #### verify-image 命令 ``` $ slsa-verifier verify-image --help Verifies SLSA provenance for an image Usage: slsa-verifier verify-image [flags] tarball Flags: --build-workflow-input map[] [optional] a workflow input provided by a user at trigger time in the format 'key=value'. (Only for 'workflow_dispatch' events on GitHub Actions). (default map[]) --builder-id string [optional] the unique builder ID who created the provenance -h, --help help for verify-npm-package --print-provenance [optional] print the verified provenance to stdout --provenance-path string path to a provenance file --provenance-repository string [optional] provenance repository when stored different from image repository. When set, overrides COSIGN_REPOSITORY environment variable --source-branch string [optional] expected branch the binary was compiled from --source-tag string [optional] expected tag the binary was compiled from --source-uri string expected source repository that should have produced the binary, e.g. github.com/some/repo --source-versioned-tag string [optional] expected version the binary was compiled from. Uses semantic version to match the tag ``` 首先设置镜像名称: ``` IMAGE=ghcr.io/ianlewis/actions-test:v0.0.86 ``` 使用 [crane](https://github.com/google/go-containerregistry/blob/main/cmd/crane/doc/crane.md) 命令获取容器的摘要,_无需_ 拉取它: ``` IMAGE="${IMAGE}@"$(crane digest "${IMAGE}") ``` 要验证容器镜像,请运行以下命令。请注意,要使用 `ghcr.io`,您还需要设置 `GH_TOKEN` 环境变量。 ``` slsa-verifier verify-image "$IMAGE" \ --source-uri github.com/ianlewis/actions-test \ --source-tag v0.0.86 ``` 您应该会在输出中看到验证通过。 ``` Verified build using builder https://github.com/slsa-framework/slsa-github-generator/.github/workflows/generator_container_slsa3.yml@refs/tags/v1.4.0 at commit d9be953dd17e7f20c7a234ada668f9c8c4aaafc3 PASSED: Verified SLSA provenance ``` ### npm 包 npm 包的验证目前是一项实验性功能。 有关 npm attestations 的更多详细信息,请参阅 [docs/npm.md](./docs/npm.md) #### verify-npm-package 命令 ``` $ slsa-verifier verify-npm-package --help Verifies SLSA provenance for an npm package tarball [experimental] Usage: slsa-verifier verify-npm-package [flags] tarball Flags: --attestations-path string path to a file containing the attestations --build-workflow-input map[] [optional] a workflow input provided by a user at trigger time in the format 'key=value'. (Only for 'workflow_dispatch' events on GitHub Actions). (default map[]) --builder-id string [optional] the unique builder ID who created the provenance -h, --help help for verify-npm-package --package-name string the package name --package-version string the package version --print-provenance [optional] print the verified provenance to stdout --source-branch string [optional] expected branch the binary was compiled from --source-tag string [optional] expected tag the binary was compiled from --source-uri string expected source repository that should have produced the binary, e.g. github.com/some/repo --source-versioned-tag string [optional] expected version the binary was compiled from. Uses semantic version to match the tag ``` #### 使用 SLSA3 Node.js builder 构建的 npm 包 本节介绍如何验证使用 SLSA Build L3 [Node.js builder](https://github.com/slsa-framework/slsa-github-generator/blob/main/internal/builders/nodejs/README.md) 构建的包。 要验证 npm 包,首先下载包 tarball 和 attestations。 ``` curl -Sso attestations.json $(npm view @ianlewis/actions-test@0.1.127 --json | jq -r '.dist.attestations.url') && \ curl -Sso actions-test.tgz "$(npm view @ianlewis/actions-test@0.1.127 --json | jq -r '.dist.tarball')" ``` 然后,您可以通过运行以下命令来验证包: ``` SLSA_VERIFIER_EXPERIMENTAL=1 slsa-verifier verify-npm-package actions-test.tgz \ --attestations-path attestations.json \ --builder-id "https://github.com/slsa-framework/slsa-github-generator/.github/workflows/builder_nodejs_slsa3.yml" \ --package-name "@ianlewis/actions-test" \ --package-version 0.1.127 \ --source-uri github.com/ianlewis/actions-test ``` 已验证的 in-toto 语句可以使用 `--print-provenance` 标志写入 stdout,以便通过管道传输到策略引擎。 `--source-uri` 标志仅支持 GitHub URI。不应指定标签,即使 provenance 是在某个标签下构建的。如果您打算进行源版本验证,可以使用 `--source-tag` 来验证发布标签,并使用 `--package-version` 来验证包版本。对于 commit SHA 验证,请使用 `--print-provenance` 并检查配置源或材料的 commit SHA。 #### 使用 npm CLI 构建的 npm 包 本节介绍如何验证在 GitHub 上使用 npm CLI 构建的包。 要验证 npm 包,首先下载包 tarball 和 attestations。 ``` curl -Sso attestations.json $(npm view @ianlewis/actions-test@0.1.132 --json | jq -r '.dist.attestations.url') && \ curl -Sso actions-test.tgz "$(npm view @ianlewis/actions-test@0.1.132 --json | jq -r '.dist.tarball')" ``` 然后,您可以通过运行以下命令来验证包: ``` SLSA_VERIFIER_EXPERIMENTAL=1 slsa-verifier verify-npm-package actions-test.tgz \ --attestations-path attestations.json \ --builder-id "https://github.com/actions/runner/github-hosted" \ --package-name "@ianlewis/actions-test" \ --package-version 0.1.132 \ --source-uri github.com/ianlewis/actions-test ``` 如果包是使用自托管 runner 构建的,请将 "https://github.com/actions/runner/github-hosted" 替换为 "https://github.com/actions/runner/self-hosted"。 已验证的 in-toto 语句可以使用 `--print-provenance` 标志写入 stdout,以便通过管道传输到策略引擎。 `--source-uri` 标志仅支持 GitHub URI。不应指定标签,即使 provenance 是在某个标签下构建的。如果您打算进行源版本验证,可以使用 `--source-tag` 来验证发布标签,并使用 `--package-version` 来验证包版本。对于 commit SHA 验证,请使用 `--print-provenance` 并检查配置源或材料的 commit SHA。 ### 基于容器的构建 要验证由 [Container-based builder](https://github.com/slsa-framework/slsa-github-generator/blob/main/internal/builders/docker/README.md) 生成的构件,您首先需要运行以下命令来验证 provenance,就像上面针对一般 [Artifacts](#artifacts) 的部分一样: ``` $ slsa-verifier verify-artifact slsa-test-linux-amd64 \ --provenance-path slsa-test-linux-amd64.sigstore \ --source-uri github.com/slsa-framework/slsa-test \ --source-tag v1.0.3 Verified signature against tlog entry index 3189970 at URL: https://rekor.sigstore.dev/api/v1/log/entries/206071d5ca7a2346e4db4dcb19a648c7f13b4957e655f4382b735894059bd199 Verified build using builder https://github.com/slsa-framework/slsa-github-generator/.github/workflows/builder_container-based_slsa3.yml@refs/tags/v1.7.0 at commit 5bb13ef508b2b8ded49f9264d7712f1316830d10 PASSED: Verified SLSA provenance ``` 输入 provenance 是一个 `.sigstore` 文件,它是一个 [Sigstore bundle](https://github.com/sigstore/protobuf-specs/blob/main/protos/sigstore_bundle.proto#L63),其中包含包含 SLSA provenance 的 in-toto 语句以及验证材料。bundle 中包含的已验证 in-toto 语句可以使用 `--print-provenance` 标志写入 stdout,以便通过管道传输到策略引擎。 要验证用于生成构件的用户指定构建器镜像,请使用以下命令提取构建器镜像并在策略引擎中进行验证: ``` $ cat verifier-statement.intoto | jq -r '.predicate.buildDefinition.externalParameters.builderImage' ``` 构建器镜像使用 [in-toto Resource Descriptor](https://github.com/in-toto/attestation/blob/main/spec/v1/resource_descriptor.md) 进行描述。 如果构建是可重现的,您还可以使用内部 [docker CLI 工具](https://github.com/slsa-framework/slsa-github-generator/tree/main/internal/builders/docker#the-verify-command) 通过使用提供的 provenance 重新构建构件来验证构件。 ## GitHub `attest-build-provenance` Attestations 的验证 Attestations 由利用 [attest-build-proance](https://github.com/actions/attest-build-provenance) action 的构建器生成。 目前仅限于使用以下 builder-ids 构建的构件: - `github.com/bazel-contrib/.github/blob/master/.github/workflows/release_ruleset.yaml` - `github.com/bazel-contrib/publish-to-bcr/.github/workflows/publish.yaml` ### `verify-github-attestation` 命令 ``` $ slsa-verifier verify-github-attestation --help Verifies SLSA provenance for a GitHub attestation Usage: slsa-verifier verify-github-attestation [flags] module-file Flags: --attestation-path string path to an attestation file --builder-id string the unique builder ID who created the provenance -h, --help help for verify-github-attestation --print-attestation [optional] print the verified attestation to stdout --source-uri string expected source repository that should have produced the binary, e.g. github.com/some/repo ``` 首先下载构件和 attestation(在本例中来自 bazel central registry) ``` $ curl -sSO https://bcr.bazel.build/modules/aspect_rules_lint/1.3.4/MODULE.bazel $ curl -sSO https://bcr.bazel.build/modules/aspect_rules_lint/1.3.4/MODULE.bazel.intoto.jsonl ``` 验证 attestation ``` $ slsa-verifier verify-github-attestation --source-uri github.com/aspect-build/rules_lint --builder-id https://github.com/bazel-contrib/publish-to-bcr/.github/workflows/publish.yaml --attestation-path MODULE.bazel.intoto.jsonl MODULE.bazel Verified build using builder "https://github.com/bazel-contrib/publish-to-bcr/.github/workflows/publish.yaml@refs/tags/v0.0.1" at commit 1e1a949147d641428dac19e77f044b782f5941fd Verifying artifact MODULE.bazel: PASSED PASSED: SLSA verification passed ``` ## Google Cloud Build 的验证 ### Artifacts (构件) 此项正在进行中,目前不受支持。 ### 容器 要验证容器镜像,您需要通过提供其摘要来传递一个 _不可变_ 的容器镜像名称,以避免 [TOCTOU 攻击](#toctou-attacks)。 首先设置镜像名称: ``` IMAGE=laurentsimon/slsa-gcb-v0.3:test ``` 下载 provenance: ``` gcloud artifacts docker images describe $IMAGE --format json --show-provenance > provenance.json ``` 使用 [crane](https://github.com/google/go-containerregistry/blob/main/cmd/crane/doc/crane.md) 命令获取容器的摘要,_无需_ 拉取它: ``` IMAGE="${IMAGE}@"$(crane digest "${IMAGE}") ``` 验证镜像: ``` slsa-verifier verify-image "$IMAGE" \ --provenance-path provenance.json \ --source-uri github.com/laurentsimon/gcb-tests \ --builder-id=https://cloudbuild.googleapis.com/GoogleHostedWorker ``` 您应该会在输出中看到验证通过。 ``` PASSED: Verified SLSA provenance ``` 已验证的 in-toto 语句可以使用 `--print-provenance` 标志写入 stdout,以便通过管道传输到策略引擎。 请注意,当使用 Cloud Build [GitHub 触发器](https://cloud.google.com/build/docs/automating-builds/github/build-repos-from-github) 启用构建时,`--source-uri` 支持 GitHub 仓库 URI,如 `github.com/$OWNER/$REPO`。否则,构建 provenance 将包含用于托管源文件的 Cloud Storage 存储桶的名称,通常格式为 `gs://[PROJECT_ID]_cloudbuild/source`(请参阅 [Running build](https://cloud.google.com/build/docs/running-builds/submit-build-via-cli-api#running_builds))。我们建议使用 GitHub 触发器,以便保留源 provenance 并验证源来自预期的版本控制仓库。您 _可以_ 匹配完全限定的 tar,如 `gs://[PROJECT_ID]_cloudbuild/source/1665165360.279777-955d1904741e4bbeb3461080299e929a.tgz`。 ## 验证摘要证明 (VSA) 我们支持 [验证](https://slsa.dev/spec/v1.1/verification_summary#how-to-verify) VSA。 我们允许传递多个 `--subject-digest` cli 选项,而不是将文件路径作为参数传递,以适应非简单文件的主题。 verify-vsa 命令 ``` $ slsa-verifier verify-vsa --help Verifies SLSA VSAs for the given subject-digests Usage: slsa-verifier verify-vsa [flags] subject-digest [subject-digest...] Flags: --attestation-path string path to a file containing the attestation -h, --help help for verify-vsa --print-attestation [optional] print the contents of attestation to stdout --public-key-id string [optional] the ID of the public key, defaults to the SHA256 digest of the base64-encoded public key --public-key-path string path to a public key file --resource-uri string the resource URI to be verified --subject-digest stringArray the digests to be verified. Pass multiple digests by repeating the flag. e.g. --subject-digest : --subject-digest : --verified-level stringArray [optional] the levels of verification to be performed. Pass multiple digests by repeating the flag, e.g., --verified-level SLSA_BUILD_LEVEL_2 --verified-level FEDRAMP_LOW' --verifier-id string the unique verifier ID who created the attestation ``` 要验证 VSA,请像这样调用 ``` $ slsa-verifier verify-vsa \ --subject-digest gce_image_id:8970095005306000053 \ --attestation-path ./cli/slsa-verifier/testdata/vsa/gce/v1/gke-gce-pre.bcid-vsa.jsonl \ --verifier-id https://bcid.corp.google.com/verifier/bcid_package_enforcer/v0.1 \ --resource-uri gce_image://gke-node-images:gke-12615-gke1418000-cos-101-17162-463-29-c-cgpv1-pre \ --verified-level BCID_L1 \ --verified-level SLSA_BUILD_LEVEL_2 \ --public-key-path ./cli/slsa-verifier/testdata/vsa/gce/v1/vsa_signing_public_key.pem \ --public-key-id keystore://76574:prod:vsa_signing_public_key \ --print-attestation ``` 对于多个主体,请使用: ``` --subject-digest sha256:abc123 --subject-digest sha256:xyz456 ``` ### 注意事项 #### Sigstore 此支持尚不适用于包装在 Sigstore bundle 中的 VSA,仅适用于简单的 DSSE envelope。 因此,我们允许用户传入公钥。 请注意,如果 DSSE Envelope `signatures` 指定的 `keyid` 不是密钥的无填充 base64 编码 sha256 哈希,例如 `sha256:abc123...`(而不是众所周知的标识符,例如 `my-kms:prod-vsa-key`),那么您必须提供 `--public-key-id` cli 选项。 #### 主体资源描述符 根据 slsa.dev 的 [VSA schema](https://slsa.dev/spec/v1.1/verification_summary#schema),我们仅支持主体的 `Name` 和 `Digest`,而不支持完整的 in_toto [Statement](https://pkg.go.dev/github.com/in-toto/attestation/go/v1#Statement) 的 [ResourceDescriptor](https://github.com/in-toto/attestation/blob/main/spec/v1/resource_descriptor.md)。 ## 已知问题 ### tuf: 无效密钥 此问题仅在验证 GitHub Actions 生成的 provenance 时发生。 **受影响的版本:** v1.3.0-v1.3.1, v1.2.0-v1.2.1, v1.1.0-v1.1.2, v1.0.0-v1.0.4 `slsa-verifier` 将失败并出现以下错误: ``` FAILED: SLSA verification failed: could not find a matching valid signature entry: got unexpected errors unable to initialize client, local cache may be corrupt: tuf: invalid key: unable to fetch Rekor public keys from TUF repository ``` 此问题由 [issue #325](https://github.com/slsa-framework/slsa-verifier/issues/325) 跟踪。您 _必须_ 更新到每个次要版本的最新补丁版本才能修复此问题。 ### panic: 赋值给 nil map 中的条目 此问题仅在针对 workflow 输入验证 provenance 时发生。 **受影响的版本:** v2.0.0 `slsa-verifier` 将失败并出现以下错误: ``` panic: assignment to entry in nil map ``` 此问题已由 [PR #379](https://github.com/slsa-framework/slsa-verifier/pull/379) 修复。您 _必须_ 更新到每个次要版本的最新补丁版本才能修复此问题。 ## 技术设计 ### 博客文章 在 [此处](https://security.googleblog.com/2022/04/improving-software-supply-chain.html) 查找我们的博客文章系列。 ### 规范 如需更深入的技术探讨,请阅读 [SPECIFICATIONS.md](https://github.com/slsa-framework/slsa-github-generator/blob/main/SPECIFICATIONS.md)。 ### TOCTOU 攻击 正如 [Wikipedia](https://en.wikipedia.org/wiki/Time-of-check_to_time-of-use) 上所解释的,“检查时间到使用时间 (TOCTOU) 是一类软件错误,由涉及检查系统某部分状态及使用该检查结果的竞态条件引起”。 在 provenance 验证的上下文中,假设您验证一个通过 _可变_ 镜像 `image:tag` 引用的容器。验证成功并验证相应的哈希值为 `sha256:abcdef...`。验证后,您使用 `docker run image:tag` 拉取并运行镜像。攻击者可能已在验证步骤和运行步骤之间更改了镜像。为了减轻此攻击,我们要求用户始终传递给他们验证的构件的 _不可变_ 引用。
标签:DevSecOps, EVTX分析, GitHub Actions, Golang, JSONLines, meg, NPM包安全, OpenSSF, SLSA, Web截图, 上游代理, 代码签名, 信息安全, 安全编程, 完整性校验, 容器安全, 日志审计, 来源验证, 构建合规, 自动笔记, 软件工件, 零信任