作者:Orlin Vasilev
成品(Artifact)签名和签名验证是关键的安全功能,允许你验证成品的完整性。Harbor 通过与Notary[1]和Cosign[2]的集成支持内容信任。
Harbor v2.5 集成了对 Cosign 的支持,这是一个 OCI 成品签名和验证解决方案,是Sigstore 项目[3]的一部分。
Cosign 对 OCI 成品签名,并将生成的签名推入 Harbor。这个签名作为一个成品附件跟已签名成品一起存储。Harbor 管理已签名成品和 cosign 签名之间的链接,允许你将诸如标记保留规则(tag retention rules)和不可变规则(immutable rules)之类的东西应用于已签名成品,并且它将扩展到已签名成品和签名。通过这种方式,你可以使用 Harbor 的内置功能来管理已签名成品和 cosign 签名附件。
将 Cosign 与 Harbor 结合使用的一个关键特性是能够使用 Harbor 的复制功能[4]来复制签名及其相关的已签名成品。这意味着,如果一个复制规则(replication rule)应用于一个已签名成品,Harbor 将把复制规则应用于签名,就像它应用于已签名成品一样。
你可以参阅完整文档[5]了解更多。
配置两个启用了 Cosign 的 Harbor 实例,设置项目仓库(在 v2.5.0 中为默认值),并配置复制。我们将有两个实例 harbor1 和 harbor2,项目“cosign”和 harbor1 到 harbor2 之间的复制规则(基于推送),使用机器人帐户(robo-account)。
在我们的设置中,我们使用离线安装程序[6]。
# ./install.sh --with-notary --with-trivy
[Step 0]: checking if docker is installed ...
...
...
...
[Step 5]: starting Harbor ...
Creating network "harbor_harbor" with the default driver
Creating network "harbor_harbor-notary" with the default driver
Creating network "harbor_notary-sig" with the default driver
Creating harbor-log ... done
Creating harbor-portal ... done
Creating redis ... done
Creating registryctl ... done
Creating registry ... done
Creating harbor-db ... done
Creating trivy-adapter ... done
Creating notary-signer ... done
Creating harbor-core ... done
Creating harbor-jobservice ... done
Creating nginx ... done
Creating notary-server ... done
✔ ----Harbor has been installed and started successfully.----
在仓库启用 cosign:
保存机器人机密做安装程序复制:
设置新的目标注册中心:
设置从 Harbor1->Harbor2 的复制规则:
为了能够执行以下步骤,你需要安装“cosign”。见安装说明[9]。
$ cosign generate-key-pair
Enter password for private key:
Enter again:
Private key written to cosign.key
Public key written to cosign.pub
你可以导出密钥的密码(也称为 pass-phrase),以便在自动化中使用:
export COSIGN_PASSWORD=Your_Super_P1$$w0rD
使用你的 cosign-demo 用户登录第一个 Harbor 实例。
$ docker login harbor1.orlix.org
Authenticating with existing credentials...
Login Succeeded
然后将一个镜像推送到你已经设置好的 cosign 项目,下面的例子使用了 pause:1。
$ docker push harbor1.orlix.org/cosign/pause:1
The push refers to repository [harbor1.orlix.org/cosign/pause]
5f70bf18a086: Layer already exists
e16a89738269: Layer already exists
1: digest: sha256:b31bfb4d0213f254d361e0079deaaebefa4f82ba7aa76ef82e90b4935ad5b105 size: 938
一旦我们在注册中心中有了可用的镜像,我们就可以用 cosign 来做镜像签名。
$ cosign sign --key cosign.key harbor1.orlix.org/cosign/pause:1
Enter password for private key:
Pushing signature to: harbor1.orlix.org/cosign/pause
验证复制:
在 harbor1 实例上触发复制规则 harbor1->harbor2 之后,你可以看到该镜像在两个 harbor 实例中都由 Cosign 签名,通过运行 cosign verify 进行签名。
$ cosign verify --key cosign.pub harbor1.orlix.org/cosign/pause:1 | jq .
Verification for harbor1.orlix.org/cosign/pause:1 --
The following checks were performed on each of these signatures:
- The cosign claims were validated
- The signatures were verified against the specified public key
[
{
"critical": {
"identity": {
"docker-reference": "harbor1.orlix.org/cosign/pause"
},
"image": {
"docker-manifest-digest": "sha256:b31bfb4d0213f254d361e0079deaaebefa4f82ba7aa76ef82e90b4935ad5b105"
},
"type": "cosign container image signature"
},
"optional": null
}
]
$ cosign verify --key cosign.pub harbor2.orlix.org/cosign/pause:1 | jq .
Verification for harbor2.orlix.org/cosign/pause:1 --
The following checks were performed on each of these signatures:
- The cosign claims were validated
- The signatures were verified against the specified public key
[
{
"critical": {
"identity": {
"docker-reference": "harbor1.orlix.org/cosign/pause"
},
"image": {
"docker-manifest-digest": "sha256:b31bfb4d0213f254d361e0079deaaebefa4f82ba7aa76ef82e90b4935ad5b105"
},
"type": "cosign container image signature"
},
"optional": null
}
验证返回结果和退出代码零,表明签名有效!摘要(digest)也是一样的!
成功!!!
Orlin Vasilev,Harbor 社区经理,github.com/OrlinVasilev。
[1]Notary: https://github.com/notaryproject/notary
[2]Cosign: https://github.com/sigstore/cosign
[3]Sigstore 项目: https://github.com/sigstore
[4]复制功能: https://goharbor.io/docs/2.5.0/administration/configuring-replication/
[5]完整文档: https://goharbor.io/docs/2.5.0/working-with-projects/working-with-images/sign-images/
[6]离线安装程序: https://goharbor.io/docs/2.5.0/install-config/download-installer/
[7]创建机器人帐户: https://goharbor.io/docs/2.5.0/administration/robot-accounts/
[8]设置复制: https://goharbor.io/docs/2.5.0/administration/configuring-replication/
[9]安装说明: https://docs.sigstore.dev/cosign/installation/
[10]Harbor 社区: https://goharbor.io/community/
[11]@project_harbor: https://twitter.com/project_harbor
[12]CNCF Slack: https://slack.cncf.io/
[13]Github: https://github.com/goharbor/harbor
CNCF (Cloud Native Computing Foundation)成立于2015年12月,隶属于Linux Foundation,是非营利性组织。
CNCF(云原生计算基金会)致力于培育和维护一个厂商中立的开源生态系统,来推广云原生技术。我们通过将最前沿的模式民主化,让这些创新为大众所用。