当前位置:   article > 正文

云原生|kubernetes|安全漏扫神器trivy的部署和使用

云原生|kubernetes|安全漏扫神器trivy的部署和使用

前言:

云原生领域内的安全漏扫工具有clair和trivy是比较常用的,而安全漏扫工具是可以和harbor这样的私有仓库集成的,自harbor-1.21版以后都是默认使用trivy这个漏扫工具的,而在此之前是使用clair的。

那么,本文将就什么是trivy,trivy如何正确的部署,如何正确的使用做一个简单的探讨。

一,

什么是trivy?

trivy是一个主要运用在云原生领域的安全漏扫工具,是一种易于使用的开源漏洞扫描器,可帮助团队“左移”将安全性纳入构建管道。

那么,trivy的工作范围主要是对用于生产或者即将用于生产的镜像进行安全漏洞扫描,例如,centos的某个基础镜像,这个 CentOS 在 2021 年 7 月 29 日至 8 月 10 日期间的下载量已超过 700 万次,但该镜像具有大量未修补漏洞并且没有正式弃用。如果在生产中使用这样的镜像无疑是一个巨大的安全隐患。

其次是文件系统,也可以扫描git 远程仓库以及kubernetes集群和kubernetes内的资源。

  1. Targets:
  2. - Container Image
  3. - Filesystem
  4. - Git repository (remote)
  5. - Kubernetes cluster or resource

二,

如何正确的部署trivy?

trivy的安装方式比较多,可以rpm的形式安装,也可以apt的形式安装,也可以helm形式的直接集成到kubernetes内,也可以直接docker run 镜像的方式部署。

那么,比较常见的也是难度比较小的是rpm形式安装了。

下面是部署方式,

  1. Get Trivy by your favorite installation method. See [installation] section in the documentation for details. For example:
  2. - `apt-get install trivy`
  3. - `yum install trivy`
  4. - `brew install aquasecurity/trivy/trivy`
  5. - `docker run aquasec/trivy`
  6. - Download binary from https://github.com/aquasecurity/trivy/releases/latest/

这么说还是比较抽象,直接从GitHub下载rpm包上传到服务器上安装即可,我这里的服务器是centos7 64位的机器,因此选择下载trivy_0.34.0_Linux-64bit.rpm

下载地址:  Release v0.34.0 · aquasecurity/trivy · GitHub

 rpm安装就不用说了,直接安装即可,没有依赖。

trivy使用中的主要的困扰是需要联网从GitHub下载trivy-db 数据库,虽然有离线的trivy-db下载,但离线的通常是v1版本的,而高版本的trivy是使用的是v2

目前还没有比较好的解决办法,只有科学上网这一个办法了。

Releases · aquasecurity/trivy-db · GitHub

 

三,

trivy的使用

kubernetes集群的检测

