Harbor 是一个CNCF基金会托管的开源的可信的云原生docker registry项目,可以用于存储、签名、扫描镜像内容,Harbor 通过添加一些常用的功能如安全性、身份权限管理等来扩展 docker registry 项目,此外还支持在 registry 之间复制镜像,还提供更加高级的安全功能,如用户管理、访问控制和活动审计等,在新版本中还添加了Helm仓库托管的支持。
Harbor最核心的功能就是给 docker registry 添加上一层权限保护的功能,要实现这个功能,就需要我们在使用 docker login、pull、push 等命令的时候进行拦截,先进行一些权限相关的校验,再进行操作,其实这一系列的操作 docker registry v2 就已经为我们提供了支持,v2 集成了一个安全认证的功能,将安全认证暴露给外部服务,让外部服务去实现。
linux 3.10.0-957.5.1.el7.x86_64 centos 7.6.1810 配置 2c2g500g
docker 为centos用户提供了三种安装方式,我们选择第一种,也是官网推荐的安装方式
移除旧的docker 依赖 sudo yum remove docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-engine 设置docker 源 sudo yum install -y yum-utils sudo yum-config-manager \ --add-repo \ https://download.docker.com/linux/centos/docker-ce.repo 安装docker引擎,默认最新版本 sudo yum install docker-ce docker-ce-cli containerd.io 启动 systemctl enable docker systemctl start docker 测试 docker -v Docker version 19.03.12, build 48a66213fe脚本执行完成后查看harbor组成 和运行状态
docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 3c73fc1bdf49 goharbor/nginx-photon:v2.0.0 "nginx -g 'daemon of…" 44 hours ago Up 44 hours (healthy) 0.0.0.0:80->8080/tcp nginx cc58e0fd2347 goharbor/harbor-jobservice:v2.0.0 "/harbor/entrypoint.…" 44 hours ago Up 44 hours (healthy) harbor-jobservice 7f5929dba6bc goharbor/harbor-core:v2.0.0 "/harbor/entrypoint.…" 44 hours ago Up 44 hours (healthy) harbor-core 001167acd8fc goharbor/harbor-db:v2.0.0 "/docker-entrypoint.…" 44 hours ago Up 44 hours (healthy) 5432/tcp harbor-db 1684303e0782 goharbor/harbor-registryctl:v2.0.0 "/home/harbor/start.…" 44 hours ago Up 44 hours (healthy) registryctl aa4b212f6595 goharbor/redis-photon:v2.0.0 "redis-server /etc/r…" 44 hours ago Up 44 hours (healthy) 6379/tcp redis 79189cffe12a goharbor/registry-photon:v2.0.0 "/home/harbor/entryp…" 44 hours ago Up 44 hours (healthy) 5000/tcp registry c1f45a3e3131 goharbor/harbor-portal:v2.0.0 "nginx -g 'daemon of…" 44 hours ago Up 44 hours (healthy) 8080/tcp harbor-portal 4c85974a6c25 goharbor/harbor-log:v2.0.0 "/bin/sh -c /usr/loc…" 44 hours ago Up 44 hours (healthy) 127.0.0.1:1514->10514/tcp harbor-log docker-compose ps Name Command State Ports --------------------------------------------------------------------------------------------- harbor-core /harbor/entrypoint.sh Up (healthy) harbor-db /docker-entrypoint.sh Up (healthy) 5432/tcp harbor-jobservice /harbor/entrypoint.sh Up (healthy) harbor-log /bin/sh -c /usr/local/bin/ ... Up (healthy) 127.0.0.1:1514->10514/tcp harbor-portal nginx -g daemon off; Up (healthy) 8080/tcp nginx nginx -g daemon off; Up (healthy) 0.0.0.0:80->8080/tcp redis redis-server /etc/redis.conf Up (healthy) 6379/tcp registry /home/harbor/entrypoint.sh Up (healthy) 5000/tcp registryctl /home/harbor/start.sh Up (healthy) 访问 harbor 使用默认用户名密码登录,登录后可修改 admin : Harbor12345注意:选择ldap后,用户认证管理通过ldap控制,不能通过harbor 新增,删除,管理用户组权限
如图:一个项目下,包含这个对项目的镜像仓库管理(项目下的镜像),成员管理(可访问项目的成员),配置管理(白名单,可访问程度等),标签管理(分类表示),机器人账户(通过机器人账户自动pull , push 镜像)管理等功能
系统管理基础功能都集中在上图,左侧菜单栏提供了系统管理的功能,包括用户管理,组管理, 仓库管理,复制管理,标签,项目定额,审查服务,垃圾清理等功能
用户管理 启用ldap后,初次登录后的用户,就会成为系统可展示的用户 组管理 接入ldap后,组管理由ldap的域控决定,由于公司暂无现成的域控分类,所以此处不添加,如果使用数据库认证,这里可自行管理组,方便项目中统一成员管理 仓库管理 ldap 2.0 不仅支持 多个harbor系统之间的镜像同步,也支持向第三方docker仓库同步镜像,这个仓库可供复制管理选择 复制管理 复制管理允许通过一定的策略,向其他仓库同步镜像,比如镜像集群之间的数据同步 标签 这个标签是全局标签 项目定额 项目定额可以设置项目可存储镜像的大小,默认不限制 审查服务 为了镜像安全,审查服务提供了扫描器,扫描镜像是否有漏洞,2.0 以Trivy作为默认扫描器,也可以配置其他扫描器,如clair等,harbor提供prepare脚本支持一键修改 ./prepare --help prepare base dir is set to /home/admin/harbor/harbor Usage: main.py prepare [OPTIONS] Options: --conf TEXT the path of Harbor configuration file --with-notary the Harbor instance is to be deployed with notary --with-clair the Harbor instance is to be deployed with clair --with-trivy the Harbor instance is to be deployed with Trivy --with-chartmuseum the Harbor instance is to be deployed with chart repository supporting --help Show this message and exit. Clean up the input dir 垃圾清理 垃圾清理用来删除指定规则下的镜像Harbor支持远程挂载存储,以解决本地存储不足的情况,支持NFS,OSS,分布式存储等
Harbor搭建好之后,就可以通过docker client上传镜像了,docker安装同上
配置镜像加速 配置阿里云镜像加速器 vim /etc/docker/daemon.json { "data-root": "/data/docker", # docker数据目录,可不修改 "insecure-registries": ["0.0.0.0/0"], # 非安全地址 你的harbor地址 或者0.0.0.0/0 (由于未使用https认证) "registry-mirrors": ["https://xxxx.mirror.aliyuncs.com"] # 阿里云加速地址 自己找 } 重启docker service docker restartsystemd 系统使用如下命令
systemctl restart docker登录私有镜像仓库,如果没有配置上面的非安全地址,会出现401错误
tag 我们从dockerhub pull一个node镜像到本地,然后对这个镜像打tag,可直接复制此处命令做修改 查看拉下来的官网镜像 docker images REPOSITORY TAG IMAGE ID CREATED SIZE node latest 37ad18cd8bd1 2 days ago 943MB对其打 tag,私有需要在tag中加入仓库地址,如下
docker tag node:latest xx.xx.xx.xx/library/zm-node查看镜像
docker images REPOSITORY TAG IMAGE ID CREATED SIZE xx.xx.xx.xx/library/zm-node latest 37ad18cd8bd1 2 days ago 943MB node latest 37ad18cd8bd1 2 days ago 943MB 推送 docker push xx.xx.xx.xx/library/zm-node 查看镜像 至此私有仓库的搭建和测试完成过程中在ldap 和 docker 认证问题上耗时较长,最诡异的问题是 login成功了,push有问题 ,提示 unauthorized to access repository
harbor官方文档 harbor使用手册 k8s harbor 内网协议学习LDAP篇之组和OU介绍