actions/attest-build-provenance
為工作流程工件產生簽章的建置來源證明。由 @actions/attest 套件內部驅動。
證明使用 in-toto 格式將某些主題(命名工件及其摘要)綁定到 SLSA 建構來源謂詞。
使用短期 Sigstore 頒發的簽名證書為證明產生可驗證的簽名。如果啟動 GitHub Actions 工作流程的儲存庫是公共的,則 Sigstore 的公共物品實例將用於產生證明簽章。如果儲存庫是私有/內部的,它將使用 GitHub 私有 Sigstore 實例。
建立並簽署證明後,它將上傳到 GH 證明 API 並與啟動工作流程的儲存庫關聯。
可以使用 GitHub CLI 中的attestation
指令來驗證證明。
有關工件證明的更多信息,請參閱使用工件證明來確定構建的來源。
在 GitHub Actions 工作流程中,該工作流程建立了一些您想要證明的工件:
確保設定以下權限:
permissions :
id-token : write
attestations : write
id-token
權限使操作能夠建立請求 Sigstore 簽章憑證所需的 OIDC 令牌。 attestations
權限對於持久證明是必要的。
建置工件後,將以下內容新增至您的工作流程:
- uses : actions/attest-build-provenance@v1
with :
subject-path : ' <PATH TO ARTIFACT> '
subject-path
參數應標識您要為其產生證明的工件。
參見action.yml
- uses : actions/attest-build-provenance@v1
with :
# Path to the artifact serving as the subject of the attestation. Must
# specify exactly one of "subject-path" or "subject-digest". May contain a
# glob pattern or list of paths (total subject count cannot exceed 2500).
subject-path :
# SHA256 digest of the subject for the attestation. Must be in the form
# "sha256:hex_digest" (e.g. "sha256:abc123..."). Must specify exactly one
# of "subject-path" or "subject-digest".
subject-digest :
# Subject name as it should appear in the attestation. Required unless
# "subject-path" is specified, in which case it will be inferred from the
# path.
subject-name :
# Whether to push the attestation to the image registry. Requires that the
# "subject-name" parameter specify the fully-qualified image name and that
# the "subject-digest" parameter be specified. Defaults to false.
push-to-registry :
# Whether to attach a list of generated attestations to the workflow run
# summary page. Defaults to true.
show-summary :
# The GitHub token used to make authenticated API requests. Default is
# ${{ github.token }}
github-token :
姓名 | 描述 | 例子 |
---|---|---|
bundle-path | 包含產生的證明的文件的絕對路徑 | /tmp/attestation.jsonl |
證明以 JSON 序列化 Sigstore 捆綁包格式儲存。
如果同時證明多個主題,則每個證明將在單獨的行上寫入輸出檔案(使用 JSON 行格式)。
同時認證的科目不得超過2500個。主題將按 50 個批次進行處理。
對於基本用例,只需將attest-build-provenance
操作新增至您的工作流程中,並提供您要為其產生證明的工件的路徑。
name : build-attest
on :
workflow_dispatch :
jobs :
build :
permissions :
id-token : write
contents : read
attestations : write
steps :
- name : Checkout
uses : actions/checkout@v4
- name : Build artifact
run : make my-app
- name : Attest
uses : actions/attest-build-provenance@v1
with :
subject-path : ' ${{ github.workspace }}/my-app '
如果您要產生多個工件,則可以透過在subject-path
輸入中使用通配符為每個工件產生來源證明。
- uses : actions/attest-build-provenance@v1
with :
subject-path : ' dist/**/my-bin-* '
有關受支援的通配符以及行為和文檔,請參閱@actions/glob,它在內部用於搜尋文件。
或者,您可以使用逗號或換行符號分隔清單明確列出多個主題:
- uses : actions/attest-build-provenance@v1
with :
subject-path : ' dist/foo, dist/bar '
- uses : actions/attest-build-provenance@v1
with :
subject-path : |
dist/foo
dist/bar
使用容器映像時,您可以使用subject-name
和subject-digest
輸入呼叫操作。
如果您想要使用push-to-registry
選項將證明發佈到容器註冊表,則subject-name
指定完全限定的映像名稱(例如“ghcr.io/user/app”或“acme. azurecr.io/user/app”) 。不要將標籤作為圖像名稱的一部分 - 所證明的特定圖像由提供的摘要標識。
證明捆綁包根據 Cosign Bundle 規範儲存在 OCI 註冊表中。
注意:推送到 Docker Hub 時,請使用「index.docker.io」作為映像名稱的登錄部分。
name : build-attested-image
on :
push :
branches : [main]
jobs :
build :
runs-on : ubuntu-latest
permissions :
id-token : write
packages : write
contents : read
attestations : write
env :
REGISTRY : ghcr.io
IMAGE_NAME : ${{ github.repository }}
steps :
- name : Checkout
uses : actions/checkout@v4
- name : Login to GitHub Container Registry
uses : docker/login-action@v3
with :
registry : ${{ env.REGISTRY }}
username : ${{ github.actor }}
password : ${{ secrets.GITHUB_TOKEN }}
- name : Build and push image
id : push
uses : docker/[email protected]
with :
context : .
push : true
tags : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
- name : Attest
uses : actions/attest-build-provenance@v1
id : attest
with :
subject-name : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
subject-digest : ${{ steps.push.outputs.digest }}
push-to-registry : true