检测内容有kubernetes集群的所有镜像,集群使用的role和clusterrole和静态pod

  1. [root@k8s-master ~]# trivy k8s --report summary cluster
  2. 2023-01-06T04:56:44.547+0800 INFO Need to update DB
  3. 2023-01-06T04:56:44.547+0800 INFO DB Repository: ghcr.io/aquasecurity/trivy-db
  4. 2023-01-06T04:56:44.547+0800 INFO Downloading DB...
  5. 35.96 MiB / 35.96 MiB [------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------] 100.00% 5.23 MiB p/s 7.1s
  6. 159 / 159 [------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------] 100.00% 1 p/s
  7. Summary Report for kubernetes-admin@kubernetes
  8. Workload Assessment
  9. ┌─────────────┬────────────────────────────────────────┬────────────────────────┬────────────────────┬───────────────────┐
  10. │ Namespace │ Resource │ Vulnerabilities │ Misconfigurations │ Secrets │
  11. │ │ ├────┬─────┬────┬────┬───┼───┬───┬───┬────┬───┼───┬───┬───┬───┬───┤
  12. │ │ │ C │ H │ M │ L │ U │ C │ H │ M │ L │ U │ C │ H │ M │ L │ U │
  13. ├─────────────┼────────────────────────────────────────┼────┼─────┼────┼────┼───┼───┼───┼───┼────┼───┼───┼───┼───┼───┼───┤
  14. │ kube-system │ DaemonSet/kube-flannel-ds │ 12 │ 124 │ 56 │ 16 │ 4 │ │ 1 │ 7 │ 16 │ │ │ │ │ │ │
  15. │ kube-system │ Pod/kube-controller-manager-k8s-master │ │ │ │ │ │ │ 1 │ 3 │ 8 │ │ │ │ │ │ │
  16. │ kube-system │ Service/kube-dns │ │ │ │ │ │ │ │ 1 │ │ │ │ │ │ │ │
  17. │ kube-system │ Pod/kube-apiserver-k8s-master │ │ │ │ │ │ │ 1 │ 3 │ 9 │ │ │ │ │ │ │
  18. │ kube-system │ DaemonSet/kube-proxy │ 15 │ 14 │ 20 │ 58 │ │ │ 2 │ 4 │ 10 │ │ │ │ │ │ │
  19. │ kube-system │ Pod/etcd-k8s-master │ │ 16 │ 8 │ │ │ │ 1 │ 3 │ 7 │ │ │ │ │ │ │
  20. │ kube-system │ Deployment/coredns │ │ 7 │ 3 │ 1 │ │ │ │ 3 │ 5 │ │ │ │ │ │ │
  21. │ kube-system │ Pod/kube-scheduler-k8s-master │ │ │ │ │ │ │ 1 │ 3 │ 8 │ │ │ │ │ │ │
  22. │ default │ Job/kube-bench │ 5 │ 34 │ 9 │ 1 │ │ │ 1 │ 3 │ 10 │ │ │ │ │ │ │
  23. │ default │ Job/kube-bench-master │ 1 │ 30 │ 9 │ 1 │ │ │ 1 │ 4 │ 10 │ │ │ │ │ │ │
  24. └─────────────┴────────────────────────────────────────┴────┴─────┴────┴────┴───┴───┴───┴───┴────┴───┴───┴───┴───┴───┴───┘
  25. Severities: C=CRITICAL H=HIGH M=MEDIUM L=LOW U=UNKNOWN
  26. RBAC Assessment
  27. ┌─────────────┬─────────────────────────────────────────────────────────────────┬───────────────────┐
  28. │ Namespace │ Resource │ RBAC Assessment │
  29. │ │ ├───┬───┬───┬───┬───┤
  30. │ │ │ C │ H │ M │ L │ U │
  31. ├─────────────┼─────────────────────────────────────────────────────────────────┼───┼───┼───┼───┼───┤
  32. │ kube-system │ Role/system::leader-locking-kube-scheduler │ │ │ 1 │ │ │
  33. │ kube-system │ Role/system:controller:bootstrap-signer │ 1 │ │ │ │ │
  34. │ kube-system │ Role/system:controller:token-cleaner │ 1 │ │ │ │ │
  35. │ kube-system │ Role/system::leader-locking-kube-controller-manager │ │ │ 1 │ │ │
  36. │ kube-system │ Role/system:controller:cloud-provider │ │ │ 1 │ │ │
  37. │ kube-public │ Role/system:controller:bootstrap-signer │ │ │ 1 │ │ │
  38. │ │ ClusterRole/system:controller:horizontal-pod-autoscaler │ 1 │ │ │ │ │
  39. │ │ ClusterRole/system:controller:deployment-controller │ │ 2 │ │ │ │
  40. │ │ ClusterRole/edit │ 2 │ 7 │ 1 │ │ │
  41. │ │ ClusterRole/admin │ 3 │ 7 │ 1 │ │ │
  42. │ │ ClusterRole/system:controller:cronjob-controller │ │ 2 │ │ │ │
  43. │ │ ClusterRole/system:controller:endpointslicemirroring-controller │ │ 1 │ │ │ │
  44. │ │ ClusterRole/system:kube-controller-manager │ 5 │ 2 │ │ │ │
  45. │ │ ClusterRole/system:aggregate-to-edit │ 2 │ 7 │ 1 │ │ │
  46. │ │ ClusterRole/system:controller:persistent-volume-binder │ 1 │ 2 │ │ │ │
  47. │ │ ClusterRole/system:controller:root-ca-cert-publisher │ │ │ 1 │ │ │
  48. │ │ ClusterRole/system:controller:replicaset-controller │ │ 1 │ │ │ │
  49. │ │ ClusterRole/system:aggregate-to-admin │ 1 │ │ │ │ │
  50. │ │ ClusterRole/system:controller:resourcequota-controller │ 1 │ │ │ │ │
  51. │ │ ClusterRole/system:controller:endpoint-controller │ │ 1 │ │ │ │
  52. │ │ ClusterRole/system:node │ 1 │ │ │ │ │
  53. │ │ ClusterRole/system:controller:replication-controller │ │ 1 │ │ │ │
  54. │ │ ClusterRole/system:controller:job-controller │ │ 1 │ │ │ │
  55. │ │ ClusterRole/system:controller:endpointslice-controller │ │ 1 │ │ │ │
  56. │ │ ClusterRole/system:controller:expand-controller │ 1 │ │ │ │ │
  57. │ │ ClusterRole/cluster-admin │ 2 │ │ │ │ │
  58. │ │ ClusterRole/system:controller:namespace-controller │ 1 │ │ │ │ │
  59. │ │ ClusterRole/system:controller:generic-garbage-collector │ 1 │ │ │ │ │
  60. │ │ ClusterRole/system:kube-scheduler │ │ 2 │ │ │ │
  61. └─────────────┴─────────────────────────────────────────────────────────────────┴───┴───┴───┴───┴───┘
  62. Severities: C=CRITICAL H=HIGH M=MEDIUM L=LOW U=UNKNOWN
  63. Infra Assessment
  64. ┌─────────────┬────────────────────────────────────────┬─────────────────────────────┐
  65. │ Namespace │ Resource │ Kubernetes Infra Assessment │
  66. │ │ ├────┬────┬────┬─────┬────────┤
  67. │ │ │ C │ H │ M │ L │ U │
  68. ├─────────────┼────────────────────────────────────────┼────┼────┼────┼─────┼────────┤
  69. │ kube-system │ Pod/kube-apiserver-k8s-master │ │ │ 1 │ 10 │ │
  70. │ kube-system │ Pod/kube-controller-manager-k8s-master │ │ │ │ 3 │ │
  71. │ kube-system │ Pod/kube-scheduler-k8s-master │ │ │ │ 1 │ │
  72. └─────────────┴────────────────────────────────────────┴────┴────┴────┴─────┴────────┘
  73. Severities: C=CRITICAL H=HIGH M=MEDIUM L=LOW U=UNKNOWN

