SLSA 定义

BuildKit 支持 它运行。

BuildKit 生成的 provenance 格式由 SLSA Provenance 格式定义。

本页描述了 BuildKit 如何填充每个字段,以及该字段是否获取 生成证明时包含mode=minmode=max.

builder.id

对应于SLSAbuilder.id.

包含在mode=minmode=max.

builder.id字段设置为内部版本的 URL(如果可用)。

    "builder": {
      "id": "https://github.com/docker/buildx/actions/runs/3709599520"
    },

可以使用builder-idattestation 参数。

buildType

对应于SLSAbuildType.

包含在mode=minmode=max.

buildTypefield 设置为https://mobyproject.org/buildkit@v1可以是 用于确定 Provenance 内容的结构。

    "buildType": "https://mobyproject.org/buildkit@v1",

invocation.configSource

对应于SLSAinvocation.configSource.

包含在mode=minmode=max.

描述初始化构建的配置。

    "invocation": {
      "configSource": {
        "uri": "https://github.com/moby/buildkit.git#refs/tags/v0.11.0",
        "digest": {
          "sha1": "4b220de5058abfd01ff619c9d2ff6b09a049bea0"
        },
        "entryPoint": "Dockerfile"
      },
      ...
    },

对于从远程上下文(如 Git 或 HTTP URL)初始化的构建,此 object 定义上下文 URL 及其在uridigest领域。 对于使用本地前端(如 Dockerfile)的构建,entryPointfield 定义路径 对于初始化构建的前端文件 (filenamefrontend 选项)。

invocation.parameters

对应于SLSAinvocation.parameters.

部分包含在mode=min.

描述传递给 build 的 build 输入。

    "invocation": {
      "parameters": {
        "frontend": "gateway.v0",
        "args": {
          "build-arg:BUILDKIT_CONTEXT_KEEP_GIT_DIR": "1",
          "label:FOO": "bar",
          "source": "docker/dockerfile-upstream:master",
          "target": "release"
        },
        "secrets": [
          {
            "id": "GIT_AUTH_HEADER",
            "optional": true
          },
          ...
        ],
        "ssh": [],
        "locals": []
      },
      ...
    },

以下字段包含在两者中mode=minmode=max:

  • locals列出生成中使用的任何本地源,包括生成 context 和 frontend 文件。

  • frontend定义用于构建的 BuildKit 前端的类型。现在 这可以是dockerfile.v0gateway.v0.

  • args定义传递给 BuildKit 前端的构建参数。

    中的 keyargs对象反映 BuildKit 接收的选项 他们。例如build-arglabel前缀用于构建 arguments 和 labels,以及targetkey 定义 建立。这sourcekey 定义 Gateway 前端的源镜像,如果 使用。

以下字段仅包含在mode=max:

  • secrets定义构建期间使用的密钥。请注意,实际的 secret 值不包括在内。
  • ssh定义构建期间使用的 SSH 转发。

invocation.environment

对应于SLSAinvocation.environment.

包含在mode=minmode=max.

    "invocation": {
      "environment": {
        "platform": "linux/amd64"
      },
      ...
    },

BuildKit 当前设置的唯一值是platform当前版本 机器。请注意,这不一定是构建结果的平台 可以从in-totosubject 字段。

materials

对应于SLSAmaterials.

包含在mode=minmode=max.

定义作为构建一部分的所有外部工件。价值 取决于项目的类型:

  • 包含镜像源代码的 Git 存储库的 URL
  • HTTP URL(如果您是从远程 tarball 构建),或者包含的 使用ADDDockerfile 中的 command
  • 构建期间使用的任何 Docker 镜像

Docker 镜像的 URL 将采用 Package URL 格式。

所有构建材料都将包含构件的不可变校验和。 从可变标签构建时,您可以使用摘要信息来 确定与构建运行时间相比,构件是否已更新。

    "materials": [
      {
        "uri": "pkg:docker/alpine@3.17?platform=linux%2Famd64",
        "digest": {
          "sha256": "8914eb54f968791faf6a8638949e480fef81e697984fba772b3976835194c6d4"
        }
      },
      {
        "uri": "https://github.com/moby/buildkit.git#refs/tags/v0.11.0",
        "digest": {
          "sha1": "4b220de5058abfd01ff619c9d2ff6b09a049bea0"
        }
      },
      ...
    ],

buildConfig

对应于SLSAbuildConfig.

仅包含在mode=max.

定义在构建期间执行的构建步骤。

BuildKit 内部使用 LLB 定义来执行构建步骤。法学学士 构建步骤的定义在buildConfig.llbDefinition田。

