首页 > 其他分享 >容器安全之镜像扫描

容器安全之镜像扫描

时间:2023-03-31 09:36:05浏览次数:44  
标签:容器 scan 扫描 https 镜像 docker Docker

目录

一、镜像扫描

  1. docker scan
  2. Trivy(推荐使用)
  3. clair
  4. harbor-scanner 支持中文漏洞库

针对上述解决方案,我们调查了 TrivyClaireAnchore EngineQuayDocker hubGCR 等几种扫描工具,从不同维度进行对比。(来源于网络)

img

本文主要介绍下 docker scanTrivy

二、镜像扫描可以存在的场景

  1. 构建镜像的整个流水线

    Jenkins 或者 gitlab Runner集成

    1. docker scan
    2. Trivy
  2. 镜像仓库定期扫描

    1. harbor-scanner-trivy
    2. harbor-scanner
  3. 运行时,在镜像拉取到主机节点,启动时扫描镜像漏洞,禁止镜像运行。

    1. ImagePolicyWebhook

三、 docker scan

Docker 本地镜像的漏洞扫描

docker scandocker 官方推出来的插件。

使用之前需要安装此插件

3.1、Centos 安装插件

yum install docker-scan-plugin

获取当前安装的版本

docker scan --accept-license --version
Version:    v0.12.0
Git commit: 1074dd0
Provider:   Snyk (1.790.0 (standalone))

3.2、登录 dockerhub 用户

在使用 docker scan 之前,我们需要登录我们的 dockerhub 用户,否则扫描不了。

[root@ops-111-111 ~]# docker scan hello-world
Docker Scan relies upon access to Snyk, a third party provider, do you consent to proceed using Snyk? (y/N)
y
failed to get DockerScanID: You need to be logged in to Docker Hub to use the scan feature.

If you are not using Docker Desktop, either
- use the "docker login" CLI command with a username and password. Note this will not work if
  2FA is required or if SSO enforcement is enabled on Docker Hub; or
- use the "docker login" CLI command with a username and Personal Access Token. This requires
  a token to be generated in advance.

If you are using Docker Desktop: login via the UI or whale menu

登录

[root@ops-111-111 ~]# docker login 
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: djxslp
Password: 
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded

3.3、扫描

[root@ops-111-111 ~]# docker scan hello-world

Testing hello-world...

Package manager:   linux
Project name:      docker-image|hello-world
Docker image:      hello-world
Platform:          linux/amd64

✔ Tested hello-world for known vulnerabilities, no vulnerable paths found.

Note that we do not currently have vulnerability data for your image.

For more free scans that keep your images secure, sign up to Snyk at https://dockr.ly/3ePqVcp

3.4、使用限制

免费扫描限制为10/月。

四、Trivy(推荐使用)

Trivy 是 漏洞、配置错误、Secret 等 全面且多功能的安全扫描仪。

GitHub - aquasecurity/trivy: Find vulnerabilities, misconfigurations, secrets, SBOM in containers, Kubernetes, code repositories, clouds and more

阿里云镜像仓库,镜像云安全扫描引擎也默认提供Trivy扫描引擎

支持扫描

  • Container Image
  • Filesystem
  • Git Repository (remote)
  • Virtual Machine Image
  • Kubernetes
  • AWS

4.1、 安装

wget https://github.com/aquasecurity/trivy/releases/download/v0.38.1/trivy_0.38.1_Linux-64bit.deb
apt install trivy_0.38.1_Linux-64bit.deb

示例命令

trivy image python:3.4-alpine

trivy image  -s  HIGH   python:3.4-alpine  # 指定漏洞等级

trivy k8s --report summary cluster # 扫描集群

4.2、下载DB

注意下载 DB 是比较慢的,如果我们有对应的梯子,可以用的话最好使用梯子。 我这边是通过我电脑的 Clash 监听的端口,然后我服务器配置 http 和 https 代理。

2023-03-29T10:10:09.318+0800	INFO	Need to update DB
2023-03-29T10:10:09.318+0800	INFO	DB Repository: ghcr.io/aquasecurity/trivy-db
2023-03-29T10:10:09.318+0800	INFO	Downloading DB...

临时使用代理

export http_proxy="http://http_proxy:7890"
export https_proxy="http://http_proxy:7890"

4.3、使用

trivy  image -s MEDIUM,HIGH,CRITICAL  test-demo  --timeout 30m 

结果

Total: 752 (MEDIUM: 688, HIGH: 61, CRITICAL: 3)
┌──────────────────────────┬──────────────────┬──────────┬───────────────────────┬──────────────────────────┬──────────────────────────────────────────────────────────────┐
│         Library          │  Vulnerability   │ Severity │   Installed Version   │      Fixed Version       │                            Title                             │
├──────────────────────────┼──────────────────┼──────────┼───────────────────────┼──────────────────────────┼──────────────────────────────────────────────────────────────┤
│ audit-libs               │ CVE-2015-5186    │ MEDIUM   │ 2.8.1-3.el7           │                          │ Audit: log terminal emulator escape sequences handling       │
│                          │                  │          │                       │                          │ https://avd.aquasec.com/nvd/cve-2015-5186                    │
├──────────────────────────┼──────────────────┤          ├───────────────────────┼──────────────────────────┼──────────────────────────────────────────────────────────────┤
│ bash                     │ CVE-2012-6711    │          │ 4.2.46-30.el7         │                          │ bash: heap-based buffer overflow during echo of unsupported  │
│                          │                  │          │                       │                          │ characters                                                   │
│                          │                  │          │                       │                          │ https://avd.aquasec.com/nvd/cve-2012-6711                    │
│                          ├──────────────────┤          │                       ├──────────────────────────┼──────────────────────────────────────────────────────────────┤
│                          │ CVE-2019-9924    │          │                       │ 4.2.46-34.el7            │ bash: BASH_CMD is writable in restricted bash shells         │
│                          │                  │          │                       │                          │ https://avd.aquasec.com/nvd/cve-2019-9924                    │
Java (jar)
==========
Total: 14 (MEDIUM: 2, HIGH: 10, CRITICAL: 2)