检测namespace kube-system下的所有镜像:

  1. a=`kubectl get po -n kube-system --output=custom-columns="IMAGE:.spec.containers[*].image"`
  2. for i in $a;do trivy image --skip-update -s 'HIGH,CRITICAL' $i;done

这里解释一下,kubectl get po -n kube-system  --output=custom-columns="IMAGE:.spec.containers[*].image"是获取namespace下所有镜像的名称

  1. [root@k8s-master ~]# kubectl get po -n kube-system --output=custom-columns="IMAGE:.spec.containers[*].image"
  2. IMAGE
  3. registry.aliyuncs.com/google_containers/coredns:v1.8.6
  4. registry.aliyuncs.com/google_containers/coredns:v1.8.6
  5. registry.aliyuncs.com/google_containers/etcd:3.5.6-0
  6. registry.aliyuncs.com/google_containers/kube-apiserver:v1.23.15
  7. registry.aliyuncs.com/google_containers/kube-controller-manager:v1.23.15
  8. quay.io/coreos/flannel:v0.13.0
  9. quay.io/coreos/flannel:v0.13.0
  10. quay.io/coreos/flannel:v0.13.0
  11. registry.aliyuncs.com/google_containers/kube-proxy:v1.23.15
  12. registry.aliyuncs.com/google_containers/kube-proxy:v1.23.15
  13. registry.aliyuncs.com/google_containers/kube-proxy:v1.23.15
  14. registry.aliyuncs.com/google_containers/kube-scheduler:v1.23.15

