Notary 是什么 你可能已经听说过 Notary,这是一个基于 TUF 项目的用于软件制品签名的开源软件。 Notary 如何运作 首先说说 Notary 的核心概念。 安装 进入 notary-k8s 目录。 可选项目:构建 Notary 并加入自己的镜像库。 要从头构建最新的 Notary 镜像,需要从 build 目录开始。 然后就是创建命名空间并安装 Helm Chart: $ kubectl create namespace notary # 切换到 notary 命名空间 $ helm install notary notary 如果 Pod 已经运行,就表明 Notary 安装成功了。然而在我们试用 Notary 服务之前,我们应该提交最后生成的 Notary Wrapper 模板。 从 notary-k8s/helm/certs 复制证书文件到 helm/notary-wrapper/certs: notary-wrapper.crt notary-wrapper.key root-ca.crt
/cert_tmp/notary-signer.crt Copying certs for notary signer Copying notary signer configuration file /common/config/notary/notary-signer.crt Clearing the configuration file: . /common/config/notary/notary-signer.key Clearing the configuration file: . /common/config/notary/notary-signer-ca.crt Clearing the configuration file: . /cert_tmp/notary-signer.crt Copying certs for notary signer Copying notary signer configuration file
│ └── notary.upstream.conf ├── notary │ ├── mysql-initdb.d │ │ ├── initial-notaryserver.sql │ │ └── initial-notarysigner.sql │ ├── notary-signer-ca.crt │ ├── notary-signer.crt │ ├── notary-signer.key │ ├── server-config.json │ ├── signer-config.json │ ', dest='notary_mode',default=False, action='store_true', help="the Harbor instance is to be deployed with notary") args = parser.parse_args() print args.cfgfile 配置文件 import StringIO import ConfigParser
否则上传镜像时会报错),并创建一个子用户用于管理该桶,并生成一个密钥用于harbor连接访问 购买一台PostgreSQL RDS(1 核 2 GiB,磁盘 10 G),并创建3个库:registry、notary_server 、notary_signer、 在KTE中创建一个新的命令空间:ns-harbor 在KTE中创建一个storeageClass:sc-harbor 图片安装前的准备 安装配置 在控制机上配置好 =notary.test.com \ --set ingress.notary.ingressClassName=kong \ --set ingress.notary.controller=ingress-controllers.konghq.com **" \ --set externalDatabase.coreDatabase="registry" \ --set externalDatabase.notaryServerDatabase="notary_server =notary.test.com \ --set ingress.notary.ingressClassName=kong \ --set ingress.notary.controller=ingress-controllers.konghq.com
/notary.upstream.conf Generated configuration file: /config/nginx/conf.d/notary.server.conf Generated file: /config/notary/signer_env Generated configuration file: /config/notary/signer-config.postgres.json (goharbor/notary-signer-photon:v2.2.2)... v2.2.2: Pulling from goharbor/notary-signer-photon b31150c04016 :v2.2.2 Pulling notary-server (goharbor/notary-server-photon:v2.2.2)... v2.2.2: Pulling from goharbor Creating notary-signer ... Creating notary-server ... Creating harbor-jobservice ...
v2 alpha1 发布 Notary v1,也称为 Docker Content Trust(DCT),主要是为当时的 Docker Hub 发布的。 对 Notary 不了解的小伙伴,可以看下我两年前写的一篇 《K8S 生态周报| TUF 正式从 CNCF 毕业》在这篇文章中介绍了 TUF 还有 Notary 等内容。这里就不展开了。 Notary v2 支持对存储在基于 OCI 分发的注册表中的所有工件(容器镜像、软件材料清单、扫描结果)进行签名,并增强了 ORAS 工件规范。 Notary v2 的一个关键原则是它支持在注册中心内和跨注册中心推广已签名的工件,包括私有网络环境。 它的工作过程如下图所示: Notary v2 在 Notary v2 中最显著的变化就是易用性的提升,包括它发布了名为 notation 的 CLI 工具。可以创建证书,签名,校验等。
镜像的创建者可以对镜像做数字签名,签名的结果称为摘要(Digest),保存在一个称为 Notary 服务中。 当镜像的用户下载时,根据镜像的名称,可以从 Notary 获得镜像的摘要,然后使用 Registry V2 的 API,做 Pull by content (Digest)的 Registry 调用,即可获得来自信任者的镜像 在安装 Harbor 时,加上 --with-notary 选项,并且设置 HTTPS 功能,即可启动 Notary 服务。 即可使用内容信任功能获取信任的镜像: export DOCKER_CONTENT_TRUST=1 export DOCKER_CONTENT_TRUST_SERVER=https://Harbor_IP:4443 集成了内容信任Notary
harbor-release-harbor-jobservice-878896998-glbvw 1/1 Running 4 8m harbor-release-harbor-notary-server -6ccddbcd98-knk2n 1/1 Running 0 8m harbor-release-harbor-notary-signer-5f4df97cd5-2vbb8 harbor-release-harbor-mysql-0 1/1 Running 0 8m harbor-release-harbor-notary-db Add DNS resolution entry for Notary FQDN notary-harbor.local to K8s Ingress Controller IP on DNS Server jsonpath="{.data.HARBOR_ADMIN_PASSWORD}" | base64 --decode; echo 命令可以得到harbor的管理员密码 要添加两个域名映射harbor.local、notary-harbor.local
: notary-harbor.minminmsn.com annotations: ingress.kubernetes.io/ssl-redirect: "true" Only needed when notary.enabled # is set to true notaryPort: 4443 nodePort: # The is set to true notary: # The service port Notary listens on port: 4443 # The node port Notary listens on nodePort: 30004 # The external URL for Harbor core service ClusterIP 10.254.255.218 <none> 4443/TCP 0s min-harbor-notary-signer ClusterIP
Harbor 2.5通过与另外两个开源项目Notary[1] 和 Cosign[2] 的集成,支持了内容信任,其中 Cosign 是新增的功能。 安装两个启用了 cosign(和 notary)Harbor的实例 我们使用Harbor的离线安装程序[6]。 # . /install.sh --with-notary --with-trivy [Step 0]: checking if docker is installed ... ... ... ... 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
快速上手 Harbor 中提供了 Notary 服务来提供了这方面的保障,Docker 17.12 之后也提供了对应的运行时支持。 这里用 1.10.0 版本的 Harbor 为例,在安装命令中加入参数 --with-notary 就可以启用这个服务了。 Has a notary repository been initialized? 这里多出了一个初始化过程,在我们照章输入密码之后,发现出了错,这是因为我们没有设置 Notary 服务地址,加入环境变量来解决:export DOCKER_CONTENT_TRUST_SERVER=https 幕后 Docker 包含了简写为 DCT 的内容签名(Docker Content Trust)支持,能够借助 Notary 进行内容签署和校验。
/harbor-harbor-jobservice-778454b56-7qjzl 1/1 Running 0 7m2s pod/harbor-harbor-notary-server -79dff589-488k4 1/1 Running 1 7m2s pod/harbor-harbor-notary-signer-6bdd9fc8d5-x4nwp ClusterIP 10.96.142.122 <none> 4443/TCP 7m2s service/harbor-harbor-notary-signer 1/1 1 1 7m2s deployment.apps/harbor-harbor-notary-signer 1/1 1 -79dff589 1 1 1 7m2s replicaset.apps/harbor-harbor-notary-signer-6bdd9fc8d5
Harbor 2.5通过与另外两个开源项目Notary[1] 和 Cosign[2] 的集成,支持了内容信任,其中 Cosign 是新增的功能。 安装两个启用了 cosign(和 notary)Harbor的实例 我们使用Harbor的离线安装程序[6]。 # . /install.sh --with-notary --with-trivy [Step 0]: checking if docker is installed ... ... ... ... Creating network "harbor_harbor" with the default driver Creating network "harbor_harbor-notary" with 参考资料 [1] Notary: https://github.com/notaryproject/notary [2] Cosign: https://github.com/sigstore/cosign
80, 443 419d minminmsn-harbor-ingress core-harbor.minminmsn.com,notary-harbor.minminmsn.com serviceName: minminmsn-harbor-core servicePort: 80 path: /c/ - host: notary-harbor.minminmsn.com http: paths: - backend: serviceName: minminmsn-harbor-notary-server tls: - hosts: - core-harbor.minminmsn.com secretName: ingress-secret2021 - hosts: - notary-harbor.minminmsn.com
: notary.harbor.tech.21cn.com # set to the type of ingress controller if it has specific requirements : # notary-specific annotations annotations: {} harbor: # harbor ingress-specific Only needed when notary.enabled # is set to true notaryPort: 4443 nodePort: # The name is set to true notary: # The service port Notary listens on port: 4443 Only needed when notary.enabled # is set to true notaryPort: 4443 annotations: {}
Harbor 通过与Notary[1]和Cosign[2]的集成支持内容信任。 安装两个启用了 cosign(和 notary)的实例 在我们的设置中,我们使用离线安装程序[6]。 # . /install.sh --with-notary --with-trivy [Step 0]: checking if docker is installed ... ... ... ... Creating network "harbor_harbor" with the default driver Creating network "harbor_harbor-notary" with 参考资料 [1]Notary: https://github.com/notaryproject/notary [2]Cosign: https://github.com/sigstore/cosign
指定参数或者 values.yaml 直接编辑 Values 文件即可: Ingress 配置通过 expose.ingress.hosts.core 和 expose.ingress.hosts.notary 需要我们手动创建3个空的数据:Harbor core、Notary server 以及 Notary signer,Harbor 会在启动时自动创建表结构 外部 Redis 通过配置 redis.type 但是使用外置的数据库我们需要提前手动创建数据库,比如我们这里使用的 GitLab 提供的数据库,则进入该 Pod 创建 harbor、notary_server、notary_signer 这3个数据库 、notary_signer ...... postgres-# \q # 退出 数据库准备过后,就可以使用我们自己定制的 values 文件来进行安装了,完整的定制的 values 文件如下所示: -7d79b7d46d-dlgt7 1/1 Running 0 91s harbor-harbor-notary-signer-69d8fdd476-7pt44 1
证书 openssl genrsa -out harbor-notary.key 2048 openssl req -new -key harbor-notary.key -out harbor-notary.csr -subj "/C=CN/ST=Sichuan/L=Chengdu/O=anson/OU=harbor-notary/CN=harbor-notary.anson.cn" openssl x509 - -in harbor-notary.csr -out harbor-notary.crt -days 36500 kubectl create secret tls tls-harbor-notary --cert=harbor-notary.crt --key=harbor-notary.key -n harbor 打开values配置文件 vi harbor/values.yaml 修改如下参数 " # 第25行,notary证书secret ingress: hosts: core: harbor.anson.cn # 第38行,harbor域名 notary
目录下执行docker-compose up -d也无法启动harbor服务,并报下面异常信息: WARN[0000] Found orphan containers ([trivy-adapter notary-server notary-signer chartmuseum]) for this project.
至于它的存在感嘛,不知道你是否有使用过 Docker Content Trust(DCT) 相关的功能,简单来说你可以当作就是 docker trust 所涉及到的相关功能,这其中的部分功能是构建在 Docker Notary 之上的,而 Docker Notary 则是使用 TUF 作为其基础安全框架的。 (PS:Docker Inc 也已经将 Docker Notary 捐献给了 CNCF) 现在多数公有云(比如 IBM,Azure 等)提供可信镜像仓库服务时,基本也都间接的依赖于 Docker Notary