每个 LLB 步骤都是 LLB ProtoBuf API 的 JSON 定义。 LLB 图中顶点的依赖关系可以在inputs字段。

  "buildConfig": {
    "llbDefinition": [
      {
        "id": "step0",
        "op": {
          "Op": {
            "exec": {
              "meta": {
                "args": [
                  "/bin/sh",
                  "-c",
                  "go build ."
                ],
                "env": [
                  "PATH=/go/bin:/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                  "GOPATH=/go",
                  "GOFLAGS=-mod=vendor",
                ],
                "cwd": "/src",
              },
              "mounts": [...]
            }
          },
          "platform": {...},
        },
        "inputs": [
          "step8:0",
          "step2:0",
        ]
      },
      ...
    ]
  },

metadata.buildInvocationId

对应于SLSAmetadata.buildInvocationId.

包含在mode=minmode=max.

生成调用的唯一标识符。构建多平台镜像时 对于单个构建请求,此值将由所有平台共享 版本。

    "metadata": {
      "buildInvocationID": "rpv7a389uzil5lqmrgwhijwjz",
      ...
    },

metadata.buildStartedOn

对应于SLSAmetadata.buildStartedOn.

包含在mode=minmode=max.

生成开始时的时间戳。

    "metadata": {
      "buildStartedOn": "2021-11-17T15:00:00Z",
      ...
    },

metadata.buildFinishedOn

对应于SLSAmetadata.buildFinishedOn.

包含在mode=minmode=max.

构建完成时的时间戳。

    "metadata": {
      "buildFinishedOn": "2021-11-17T15:01:00Z",
      ...
    },

metadata.completeness

对应于SLSAmetadata.completeness.

包含在mode=minmode=max.

定义出处信息是否完整。

completeness.parameters如果所有构建参数都包含在invocation.parameters田。使用minmode 中,生成 参数不包含在来源信息中,参数不包含 完成。在未使用 一个前端。

completeness.environment对于 BuildKit 构建,始终为 true。

completeness.materials如果materials字段包含所有 build 的依赖项。从本地 目录中,材料不完整,而从远程 Git 构建时 仓库中的所有素材都可以通过 BuildKit 和completeness.materials是真的。

    "metadata": {
      "completeness": {
        "parameters": true,
        "environment": true,
        "materials": true
      },
      ...
    },

metadata.reproducible

对应于SLSAmetadata.reproducible.

定义构建结果是否应该是逐字节可重现的。这 值可由用户使用reproducible=trueattestation 参数。

    "metadata": {
      "reproducible": false,
      ...
    },

metadata.https://mobyproject.org/buildkit@v1#hermetic

包含在mode=minmode=max.

如果构建是密封的并且未访问 网络。在 Dockerfile 中,如果构建不使用RUN命令或禁用网络--network=none旗。

    "metadata": {
      "https://mobyproject.org/buildkit@v1#hermetic": true,
      ...
    },

metadata.https://mobyproject.org/buildkit@v1#metadata

部分包含在mode=min.

此扩展字段定义特定于 BuildKit 的附加元数据,该元数据不是 SLSA 出处规范的一部分。

    "metadata": {
      "https://mobyproject.org/buildkit@v1#metadata": {
        "source": {...},
        "layers": {...},
        "vcs": {...},
      },
      ...
    },

source

仅包含在mode=max.

定义 LLB 构建步骤的源映射,在buildConfig.llbDefinition字段,转换为其原始源代码(例如 Dockerfile 命令)。这source.locationsfield 包含所有 在 LLB 步骤中运行的 Dockerfile 命令。source.infos数组包含 源代码本身。如果 BuildKit 前端提供了此映射,则存在此映射 创建 LLB 定义时。

layers

仅包含在mode=max.

定义中定义的 LLB 构建步骤挂载的层映射buildConfig.llbDefinition添加到等效层的 OCI 描述符。这 如果图层数据可用,则存在映射,通常是当认证为 对于镜像,或者构建步骤是否在构建过程中提取了镜像数据。

vcs

包含在mode=minmode=max.

定义用于构建的版本控制系统的可选元数据。如果 构建使用 Git 仓库中的远程上下文,BuildKit 会提取详细信息 的 Alpha S Git,并将其显示在invocation.configSource田。但是,如果构建使用来自本地 目录中,即使该目录包含 Git 存储 库。在这种情况下,构建客户端可以发送额外的vcs:sourcevcs:revisionbuild 选项,BuildKit 会将它们添加到来源 证明作为额外的元数据。请注意,与invocation.configSource字段中,BuildKit 不会验证vcsvalues 和 因此,它们不可信,只能用作元数据提示。

输出

要检查生成并附加到容器镜像的来源,请执行以下作: 您可以使用docker buildx imagetools命令检查镜像 注册表。检查认证会显示认证存储规范中描述的格式。

例如,检查基于alpine:latest结果 在类似于以下内容的出处证明中,对于mode=min建:

{
  "_type": "https://in-toto.io/Statement/v0.1",
  "predicateType": "https://slsa.dev/provenance/v0.2",
  "subject": [
    {
      "name": "pkg:docker/<registry>/<image>@<tag/digest>?platform=<platform>",
      "digest": {
        "sha256": "e8275b2b76280af67e26f068e5d585eb905f8dfd2f1918b3229db98133cb4862"
      }
    }
  ],
  "predicate": {
    "builder": {
      "id": ""
    },
    "buildType": "https://mobyproject.org/buildkit@v1",
    "materials": [
      {
        "uri": "pkg:docker/alpine@latest?platform=linux%2Famd64",
        "digest": {
          "sha256": "8914eb54f968791faf6a8638949e480fef81e697984fba772b3976835194c6d4"
        }
      }
    ],
    "invocation": {
      "configSource": {
        "entryPoint": "Dockerfile"
      },
      "parameters": {
        "frontend": "dockerfile.v0",
        "args": {},
        "locals": [
          {
            "name": "context"
          },
          {
            "name": "dockerfile"
          }
        ]
      },
      "environment": {
        "platform": "linux/amd64"
      }
    },
    "metadata": {
      "buildInvocationID": "yirbp1aosi1vqjmi3z6bc75nb",
      "buildStartedOn": "2022-12-08T11:48:59.466513707Z",
      "buildFinishedOn": "2022-12-08T11:49:01.256820297Z",
      "reproducible": false,
      "completeness": {
        "parameters": true,
        "environment": true,
        "materials": false
      },
      "https://mobyproject.org/buildkit@v1#metadata": {}
    }
  }
}

对于类似的 build,但使用mode=max:

{
  "_type": "https://in-toto.io/Statement/v0.1",
  "predicateType": "https://slsa.dev/provenance/v0.2",
  "subject": [
    {
      "name": "pkg:docker/<registry>/<image>@<tag/digest>?platform=<platform>",
      "digest": {
        "sha256": "e8275b2b76280af67e26f068e5d585eb905f8dfd2f1918b3229db98133cb4862"
      }
    }
  ],
  "predicate": {
    "builder": {
      "id": ""
    },
    "buildType": "https://mobyproject.org/buildkit@v1",
    "materials": [
      {
        "uri": "pkg:docker/alpine@latest?platform=linux%2Famd64",
        "digest": {
          "sha256": "8914eb54f968791faf6a8638949e480fef81e697984fba772b3976835194c6d4"
        }
      }
    ],
    "invocation": {
      "configSource": {
        "entryPoint": "Dockerfile"
      },
      "parameters": {
        "frontend": "dockerfile.v0",
        "args": {},
        "locals": [
          {
            "name": "context"
          },
          {
            "name": "dockerfile"
          }
        ]
      },
      "environment": {
        "platform": "linux/amd64"
      }
    },
    "buildConfig": {
      "llbDefinition": [
        {
          "id": "step0",
          "op": {
            "Op": {
              "source": {
                "identifier": "docker-image://docker.io/library/alpine:latest@sha256:8914eb54f968791faf6a8638949e480fef81e697984fba772b3976835194c6d4"
              }
            },
            "platform": {
              "Architecture": "amd64",
              "OS": "linux"
            },
            "constraints": {}
          }
        },
        {
          "id": "step1",
          "op": {
            "Op": null
          },
          "inputs": ["step0:0"]
        }
      ]
    },
    "metadata": {
      "buildInvocationID": "46ue2x93k3xj5l463dektwldw",
      "buildStartedOn": "2022-12-08T11:50:54.953375437Z",
      "buildFinishedOn": "2022-12-08T11:50:55.447841328Z",
      "reproducible": false,
      "completeness": {
        "parameters": true,
        "environment": true,
        "materials": false
      },
      "https://mobyproject.org/buildkit@v1#metadata": {
        "source": {
          "locations": {
            "step0": {
              "locations": [
                {
                  "ranges": [
                    {
                      "start": {
                        "line": 1
                      },
                      "end": {
                        "line": 1
                      }
                    }
                  ]
                }
              ]
            }
          },
          "infos": [
            {
              "filename": "Dockerfile",
              "data": "RlJPTSBhbHBpbmU6bGF0ZXN0Cg==",
              "llbDefinition": [
                {
                  "id": "step0",
                  "op": {
                    "Op": {
                      "source": {
                        "identifier": "local://dockerfile",
                        "attrs": {
                          "local.differ": "none",
                          "local.followpaths": "[\"Dockerfile\",\"Dockerfile.dockerignore\",\"dockerfile\"]",
                          "local.session": "q2jnwdkas0i0iu4knchd92jaz",
                          "local.sharedkeyhint": "dockerfile"
                        }
                      }
                    },
                    "constraints": {}
                  }
                },
                {
                  "id": "step1",
                  "op": {
                    "Op": null
                  },
                  "inputs": ["step0:0"]
                }
              ]
            }
          ]
        },
        "layers": {
          "step0:0": [
            [
              {
                "mediaType": "application/vnd.oci.image.layer.v1.tar+gzip",
                "digest": "sha256:c158987b05517b6f2c5913f3acef1f2182a32345a304fe357e3ace5fadcad715",
                "size": 3370706
              }
            ]
          ]
        }
      }
    }
  }
}