然后把这些镜像名称赋值给了变量a, 然后for循环trivy 检测这些镜像,检测的结果如下:

  1. 前面的内容略略略了
  2. registry.aliyuncs.com/google_containers/kube-proxy:v1.23.15 (debian 11.0)
  3. =========================================================================
  4. Total: 29 (HIGH: 14, CRITICAL: 15)
  5. ┌─────────────────┬────────────────┬──────────┬───────────────────┬─────────────────────────┬──────────────────────────────────────────────────────────────┐
  6. │ Library │ Vulnerability │ Severity │ Installed Version │ Fixed Version │ Title │
  7. ├─────────────────┼────────────────┼──────────┼───────────────────┼─────────────────────────┼──────────────────────────────────────────────────────────────┤
  8. │ dpkg │ CVE-2022-1664 │ CRITICAL │ 1.20.9 │ 1.20.10 │ Dpkg::Source::Archive in dpkg, the Debian package management │
  9. │ │ │ │ │ │ system, b ... │
  10. │ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2022-1664 │
  11. ├─────────────────┼────────────────┼──────────┼───────────────────┼─────────────────────────┼──────────────────────────────────────────────────────────────┤
  12. │ gzip │ CVE-2022-1271 │ HIGH │ 1.10-4 │ 1.10-4+deb11u1 │ gzip: arbitrary-file-write vulnerability │
  13. │ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2022-1271 │
  14. ├─────────────────┼────────────────┼──────────┼───────────────────┼─────────────────────────┼──────────────────────────────────────────────────────────────┤
  15. │ libc-bin │ CVE-2021-33574 │ CRITICAL │ 2.31-13 │ 2.31-13+deb11u3 │ glibc: mq_notify does not handle separately allocated thread │
  16. │ │ │ │ │ │ attributes │
  17. │ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2021-33574 │
  18. │ ├────────────────┤ │ │ ├──────────────────────────────────────────────────────────────┤
  19. │ │ CVE-2022-23218 │ │ │ │ glibc: Stack-based buffer overflow in svcunix_create via │
  20. │ │ │ │ │ │ long pathnames │
  21. │ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2022-23218 │
  22. │ ├────────────────┤ │ │ ├──────────────────────────────────────────────────────────────┤
  23. │ │ CVE-2022-23219 │ │ │ │ glibc: Stack-based buffer overflow in sunrpc clnt_create via │
  24. │ │ │ │ │ │ a long pathname │
  25. │ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2022-23219 │
  26. │ ├────────────────┼──────────┤ ├─────────────────────────┼──────────────────────────────────────────────────────────────┤
  27. │ │ CVE-2021-3999 │ HIGH │ │ 2.31-13+deb11u4 │ glibc: Off-by-one buffer overflow/underflow in getcwd() │
  28. │ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2021-3999 │
  29. ├─────────────────┼────────────────┼──────────┤ ├─────────────────────────┼──────────────────────────────────────────────────────────────┤
  30. │ libc6 │ CVE-2021-33574 │ CRITICAL │ │ 2.31-13+deb11u3 │ glibc: mq_notify does not handle separately allocated thread │
  31. │ │ │ │ │ │ attributes │
  32. │ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2021-33574 │
  33. │ ├────────────────┤ │ │ ├──────────────────────────────────────────────────────────────┤
  34. │ │ CVE-2022-23218 │ │ │ │ glibc: Stack-based buffer overflow in svcunix_create via │
  35. │ │ │ │ │ │ long pathnames │
  36. │ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2022-23218 │
  37. │ ├────────────────┤ │ │ ├──────────────────────────────────────────────────────────────┤
  38. │ │ CVE-2022-23219 │ │ │ │ glibc: Stack-based buffer overflow in sunrpc clnt_create via │
  39. │ │ │ │ │ │ a long pathname │
  40. │ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2022-23219 │
  41. │ ├────────────────┼──────────┤ ├─────────────────────────┼──────────────────────────────────────────────────────────────┤
  42. │ │ CVE-2021-3999 │ HIGH │ │ 2.31-13+deb11u4 │ glibc: Off-by-one buffer overflow/underflow in getcwd() │
  43. │ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2021-3999 │
  44. ├─────────────────┼────────────────┤ ├───────────────────┼─────────────────────────┼──────────────────────────────────────────────────────────────┤
  45. │ libcom-err2 │ CVE-2022-1304 │ │ 1.46.2-2 │ │ e2fsprogs: out-of-bounds read/write via crafted filesystem │
  46. │ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2022-1304 │
  47. ├─────────────────┼────────────────┼──────────┼───────────────────┼─────────────────────────┼──────────────────────────────────────────────────────────────┤
  48. │ libdb5.3 │ CVE-2019-8457 │ CRITICAL │ 5.3.28+dfsg1-0.8 │ │ sqlite: heap out-of-bound read in function rtreenode() │
  49. │ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2019-8457 │
  50. ├─────────────────┼────────────────┼──────────┼───────────────────┼─────────────────────────┼──────────────────────────────────────────────────────────────┤
  51. │ libgcrypt20 │ CVE-2021-33560 │ HIGH │ 1.8.7-6 │ │ libgcrypt: mishandles ElGamal encryption because it lacks │
  52. │ │ │ │ │ │ exponent blinding to address a... │
  53. │ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2021-33560 │
  54. ├─────────────────┼────────────────┤ ├───────────────────┼─────────────────────────┼──────────────────────────────────────────────────────────────┤
  55. │ libgmp10 │ CVE-2021-43618 │ │ 2:6.2.1+dfsg-1 │ 2:6.2.1+dfsg-1+deb11u1 │ gmp: Integer overflow and resultant buffer overflow via │
  56. │ │ │ │ │ │ crafted input │
  57. │ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2021-43618 │
  58. ├─────────────────┼────────────────┤ ├───────────────────┼─────────────────────────┼──────────────────────────────────────────────────────────────┤
  59. │ libgnutls30 │ CVE-2022-2509 │ │ 3.7.1-5 │ 3.7.1-5+deb11u2 │ gnutls: Double free during gnutls_pkcs7_verify │
  60. │ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2022-2509 │
  61. ├─────────────────┼────────────────┤ ├───────────────────┼─────────────────────────┼──────────────────────────────────────────────────────────────┤
  62. │ liblzma5 │ CVE-2022-1271 │ │ 5.2.5-2 │ 5.2.5-2.1~deb11u1 │ gzip: arbitrary-file-write vulnerability │
  63. │ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2022-1271 │
  64. ├─────────────────┼────────────────┼──────────┼───────────────────┼─────────────────────────┼──────────────────────────────────────────────────────────────┤
  65. │ libpcre2-8-0 │ CVE-2022-1586 │ CRITICAL │ 10.36-2 │ 10.36-2+deb11u1 │ pcre2: Out-of-bounds read in compile_xclass_matchingpath in
  66. │ │ │ │ │ │ pcre2_jit_compile.c │
  67. │ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2022-1586 │
  68. │ ├────────────────┤ │ │ ├──────────────────────────────────────────────────────────────┤
  69. │ │ CVE-2022-1587 │ │ │ │ pcre2: Out-of-bounds read in get_recurse_data_length in
  70. │ │ │ │ │ │ pcre2_jit_compile.c │
  71. │ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2022-1587 │
  72. ├─────────────────┼────────────────┤ ├───────────────────┼─────────────────────────┼──────────────────────────────────────────────────────────────┤
  73. │ libssl1.1 │ CVE-2021-3711 │ │ 1.1.1k-1 │ 1.1.1k-1+deb11u1 │ openssl: SM2 Decryption Buffer Overflow │
  74. │ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2021-3711 │
  75. │ ├────────────────┤ │ ├─────────────────────────┼──────────────────────────────────────────────────────────────┤
  76. │ │ CVE-2022-1292 │ │ │ 1.1.1n-0+deb11u2 │ openssl: c_rehash script allows command injection │
  77. │ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2022-1292 │
  78. │ ├────────────────┤ │ ├─────────────────────────┼──────────────────────────────────────────────────────────────┤
  79. │ │ CVE-2022-2068 │ │ │ 1.1.1n-0+deb11u3 │ openssl: the c_rehash script allows command injection │
  80. │ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2022-2068 │
  81. │ ├────────────────┼──────────┤ ├─────────────────────────┼──────────────────────────────────────────────────────────────┤
  82. │ │ CVE-2021-3712 │ HIGH │ │ 1.1.1k-1+deb11u1 │ openssl: Read buffer overruns processing ASN.1 strings │
  83. │ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2021-3712 │
  84. │ ├────────────────┤ │ ├─────────────────────────┼──────────────────────────────────────────────────────────────┤
  85. │ │ CVE-2022-0778 │ │ │ 1.1.1k-1+deb11u2 │ openssl: Infinite loop in BN_mod_sqrt() reachable when │
  86. │ │ │ │ │ │ parsing certificates │
  87. │ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2022-0778 │
  88. ├─────────────────┼────────────────┼──────────┼───────────────────┼─────────────────────────┼──────────────────────────────────────────────────────────────┤
  89. │ libtasn1-6 │ CVE-2021-46848 │ CRITICAL │ 4.16.0-2 │ 4.16.0-2+deb11u1 │ libtasn1: Out-of-bound access in ETYPE_OK │
  90. │ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2021-46848 │
  91. ├─────────────────┼────────────────┼──────────┼───────────────────┼─────────────────────────┼──────────────────────────────────────────────────────────────┤
  92. │ libtirpc-common │ CVE-2021-46828 │ HIGH │ 1.3.1-1 │ 1.3.1-1+deb11u1 │ libtirpc: DoS vulnerability with lots of connections │
  93. │ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2021-46828 │
  94. ├─────────────────┤ │ │ │ │ │
  95. │ libtirpc3 │ │ │ │ │ │
  96. │ │ │ │ │ │ │
  97. ├─────────────────┼────────────────┤ ├───────────────────┼─────────────────────────┼──────────────────────────────────────────────────────────────┤
  98. │ perl-base │ CVE-2020-16156 │ │ 5.32.1-4+deb11u1 │ │ perl-CPAN: Bypass of verification of signatures in CHECKSUMS │
  99. │ │ │ │ │ │ files │
  100. │ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2020-16156 │
  101. ├─────────────────┼────────────────┼──────────┼───────────────────┼─────────────────────────┼──────────────────────────────────────────────────────────────┤
  102. │ zlib1g │ CVE-2022-37434 │ CRITICAL │ 1:1.2.11.dfsg-2 │ 1:1.2.11.dfsg-2+deb11u2 │ zlib: heap-based buffer over-read and overflow in inflate() │
  103. │ │ │ │ │ │ in inflate.c via a... │
  104. │ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2022-37434 │
  105. │ ├────────────────┼──────────┤ ├─────────────────────────┼──────────────────────────────────────────────────────────────┤
  106. │ │ CVE-2018-25032 │ HIGH │ │ 1:1.2.11.dfsg-2+deb11u1 │ zlib: A flaw found in zlib when compressing (not │
  107. │ │ │ │ │ │ decompressing) certain inputs... │
  108. │ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2018-25032 │
  109. └─────────────────┴────────────────┴──────────┴───────────────────┴─────────────────────────┴──────────────────────────────────────────────────────────────┘
  110. registry.aliyuncs.com/google_containers/kube-scheduler:v1.23.15 (debian 11.4)
  111. =============================================================================
  112. Total: 0 (HIGH: 0, CRITICAL: 0)

