关于docker:docker-内容安全签名之-notary

1次阅读

共计 2463 个字符,预计需要花费 7 分钟才能阅读完成。

简介
在网络系统之间传输数据时,信赖是一个次要问题。特地是,当通过不受信赖的媒体(例如 Internet)进行通信时,确保零碎所解决的所有数据的完整性和发布者至关重要。您能够应用 Docker Engine 将图像(数据)推入和拉入公共或公有注册表。内容信赖使您可能验证通过任何渠道从注册表接管的所有数据的完整性和发布者。

装置应用

下载 notary 仓库
# 如果 clone 过慢能够应用 gitclone.com 这个网站进行减速解决
git clone https://github.com/theupdateframework/notary.git
因为该我的项目是国外仓库, 导致有局部资源无奈下载, 须要做一下非凡解决, 所有的 dockerfile
# 替换软件源 RUN apk add --update git gcc libc-dev 替换成
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
# 减少环境变量
ENV GOPROXY=https://goproxy.cn,direct
我的项目的证书已于 2021-04-01T03:38:34Z 曾经过期了须要更新证书, 更新须要下载 cfssl 相干组件 cfssljson、cfssl-certinfo、cfssl
https://pkg.cfssl.org/R1.2/cfssljson_linux-amd64
https://pkg.cfssl.org/R1.2/cfssl-certinfo_linux-amd64
https://pkg.cfssl.org/R1.2/cfssl_linux-amd64
chmod +x cfssl*
mv cfssl* /usr/bin
进入我的项目 fixtures 目录
cd fixtures
sh ./regenerateTestingCerts.sh
更新本地证书
cp ./fixtures/root-ca.crt /etc/pki/ca-trust/source/anchors/
update-ca-trust

启用服务端

docker-compose up -d

设置环境变量

export DOCKER_CONTENT_TRUST_ROOT_PASSPHRASE="sezg6ogsmylknht8"
export DOCKER_CONTENT_TRUST_REPOSITORY_PASSPHRASE="sezg6ogsmylknht8"
export DOCKER_CONTENT_TRUST_SERVER=https://127.0.0.1:4443
export DOCKER_CONTENT_TRUST=1

在 Docker 中进行镜像签名
要签名一个 Docker 镜像,须要一个密钥对,其能够应用命令在本地生成(默认状况下存储在 ~/.docker/trust/ 中),也能够由来自证书机构。

本地生成

$ docker trust key generate point_me
Generating key for point_me...
Enter passphrase for new point_me key with ID 9deed25:
Repeat passphrase for new point_me key with ID 9deed25:
Successfully generated and loaded private key.

应用已有

$ docker trust key load key.pem --name point_me
Loading key from "key.pem"...
Enter passphrase for new point_me key with ID 8ae710e:
Repeat passphrase for new point_me key with ID 8ae710e:
Successfully imported key from key.pem

接下来,咱们将公钥增加到公证服务器上。如果是第一次执行的话,须要输出一些相干信息,才能够应用。

$ docker trust signer add --key cert.pem point_me registry.example.com/admin/demo
Adding signer "point_me" to registry.example.com/admin/demo...
Enter passphrase for new repository key with ID 10b5e94:

最初,咱们将应用私钥对特定镜像文件的标签进行签名,并将其推到仓库中去。

签名

$ docker trust sign registry.example.com/admin/demo:1
Signing and pushing trust data for local image registry.example.com/admin/demo:1, may overwrite remote trust data
The push refers to repository [registry.example.com/admin/demo]
7bff100f35cb: Pushed
1: digest: sha256:3d2e482b82608d153a374df3357c0291589a61cc194ec4a9ca2381073a17f58e size: 528
Signing and pushing trust metadata
Enter passphrase for signer key with ID 8ae710e:
Successfully signed registry.example.com/admin/demo:1

查看签名

docker trust inspect --pretty registry.example.com/admin/demo:1

缺点

目前应用 docker trust sign image 会呈现一下谬误

errors:
denied: requested access to the resource is denied
unauthorized: authentication required
正文完
 0