简介
在网络系统之间传输数据时, 信赖是一个次要问题。特地是,当通过不受信赖的媒体(例如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、cfsslhttps://pkg.cfssl.org/R1.2/cfssljson_linux-amd64https://pkg.cfssl.org/R1.2/cfssl-certinfo_linux-amd64https://pkg.cfssl.org/R1.2/cfssl_linux-amd64chmod +x cfssl*mv cfssl* /usr/bin进入我的项目fixtures 目录cd fixturessh ./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:4443export DOCKER_CONTENT_TRUST=1

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

本地生成

$ docker trust key generate point_meGenerating 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_meLoading 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/demoAdding 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:1Signing and pushing trust data for local image registry.example.com/admin/demo:1, may overwrite remote trust dataThe push refers to repository [registry.example.com/admin/demo]7bff100f35cb: Pushed1: digest: sha256:3d2e482b82608d153a374df3357c0291589a61cc194ec4a9ca2381073a17f58e size: 528Signing and pushing trust metadataEnter 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 deniedunauthorized: authentication required