可以看到,kubernetes集群的核心组件用的镜像还是比较好的,漏洞基本没有,但flannel,etcd这些组件就比较多了。因此,kubernetes部署的时候还是推荐使用二进制部署etcd集群以及二进制部署flannel这些网络组件

单独检测一下kube-apiserver:

  1. [root@k8s-master ~]# trivy image --skip-db-update registry.aliyuncs.com/google_containers/kube-apiserver:v1.23.15
  2. 2023-01-06T06:08:45.348+0800 INFO Vulnerability scanning is enabled
  3. 2023-01-06T06:08:45.348+0800 INFO Secret scanning is enabled
  4. 2023-01-06T06:08:45.348+0800 INFO If your scanning is slow, please try '--security-checks vuln' to disable secret scanning
  5. 2023-01-06T06:08:45.348+0800 INFO Please see also https://aquasecurity.github.io/trivy/v0.34/docs/secret/scanning/#recommendation for faster secret detection
  6. 2023-01-06T06:08:45.355+0800 INFO Detected OS: debian
  7. 2023-01-06T06:08:45.356+0800 INFO Detecting Debian vulnerabilities...
  8. 2023-01-06T06:08:45.356+0800 INFO Number of language-specific files: 0
  9. registry.aliyuncs.com/google_containers/kube-apiserver:v1.23.15 (debian 11.4)
  10. Total: 0 (UNKNOWN: 0, LOW: 0, MEDIUM: 0, HIGH: 0, CRITICAL: 0)

OK,这个kube-apiserver是一个比较完美的目前还没有发现漏洞的镜像

单独检测一下kube-controller-manager,这个镜像同样表现完美:

  1. [root@k8s-master ~]# trivy image --skip-db-update registry.aliyuncs.com/google_containers/kube-controller-manager:v1.23.15
  2. 2023-01-06T06:10:10.749+0800 INFO Vulnerability scanning is enabled
  3. 2023-01-06T06:10:10.749+0800 INFO Secret scanning is enabled
  4. 2023-01-06T06:10:10.749+0800 INFO If your scanning is slow, please try '--security-checks vuln' to disable secret scanning
  5. 2023-01-06T06:10:10.749+0800 INFO Please see also https://aquasecurity.github.io/trivy/v0.34/docs/secret/scanning/#recommendation for faster secret detection
  6. 2023-01-06T06:10:10.755+0800 INFO Detected OS: debian
  7. 2023-01-06T06:10:10.755+0800 INFO Detecting Debian vulnerabilities...
  8. 2023-01-06T06:10:10.756+0800 INFO Number of language-specific files: 0
  9. registry.aliyuncs.com/google_containers/kube-controller-manager:v1.23.15 (debian 11.4)
  10. Total: 0 (UNKNOWN: 0, LOW: 0, MEDIUM: 0, HIGH: 0, CRITICAL: 0)

单独检测一下kube-proxy:

trivy image --skip-db-update registry.aliyuncs.com/google_containers/kube-proxy:v1.23.15