┌─────────────────────────────────────────────────┬────────────────┬──────────┬───────────────────┬──────────────────────────────────────────────────────┬─────────────────────────────────────────────────────────────┐
│                     Library                     │ Vulnerability  │ Severity │ Installed Version │                    Fixed Version                     │                            Title                            │
├─────────────────────────────────────────────────┼────────────────┼──────────┼───────────────────┼──────────────────────────────────────────────────────┼─────────────────────────────────────────────────────────────┤
│                                                 │ CVE-2019-10247 │ MEDIUM   │                   │ 9.2.28.v20190418, 9.3.27.v20190418, 9.4.17.v20190418 │ jetty: error path information disclosure                    │
│                                                 │                │          │                   │                                                      │ https://avd.aquasec.com/nvd/cve-2019-10247                  │
├─────────────────────────────────────────────────┼────────────────┼──────────┤      

五、镜像扫描到部署阶段

5.1、ImagePolicyWebhook 容器镜像扫描

具体的操作可以查看 k8s 官方文档: ImagePolicyWebhook

其中我们可以看到需要调用到第三方的webhook, 是存在一个kainlite/kube-image-bouncer:ImagePolicyWebhook 和 GenericAdmissionWebhook Kubernetes 入场控制器的简单端点 (github.com) 组件。 这个组件实现的内容就是判断我们当前的镜像是否为 latest 的镜像。 是返回 "allowed": false

我们其实是可以对于这个组件进行改造,增加一些定制化的内容, 比如去调用一些接口获取对应的镜像的安全扫描结果,如果扫描结果是pass 的话,就可以部署,否则的话,就不允许部署。

标签:容器,scan,扫描,https,镜像,docker,Docker
From: https://www.cnblogs.com/operationhome/p/17275175.html

相关文章

  • Spring-容器启动流程
    1,Spring容器启动三个过程1、初始化Spring容器,注册内置的BeanPostProcessor的BeanDefinition到容器中2、将配置类的BeanDefinition注册到容器中3、调用refresh()方法刷新容器  因为是基于java-config技术分析源码,所以这里的入口是AnnotationConfigApplicationCon......
  • 容器类型 - 3
    6.容器类型-3字典引入场景一:声明一个列表nameList=['张三','李四','王五']如果发现"李四"这个名字写错了,通过下标修改nameList[1]='赵六'但是如果列表元素的顺序发生了变化,如下列代码nameList=['张三','王五','李四']此时就必须需要修改下标,才能完......
  • 容器类型 - 2
    5.容器类型-2元组什么是元组元组是存储多个数据的一种方式元组与列表类似,不同之处在于元组的元素不能修改元组使用小括号(),列表使用方括号[]>>>aTuple=('et',77,99.9)>>>aTuple('et',77,99.9)元组的使用访问元组#定义一个元组nums=(100,200,300)#获......
  • 容器类型 - 1
    4.容器类型-1字符串介绍定义如下定义的变量a,存储的是数字类型的值a=100如下定义的变量b,存储的是字符串类型的值b="www.tulingxueyuan.com"#或者b='www.tulingxueyuan.com'小总结:双引号或者单引号中的数据,就是字符串下标下标:就是标记空间的一个数字有些......
  • docker build 构建时 alpinelinux 镜像权限错误
    问题使用dockerbuild构建镜像时,发生一个错误:“ERROR:https://dl-cdn.alpinelinux.org/alpine/v3.15/main:Permissiondenied”。部分日志如下:[2023-03-3014:51:12]Step3/16:RUNapkupdate&&apkupgrade&&apkaddmusl-devmakegccpython3[2023-03-3014:51:12......
  • SpringBoot中如何动态加载类到容器
    任何业务脱离场景无任何实际意义。场景:1,实现了多种存储方式,redis和本地内存或者其它,但是你希望根据注解配置只加载一种类到容器。2,经典场景:mybatis将接口的代理类动态加载到容器。分类:静态加载:1,springboot中会扫描同包路径下的(@configuration@Service@Component)标记了上述......
  • 云原生容器高可用运维能力应用
    摘要:华为云容器SRE在海量集群和容器运维实践中,从智能运维能力、确定性场景恢复等多方面总结出一套确定性运维实践,以应对云原生业务快速增长。本文分享自华为云社区《云原......
  • 应用上容器云的准入条件和最佳实践
    随着Kubernetes的发展,现在有一个新的技术趋势:在容器云中以Pod的方式运行虚拟机,这样容器云平台就能够提供普通容器无法实现的功能。相信通过类似的技术,越来越多的应用会向容......
  • cAdvisor+Pro+Grafana 监控Docker容器
    cAdvisor(ContainerAdvisor) Google 开源的一个容器监控工具,可用于对容器资源的使用情况和性能进行监控。用于收集、聚合、处理和导出正在运行容器的有关信息。具体来......
  • 容器核心技术Cgroups和Namespace
    |什么是Cgroups简单一句话描述Cgroups:Cgroups是Linux内核提供的一种可以限制单个进程或者多个进程所使用资源的机制,可以对cpu,内存等资源实现精细化的控制。Cgroups全称是......