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


使用 GPG 签名签署 Red Hat Enterprise Linux 容器镜像以建立信任并验证软件来源。应用这些加密签名可确保您的镜像保持不透明,从而保护您的基础架构部署被破坏的应用程序。

先决条件

  • container-tools meta-package 和 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@example.com>
  3. 使用当前目录中的 Containerfile 构建容器镜像:

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

    <registry>, <namespace><image> 替换为容器镜像标识符。

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

     $  podman push \
        --sign-by <username@example.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 目录。

验证

  • 拉取镜像:

    $ podman pull <registry>/<namespace>/<image>

    您需要运行 podman pull 命令,以强制在我们配置时签名存在。如果您尝试从配置的 registry 中拉取使用错误密钥未签名或签名的镜像,命令将失败。

    如需更多信息,请参阅系统中的 podman-image-trust (1)podman-push (1)podman-build (1) 手册页。

Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

關於紅帽

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

让开源更具包容性

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

关于红帽文档

Legal Notice

Theme

© 2026 Red Hat
返回顶部