这个输出就比较多了,漏洞很多,14个高危漏洞,15个致命漏洞:

  1. 2023-01-06T06:11:19.285+0800 INFO Vulnerability scanning is enabled
  2. 2023-01-06T06:11:19.285+0800 INFO Secret scanning is enabled
  3. 2023-01-06T06:11:19.285+0800 INFO If your scanning is slow, please try '--security-checks vuln' to disable secret scanning
  4. 2023-01-06T06:11:19.285+0800 INFO Please see also https://aquasecurity.github.io/trivy/v0.34/docs/secret/scanning/#recommendation for faster secret detection
  5. 2023-01-06T06:11:19.292+0800 INFO Detected OS: debian
  6. 2023-01-06T06:11:19.292+0800 INFO Detecting Debian vulnerabilities...
  7. 2023-01-06T06:11:19.307+0800 INFO Number of language-specific files: 0
  8. registry.aliyuncs.com/google_containers/kube-proxy:v1.23.15 (debian 11.0)
  9. Total: 107 (UNKNOWN: 0, LOW: 58, MEDIUM: 20, HIGH: 14, CRITICAL: 15)
  10. ┌──────────────────┬──────────────────┬──────────┬───────────────────┬─────────────────────────┬──────────────────────────────────────────────────────────────┐
  11. │ Library │ Vulnerability │ Severity │ Installed Version │ Fixed Version │ Title │
  12. ├──────────────────┼──────────────────┼──────────┼───────────────────┼─────────────────────────┼──────────────────────────────────────────────────────────────┤
  13. │ apt │ CVE-2011-3374 │ LOW │ 2.2.4 │ │ It was found that apt-key in apt, all versions, do not │
  14. │ │ │ │ │ │ correctly... │
  15. │ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2011-3374 │
  16. ├──────────────────┼──────────────────┼──────────┼───────────────────┼─────────────────────────┼──────────────────────────────────────────────────────────────┤
  17. │ bsdutils │ CVE-2021-3995 │ MEDIUM │ 2.36.1-8 │ 2.36.1-8+deb11u1 │ util-linux: Unauthorized unmount of FUSE filesystems │
  18. │ │ │ │ │ │ belonging to users with similar uid... │
  19. │ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2021-3995 │
  20. │ ├──────────────────┤ │ │ ├──────────────────────────────────────────────────────────────┤
  21. │ │ CVE-2021-3996 │ │ │ │ util-linux: Unauthorized unmount of filesystems in libmount │
  22. │ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2021-3996 │
  23. │ ├──────────────────┼──────────┤ ├─────────────────────────┼──────────────────────────────────────────────────────────────┤
  24. │ │ CVE-2022-0563 │ LOW │ │ │ util-linux: partial disclosure of arbitrary files in chfn │
  25. │ │ │ │ │ │ and chsh when compiled... │
  26. │ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2022-0563 │
  27. ├──────────────────┼──────────────────┤ ├───────────────────┼─────────────────────────┼──────────────────────────────────────────────────────────────┤
  28. │ coreutils │ CVE-2016-2781 │ │ 8.32-4 │ │ coreutils: Non-privileged session can escape to the parent │
  29. │ │ │ │ │ │ session in chroot
  30. │ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2016-2781 │
  31. │ ├──────────────────┤ │ ├─────────────────────────┼──────────────────────────────────────────────────────────────┤
  32. │ │ CVE-2017-18018 │ │ │ │ coreutils: race condition vulnerability in chown and chgrp
  33. │ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2017-18018 │
  34. ├──────────────────┼──────────────────┼──────────┼───────────────────┼─────────────────────────┼──────────────────────────────────────────────────────────────┤
  35. │ dpkg │ CVE-2022-1664 │ CRITICAL │ 1.20.9 │ 1.20.10 │ Dpkg::Source::Archive in dpkg, the Debian package management │
  36. │ │ │ │ │ │ system, b ... │
  37. │ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2022-1664 │
  38. ├──────────────────┼──────────────────┼──────────┼───────────────────┼─────────────────────────┼──────────────────────────────────────────────────────────────┤
  39. │ gpgv │ CVE-2022-34903 │ MEDIUM │ 2.2.27-2 │ 2.2.27-2+deb11u2 │ gpg: Signature spoofing via status line injection │
  40. │ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2022-34903 │
  41. ├──────────────────┼──────────────────┼──────────┼───────────────────┼─────────────────────────┼──────────────────────────────────────────────────────────────┤
  42. │ gzip │ CVE-2022-1271 │ HIGH │ 1.10-4 │ 1.10-4+deb11u1 │ gzip: arbitrary-file-write vulnerability │
  43. │ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2022-1271 │
  44. ├──────────────────┼──────────────────┼──────────┼───────────────────┼─────────────────────────┼──────────────────────────────────────────────────────────────┤
  45. │ iptables │ CVE-2012-2663 │ LOW │ 1.8.7-1 │ │ iptables: --syn flag bypass │
  46. │ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2012-2663 │
  47. ├──────────────────┼──────────────────┤ ├───────────────────┼─────────────────────────┼──────────────────────────────────────────────────────────────┤
  48. │ libapt-pkg6.0 │ CVE-2011-3374 │ │ 2.2.4 │ │ It was found that apt-key in apt, all versions, do not │
  49. │ │ │ │ │ │ correctly... │
  50. │ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2011-3374 │
  51. ├──────────────────┼──────────────────┼──────────┼───────────────────┼─────────────────────────┼──────────────────────────────────────────────────────────────┤
  52. 。。。。。。。。。。。。。。。。。。。。。。。。。后面的省略了

