linux cpu占用率如何看
499
2022-10-21
Harbor镜像仓库漏洞扫描_如何检测你的镜像是否安全?
大家好!我是李大白。今天分享的主题是:Harbor漏洞扫描!
前言
在镜像的构建过程中,镜像封装的代码、软件会有不同程度的缺陷,这些缺陷一旦被恶意的者利用,入侵到内部系统进行一系列非法的操作(破坏系统的正常运行和窃取私密的信息)。当缺陷成为漏洞,将会对镜像的安全造成很大的隐患。
Harbor在1.1版本中开始引用CoreOS旗下的开源项目—Clair(现在都2.4版本了,没有谁还在用1.1以下的版本吧!)作为存储和管理的容器镜像的漏洞扫描引擎,以插件化的方式安装在Harbor中,通过插件化的漏洞扫描框架,扫描工具和服务与Harbor进行解耦,安装扫描器插件后,超级管理员(admin)即可在管理界面使用扫描工具了。
1、Harbor支持哪些扫描器?
Harbor的扫描器框架支持多个扫描工具或者服务的配置管理,管理员(admin)可将其中一个扫描器设置为默认的扫描器,如果没有设置,就会使用系统默认的扫描器来扫描项目。
1.1 Clair扫描器
Clair是CoreOS公司的一款开源容器漏洞扫描工具,是一种静态的扫描工具,在扫描过程中不需要实际运行容器,是Harbor默认的两款扫描器之一。
原理:交叉检查容器镜像的操作系统(Alpine、CentOS、Ubuntu、Debian等)——即基础镜像,和安装在操作系统上的软件包和已知具有漏洞的不安全版本是否匹配。
2.2 Trivy 扫描器
Trivy扫描器是以色列安全公司Aqua旗下的一款开源的漏洞扫描工具,主要用于容器和其它Artifact的扫描,也是Harbor默认的两款扫描器之一。
1)Trivy的功能:
能够检测许多操作系统中的漏洞;发现应用程序依赖中的漏洞;在检测漏洞方面具有很高的准确性;扫描过程无状态,不需要数据库等先决条件;
2)Trivy的适用场景
Trivy非常适用于CI场景,很容易集成到Travis CI、CircleCI、Jenkins、GitLab CI等工具中,以完成镜像的漏洞扫描。
2.3 Anchore
Anchore是美国一家安全公司旗下的开源项目,可以实现容器镜像检查、分析和认证提供中心服务。这个楼主也没用过,本文就不详细介绍了,有兴趣可自行百度。
2.4 Aqua CSP
Aqua CSP是Aqua公司旗下专注于云原生平台与环境安全的平台服务,其目标是加速容器采用并缩小DevOps与IT安全之间的差距。
Aqua CSP比较复杂,Harbor虽然也支持,但在Harbor中使用Aqua CSP并不受到推荐。
2.5 DosSec
DosSec扫描器是中国小佑科技开发,是目前唯一支持中文漏洞库的扫描器。这个楼主也没完过,有时间研究下。
2、启用插件化的扫描工具
2.1、安装Harbor时安装扫描器
[root@Over harbor]# ./install.sh --helpNote: Please set hostname and other necessary attributes in harbor.yml first. DO NOT use localhost or 127.0.0.1 for hostname, because Harbor needs to be accessed by external clients.Please set --with-notary if needs enable Notary in Harbor, and set ui_url_protocol/ssl_cert/ssl_cert_key in harbor.yml bacause notary must run under Please set --with-trivy if needs enable Trivy in HarborPlease set --with-chartmuseum if needs enable Chartmuseum in Harbor[root@Over harbor]# ./install.sh --with-trivy
2.2、Harbor已启动后才安装扫描器
如果Harbor已经运行,再安装扫描器的化,则需要先停止Harbor的运行,再安装扫描器。
1)停止Harbor
生产环境需要事先沟通好,避免影响到业务。
[root@Over harbor]# docker-compose downStopping nginx ... doneStopping harbor-jobservice ... doneStopping harbor-core ... doneStopping registryctl ... doneStopping harbor-portal ... doneStopping harbor-db ... doneStopping redis ... doneStopping registry ... doneStopping harbor-log ... doneRemoving nginx ... doneRemoving harbor-jobservice ... doneRemoving harbor-core ... doneRemoving registryctl ... doneRemoving harbor-portal ... doneRemoving harbor-db ... doneRemoving redis ... doneRemoving registry ... doneRemoving harbor-log ... doneRemoving network harbor_harbor
2)到harbor工作目录执行./prepare
[root@Over harbor]# ./prepare prepare base dir is set to /app/harborClearing the configuration file: /config/portal/nginx.confClearing the configuration file: /config/log/logrotate.confClearing the configuration file: /config/log/rsyslog_docker.confClearing the configuration file: /config/nginx/nginx.confClearing the configuration file: /config/core/envClearing the configuration file: /config/core/app.confClearing the configuration file: /config/registry/passwdClearing the configuration file: /config/registry/config.ymlClearing the configuration file: /config/registry/root.crtClearing the configuration file: /config/registryctl/envClearing the configuration file: /config/registryctl/config.ymlClearing the configuration file: /config/db/envClearing the configuration file: /config/jobservice/envClearing the configuration file: /config/jobservice/config.ymlGenerated configuration file: /config/portal/nginx.confGenerated configuration file: /config/log/logrotate.confGenerated configuration file: /config/log/rsyslog_docker.confGenerated configuration file: /config/nginx/nginx.confGenerated configuration file: /config/core/envGenerated configuration file: /config/core/app.confGenerated configuration file: /config/registry/config.ymlGenerated configuration file: /config/registryctl/envGenerated configuration file: /config/registryctl/config.ymlGenerated configuration file: /config/db/envGenerated configuration file: /config/jobservice/envGenerated configuration file: /config/jobservice/config.ymlloaded secret from file: /data/secret/keys/secretkeyGenerated configuration file: /compose_location/docker-compose.ymlClean up the input dir
3)安装Trivy扫描器
[root@Over harbor]# ./install.sh --with-trivy......✔ ----Harbor has been installed and started successfully.----
4)验证是否安装成功
[root@Over harbor]# docker-compose ps Name Command State Ports ---------------------------------------------------------------------------------------------------------------harbor-core /harbor/entrypoint.sh Up (healthy) harbor-db /docker-entrypoint.sh 96 13 Up (healthy) 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) nginx nginx -g daemon off; Up (healthy) 0.0.0.0:80->8080/tcp, 0.0.0.0:443->8443/tcpredis redis-server /etc/redis.conf Up (healthy) registry /home/harbor/entrypoint.sh Up (healthy) registryctl /home/harbor/start.sh Up (healthy) trivy-adapter /home/scanner/entrypoint.sh Up (healthy)
可以看到trivy的容器已经运行,表示安装成功。
5) UI界面查看
登录Harbor UI界面==> 【项目】==>【扫描器】即可看到已经安装的扫描器。
3、使用漏洞扫描功能
安装好扫描器后,就可以在Harbor管理界面使用扫描器进行漏洞扫描了。命令行使用则需要调用Harbor API来实现了(本处暂时不详细表述了),本处以Trivy扫描器为例。
3.1 进入扫描管理页面
【系统管理】——>【审查服务】
3.2 项目漏洞扫描
扫描状态说明
已入队列:扫描过程的起始阶段,已创建扫描任务,但未执行扫描;扫描中:正在进行扫描,但还未完成;失败:扫描过程因为遇到不可忽略的错误导致扫描未成功完成,可通过系统扫描的日志信息排查;成功:扫描过程成功,并生成对应的扫描报告。
3.3 全局漏洞扫描
在项目内的扫描操作,只能针对特定仓库下选中镜像(Artifact),扫描效率较低,可使用全局扫描功能来扫描所有项目下所有的镜像。
全局漏洞扫描可手动触发,也可设置定时任务触发。
操作:【系统管理】——【审查服务】——【漏洞】
定时任务扫描
定时任务格式:秒 分钟 小时 每日 每月 周
例:每天早上8点启动全局漏洞扫描任务
0 0 8 * * *
3.4 自动扫描
在系统上传到项目成功后,系统自动对其进行扫描操作并生成相关报告。
【项目】——【项目名】——【配置管理】
3.5 阻止有漏洞的镜像部署到容器中
当镜像经过漏洞扫描发现存在漏洞后,可以在【部署安全】-【阻止潜在漏洞镜像】选项阻止不同漏洞级别的镜像部署。
3.6 CVE白名单
如果某个镜像存在漏洞,但部署者可以接收这种漏洞,想继续使用该镜像来部署服务,则可以使用CVE特赦白名单。
【系统管理】——【配置管理】——【系统设置】——【部署安全性】
补充:
进行漏洞扫描后,扫描结果数据存放于./data/trivy-adapter/trivy/db/trivy.db文件中。
~完~
思考:
Harbor的默认扫描器有哪些?
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~