notation cert add 只支持 pem 格式证书文件路径,不支持 oci layout 目录;需先用 notation inspect 提取 issuer,再用对应 ca 证书执行 notation cert add --type ca --trust-store ,verify 时必须显式指定相同 --trust-store 名称。

notation cert add 时提示 “OCI layout not found”
这是因为 notation cert add 默认只认本地文件系统路径,而 --oci-layout 是 notation sign 的参数,不是 cert add 的合法选项——它压根不接受 OCI layout 路径作为证书信任源。
常见错误是把签名时用的 --oci-layout 想当然套到证书管理命令上,结果命令直接报错或静默失败。
-
notation cert add只支持添加 PEM 格式证书文件(.crt或.pem),路径必须指向具体文件,不能是目录 - OCI layout 是一个带
index.json和blobs/的目录结构,notation cert命令完全不解析它 - 如果证书是随签名一起存进 OCI layout 的(比如用
notation sign --oci-layout生成的),得先从blobs/里手动提取证书,再单独 add
如何从 OCI layout 中提取并信任签名用的证书
OCI layout 本身不存储“可信任的证书”,它只存签名(signature.json)和签名人公钥(通常嵌在 signature 内)。要建立信任链,你得拿到签名人自己的 CA 证书(即 issuer 的 root 或 intermediate cert),而不是签名 blob 里的公钥片段。
实操分两步:先确认签名中声明的 issuer,再用该 issuer 的 PEM 证书调用 notation cert add。
- 用
notation inspect --oci-layout <path><ref></ref></path>查看签名元数据,重点关注issuer字段(如https://notary.example.com)和subject - 根据
issuer找到对应 CA 证书文件(比如notary-ca.crt),确保它是 PEM 格式、无密码、且未被截断 - 运行
notation cert add --type ca --trust-store <code>notarynotary-ca.crt;其中notary是自定义 trust store 名,后续 verify 必须用同一个名字
notation verify --oci-layout 失败:trusted store 名字不匹配
notation verify 不会自动查默认 trust store,它必须显式指定 --trust-store,否则即使证书已 add,也会报 no matching certificate found。
这个参数名容易误解:“trust store” 不是目录路径,而是你在 cert add 时用 --trust-store 定义的逻辑名称(比如 notary),它背后对应 $HOME/.config/notation/truststore/certs/notary/ 下的文件。
- verify 命令必须带
--trust-store <name></name>,且<name></name>与 cert add 时完全一致(大小写敏感) - 如果不指定
--issuer,verify 会尝试匹配签名中issuer字段与 trust store 中证书的Subject或URI SAN,不匹配就失败 - OCI layout 路径本身不影响信任验证逻辑,它只是告诉 verify 去哪读
index.json和signature.json
为什么 verify 成功但容器运行时仍报 “untrusted image”
因为 notation 的信任配置只影响 notation verify 命令本身,对 podman、nerdctl 或 containerd 无任何作用。这些运行时有自己的签名验证机制(比如 cosign 或 in-toto),不读 ~/.config/notation/。
换言之:notation 是独立的签名工具链,不是容器运行时的插件。想让运行时认可,得走对应生态的流程。
- Podman 需要配置
/etc/containers/policy.json并启用cosign插件,或用podman image trust - nerdctl + containerd 目前不原生支持 notation 签名,需转换为 cosign 格式或等 upstream 支持
- OCI layout 路径对运行时也无效——它们只认 registry 地址(如
localhost:5000/myapp:v1),不认本地目录
notation verify 命令执行时对签名 payload 的逐层解包和证书链校验。其他所有环节——包括你把证书文件放在哪、OCI layout 目录结构多规范、甚至 sign 时用了什么 key——都不影响 verify 是否成功,只要最终传给 verify 的 issuer 字符串能跟 trust store 里某张证书的标识对上就行。