单独检测一下kube-scheduler,这个镜像同样表现接近完美:

  1. [root@k8s-master ~]# trivy image --skip-db-update registry.aliyuncs.com/google_containers/kube-scheduler:v1.23.15
  2. 2023-01-06T06:15:00.739+0800 INFO Vulnerability scanning is enabled
  3. 2023-01-06T06:15:00.739+0800 INFO Secret scanning is enabled
  4. 2023-01-06T06:15:00.739+0800 INFO If your scanning is slow, please try '--security-checks vuln' to disable secret scanning
  5. 2023-01-06T06:15:00.739+0800 INFO Please see also https://aquasecurity.github.io/trivy/v0.34/docs/secret/scanning/#recommendation for faster secret detection
  6. 2023-01-06T06:15:00.744+0800 INFO Detected OS: debian
  7. 2023-01-06T06:15:00.744+0800 INFO Detecting Debian vulnerabilities...
  8. 2023-01-06T06:15:00.744+0800 INFO Number of language-specific files: 0
  9. registry.aliyuncs.com/google_containers/kube-scheduler:v1.23.15 (debian 11.4)
  10. Total: 0 (UNKNOWN: 0, LOW: 0, MEDIUM: 0, HIGH: 0, CRITICAL: 0)

单独检测pause,这个镜像同样表现接近完美:

  1. [root@k8s-master ~]# trivy image --skip-db-update registry.aliyuncs.com/google_containers/pause:3.6
  2. 2023-01-06T06:16:36.227+0800 INFO Vulnerability scanning is enabled
  3. 2023-01-06T06:16:36.227+0800 INFO Secret scanning is enabled
  4. 2023-01-06T06:16:36.227+0800 INFO If your scanning is slow, please try '--security-checks vuln' to disable secret scanning
  5. 2023-01-06T06:16:36.227+0800 INFO Please see also https://aquasecurity.github.io/trivy/v0.34/docs/secret/scanning/#recommendation for faster secret detection
  6. 2023-01-06T06:16:36.232+0800 INFO Number of language-specific files: 0

单独检测coredns,这个镜像表现接近完美,只有一页的漏洞报告:

  1. [root@k8s-master ~]# trivy image --skip-db-update registry.aliyuncs.com/google_containers/coredns:v1.8.6
  2. 2023-01-06T06:17:43.783+0800 INFO Vulnerability scanning is enabled
  3. 2023-01-06T06:17:43.783+0800 INFO Secret scanning is enabled
  4. 2023-01-06T06:17:43.783+0800 INFO If your scanning is slow, please try '--security-checks vuln' to disable secret scanning
  5. 2023-01-06T06:17:43.783+0800 INFO Please see also https://aquasecurity.github.io/trivy/v0.34/docs/secret/scanning/#recommendation for faster secret detection
  6. 2023-01-06T06:17:43.790+0800 INFO Number of language-specific files: 1
  7. 2023-01-06T06:17:43.790+0800 INFO Detecting gobinary vulnerabilities...
  8. coredns (gobinary)
  9. Total: 11 (UNKNOWN: 0, LOW: 1, MEDIUM: 3, HIGH: 7, CRITICAL: 0)
  10. ┌─────────────────────────────────────┬────────────────┬──────────┬────────────────────────────────────┬───────────────────────────────────┬──────────────────────────────────────────────────────────────┐
  11. │ Library │ Vulnerability │ Severity │ Installed Version │ Fixed Version │ Title │
  12. ├─────────────────────────────────────┼────────────────┼──────────┼────────────────────────────────────┼───────────────────────────────────┼──────────────────────────────────────────────────────────────┤
  13. │ github.com/aws/aws-sdk-go │ CVE-2020-8911 │ MEDIUM │ v1.40.54 │ │ aws/aws-sdk-go: CBC padding oracle issue in AWS S3 Crypto │
  14. │ │ │ │ │ │ SDK for golang... │
  15. │ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2020-8911 │
  16. │ ├────────────────┼──────────┤ ├───────────────────────────────────┼──────────────────────────────────────────────────────────────┤
  17. │ │ CVE-2020-8912 │ LOW │ │ │ aws-sdk-go: In-band key negotiation issue in AWS S3 Crypto │
  18. │ │ │ │ │ │ SDK for golang... │
  19. │ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2020-8912 │
  20. ├─────────────────────────────────────┼────────────────┼──────────┼────────────────────────────────────┼───────────────────────────────────┼──────────────────────────────────────────────────────────────┤
  21. │ github.com/prometheus/client_golang │ CVE-2022-21698 │ HIGH │ v1.11.0 │ 1.11.1 │ prometheus/client_golang: Denial of service using │
  22. │ │ │ │ │ │ InstrumentHandlerCounter │
  23. │ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2022-21698 │
  24. ├─────────────────────────────────────┼────────────────┤ ├────────────────────────────────────┼───────────────────────────────────┼──────────────────────────────────────────────────────────────┤
  25. │ golang.org/x/crypto │ CVE-2021-43565 │ │ v0.0.0-20210513164829-c07d793c2f9a │ 0.0.0-20211202192323-5770296d904e │ golang.org/x/crypto: empty plaintext packet causes panic │
  26. │ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2021-43565 │
  27. │ ├────────────────┤ │ ├───────────────────────────────────┼──────────────────────────────────────────────────────────────┤
  28. │ │ CVE-2022-27191 │ │ │ 0.0.0-20220314234659-1baeb1ce4c0b │ golang: crash in a golang.org/x/crypto/ssh server │
  29. │ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2022-27191 │
  30. ├─────────────────────────────────────┼────────────────┤ ├────────────────────────────────────┼───────────────────────────────────┼──────────────────────────────────────────────────────────────┤
  31. │ golang.org/x/net │ CVE-2021-44716 │ │ v0.0.0-20210614182718-04defd469f4e │ 0.0.0-20211209124913-491a49abca63 │ golang: net/http: limit growth of header canonicalization │
  32. │ │ │ │ │ │ cache │
  33. │ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2021-44716 │
  34. │ ├────────────────┤ │ ├───────────────────────────────────┼──────────────────────────────────────────────────────────────┤
  35. │ │ CVE-2022-27664 │ │ │ 0.0.0-20220906165146-f3363e06e74c │ golang: net/http: handle server errors after sending GOAWAY │
  36. │ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2022-27664 │
  37. │ ├────────────────┼──────────┤ ├───────────────────────────────────┼──────────────────────────────────────────────────────────────┤
  38. │ │ CVE-2022-41717 │ MEDIUM │ │ 0.4.0 │ An attacker can cause excessive memory growth in a Go server │
  39. │ │ │ │ │ │ accepting... │
  40. │ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2022-41717 │
  41. ├─────────────────────────────────────┼────────────────┤ ├────────────────────────────────────┼───────────────────────────────────┼──────────────────────────────────────────────────────────────┤
  42. │ golang.org/x/sys │ CVE-2022-29526 │ │ v0.0.0-20210917161153-d61c044b1678 │ 0.0.0-20220412211240-33da011f77ad │ golang: syscall: faccessat checks wrong group │
  43. │ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2022-29526 │
  44. ├─────────────────────────────────────┼────────────────┼──────────┼────────────────────────────────────┼───────────────────────────────────┼──────────────────────────────────────────────────────────────┤
  45. │ golang.org/x/text │ CVE-2021-38561 │ HIGH │ v0.3.6 │ 0.3.7 │ golang: out-of-bounds read in golang.org/x/text/language │
  46. │ │ │ │ │ │ leads to DoS │
  47. │ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2021-38561 │
  48. │ ├────────────────┤ │ ├───────────────────────────────────┼──────────────────────────────────────────────────────────────┤
  49. │ │ CVE-2022-32149 │ │ │ 0.3.8 │ golang: golang.org/x/text/language: ParseAcceptLanguage │
  50. │ │ │ │ │ │ takes a long time to parse complex tags │
  51. │ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2022-32149 │
  52. └─────────────────────────────────────┴────────────────┴──────────┴────────────────────────────────────┴───────────────────────────────────┴──────────────────────────────────────────────────────────────┘

