第 8 章 签名容器镜像


您可以使用 GNU Privacy Guard (GPG)签名或 sigstore 签名来为容器镜像签名。两种签名技术均与任何 OCI 兼容容器注册中心兼容。在将镜像推送至远程注册中心并配置消费者之前,您可以使用 Podman 签名镜像,以便拒绝任何未签名的镜像。签名容器镜像有助于防止供应链攻击。

使用 GPG 密钥进行签名需要部署单独的备用服务器来分发签名。备用服务器可以是任何 HTTP 服务器。从 Podman 版本 4.2 开始,您可以使用容器签名的 sigstore 格式。与 GPG 密钥相比,不需要单独的备用服务器,因为 sigstore 签名存储在容器注册中心。

8.1. 使用 GPG 签名为容器镜像签名

您可以使用 GNU Privacy Guard (GPG)密钥签名镜像。

先决条件

  • container-tools 模块已安装。
  • GPG 工具已安装。
  • 备用 Web 服务器已建立,您可以在其上发布文件。

    • 您可以在 /etc/containers/registries.d/default.yaml 文件中检查系统范围的注册中心配置。lookaside-staging 选项引用签名写入的文件路径,通常在主机发布签名上设置。

      # cat /etc/containers/registries.d/default.yaml
      docker:
          <registry>:
              lookaside: https://registry-lookaside.example.com
              lookaside-staging: file:///var/lib/containers/sigstore
      ...

流程

  1. 生成一个 GPG 密钥:

    # gpg --full-gen-key
  2. 导出公钥:

    # gpg --output <path>/key.gpg --armor --export <username@domain.com>
  3. 使用 Containerfile 在当前目录中构建容器镜像:

    $ podman build -t <registry>/<namespace>/<image>

    <registry>, <namespace><image> 替换为容器镜像标识符。如需了解更多详细信息,请参阅容器 registry

  4. 为镜像签名并将其推送到注册中心:

     $  podman push \
        --sign-by <username@domain.com> \
        <registry>/<namespace>/<image>
    注意

    如果您需要在容器注册中心间移动现有镜像时为现有镜像签名,您可以使用 skopeo copy 命令。

  5. 可选:显示新镜像签名:

    # (cd /var/lib/containers/sigstore/; find . -type f)
    ./<image>@sha256=<digest>/signature-1
  6. 将本地签名复制到备用 web 服务器:

    # rsync -a /var/lib/containers/sigstore <user@registry-lookaside.example.com>:/registry-lookaside/webroot/sigstore

签名存储在由 lookaside-staging 选项决定的位置,本例中为 /var/lib/containers/sigstore 目录。

验证

其它资源

Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.