跳到内容

启用容器签名

作为容器注册表的 Galaxy 可以处理容器清单签名,服务器可以接受附加签名的镜像推送,并且还可以使用 Pulp 签名服务通过 UI 和 API 按需创建签名。

在 pulp 安装程序上启用签名

Pulp 安装程序也可以配置为启用容器签名 https://github.com/pulp/pulp_installer/tree/main/roles/galaxy_post_install#variables-for-the-signing-service 如果您使用 pulp-installer 进行配置,则可以跳过本页面的 创建容器签名服务 部分。

推送带有签名的镜像

将带有签名的已标记镜像一起推送到 Galaxy 注册表,请将 --sign-by 参数传递给客户端。

podman push --tls-verify=false --sign-by username@email.com localhost:5001

签名服务

签名服务是在 pulp 后端上定义的对象,它组合了一个 GPG 密钥和一个可执行脚本的绝对路径。

创建签名服务

要在 Galaxy 服务器上创建签名服务,需要访问 django-admin 实用程序并执行

重要

该命令必须在安装了 galaxy_ng 工作程序的 Python 环境中运行。

Bash 命令
django-admin add-signing-service \  #(1)
    unique-name \  #(2)
    /abs/path/to/script.sh \ #(3)
    GPG_KEY_ID #(4)
    --class container:ManifestSigningService #(5)
  1. django 管理命令。
  2. 签名服务应在数据库中获取的名称。
  3. 执行签名的 Shell 脚本的绝对路径。
  4. 公钥的密钥 ID。
  5. 对于容器,需要通知 --class 参数

add-signing-service 命令的位置参数

命名参数 --class

  • --class 需要设置为值 container:ManifestSigningService,以便可以执行其他检查。

重要

将密钥导入密钥环时,信任级别必须设置为高于 3 的某个值。例如:echo "${KEY_FINGERPRINT}:6:" | gpg --batch --import-ownertrust

签名脚本

Pulp Container 提供了一个使用 skopeo 生成签名的脚本示例 https://docs.pulpproject.org/pulp_container/workflows/sign-images.html#image-signature-configuration

/var/lib/pulp/scripts/container_sign.sh
#!/usr/bin/env bash
# This GPG_TTY variable might be needed on a container image that is not running as root.
# export GPG_TTY=$(tty)

# pulp_container SigningService will pass the next 4 variables to the script.
MANIFEST_PATH=$1
FINGERPRINT="$PULP_SIGNING_KEY_FINGERPRINT"
IMAGE_REFERENCE="$REFERENCE"
SIGNATURE_PATH="$SIG_PATH"

# Create container signature using skopeo
skopeo standalone-sign \
  $MANIFEST_PATH \
  $IMAGE_REFERENCE \
  $FINGERPRINT \
  --output $SIGNATURE_PATH

# Optionally pass the passphrase to the key if password protected.
# --passphrase-file /path/to/key_password.txt

# Check the exit status
STATUS=$?
if [ $STATUS -eq 0 ]; then
  echo {\"signature_path\": \"$SIGNATURE_PATH\"}
else
  exit $STATUS
fi

使用密钥和脚本创建签名服务

创建签名服务
django-admin add-signing-service container-default \
  /var/lib/pulp/scripts/container_sign.sh \
  ${FINGERPRINT} \
  --class container:ManifestSigningService

配置 Galaxy 以使用签名服务

要告诉 Galaxy 使用哪个签名服务,您需要在 pulp 设置中进行设置。

选项 1

/etc/pulp/settings.py
GALAXY_CONTAINER_SIGNING_SERVICE = "unique-name"  #(1)

  1. 创建的签名服务的名称

选项 2

环境变量
export PULP_GALAXY_CONTAINER_SIGNING_SERVICE=unique-name #(1)

  1. 创建的签名服务的名称

通过 API 签名

Galaxy 调用 Pulp Container API 来触发签名,因此如果您需要使用 API 进行签名,请参阅 Pulp 文档 https://docs.pulpproject.org/pulp_container/workflows/sign-images.html#sign-images-that-were-pushed-to-the-pulp-registry

通过 UI 签名

在 UI 的 执行环境 菜单下,有用于触发特定容器镜像的 签名 的按钮。

信息

要执行签名操作,用户必须是超级用户(管理员),或者需要由角色执行 环境管理员执行环境发布者执行环境命名空间所有者执行环境协作者 提供的 modify_content_containerpushrepository 权限

签名验证

获取公钥

Galaxy 服务器上签名服务的公钥在 URL https://FQDN/pulp/api/v3/signing-services/ 和相应的 UI 页面 公钥 上公开

如果签名来自远程服务器,则其公钥必须直接在远程服务器上找到。

安装期间的验证

为了验证容器镜像签名,客户端(podman、docker)需要使用 策略 文件进行配置,如 https://github.com/containers/image/blob/main/docs/containers-policy.json.5.md 中所述

示例

cat  /etc/containers/policy.json
{
  "default": [{"type": "reject"}],
  "transports": {
    "docker": {
       "fluffy.example.com": [
        {
          "type": "signedBy",
          "keyType": "GPGKeys",
          "keyPath": "/path-to-pupsik-key.gpg"
        }
      ]
    },
    "containers-storage": {
    "": [{"type": "insecureAcceptAnything"}] /* Allow copy operations on any images stored in containers storage (e.g. podman push) */
    }
  }
}

客户端命令的执行必须如 https://docs.pulpproject.org/pulp_container/workflows/verify-images.html#verify-images-pushed-into-pulp-container-registry 中所述

客户端验证容器镜像签名
podman pull fluffy.example.com/myrepo/test-image:foo
Trying to pull fluffy.example.com/myrepo/test-image:foo...
Getting image source signatures
Checking if image destination supports signatures
Copying blob 58147e24f776 skipped: already exists
Copying config 829374d342 done
Writing manifest to image destination
Storing signatures
829374d342ae65a12f3a95911bc04a001894349f70783fda841b1a784008727d