flannel的表现是比较差劲的,漏洞比较多,47个高危漏洞,5个致命漏洞:

  1. [root@k8s-master ~]# trivy image --skip-db-update quay.io/coreos/flannel:v0.13.0
  2. 2023-01-06T06:19:46.810+0800 INFO Vulnerability scanning is enabled
  3. 2023-01-06T06:19:46.810+0800 INFO Secret scanning is enabled
  4. 2023-01-06T06:19:46.810+0800 INFO If your scanning is slow, please try '--security-checks vuln' to disable secret scanning
  5. 2023-01-06T06:19:46.810+0800 INFO Please see also https://aquasecurity.github.io/trivy/v0.34/docs/secret/scanning/#recommendation for faster secret detection
  6. 2023-01-06T06:19:46.818+0800 INFO Detected OS: alpine
  7. 2023-01-06T06:19:46.819+0800 INFO Detecting Alpine vulnerabilities...
  8. 2023-01-06T06:19:46.821+0800 INFO Number of language-specific files: 1
  9. 2023-01-06T06:19:46.821+0800 INFO Detecting gobinary vulnerabilities...
  10. 2023-01-06T06:19:46.833+0800 WARN This OS version is no longer supported by the distribution: alpine 3.12.0
  11. 2023-01-06T06:19:46.833+0800 WARN The vulnerability detection may be insufficient because security updates are not provided
  12. quay.io/coreos/flannel:v0.13.0 (alpine 3.12.0)
  13. Total: 77 (UNKNOWN: 0, LOW: 6, MEDIUM: 19, HIGH: 47, CRITICAL: 5)
  14. 。。。。。。。。。。。。。。。。省略

由此,我们可以得出一个结论:

kubernetes集群的部署使用kubeadm是没什么问题的,但etcd,flannel。kube-proxy这些组件最好还是二进制部署。

附:

查看版本号命令可以看到,比较新的trivy是使用v2的数据库哦,并且trivy非常注意更新数据库,因此,第一次更新完数据库后,在使用的时候为了避免升级麻烦,最好还是命令加 --skip-db-update 这个参数

  1. [root@k8s-master db]# trivy version
  2. Version: 0.34.0
  3. Vulnerability DB:
  4. Version: 2
  5. UpdatedAt: 2023-01-05 12:09:26.44058254 +0000 UTC
  6. NextUpdate: 2023-01-05 18:09:26.44058214 +0000 UTC
  7. DownloadedAt: 2023-01-05 20:56:55.46729581 +0000 UTC

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/506693
推荐阅读
相关标签
  

闽ICP备14008679号