在之前的文章中我们讨论了如何在jenkins
的CI/CD
流程的Pipeline
中去集成Trivy
以及如何给Trivy
编写自定义策略来工作,那我们今天就来尝试下用Trivy Operator
给Kubernetes
集群来做一次安全扫描,并输出相应的Grafana
图表
之前的2个文章
Trivy-Operator 利用 trivy 安全工具,将其输出结果整合到 Kubernetes CRDs(自定义资源定义)中,并通过 Kubernetes API 使安全报告可访问。这样,用户可以以 Kubernetes 原生的方式查找和查看与不同资源相关的风险。
Trivy operator 根据 Kubernetes 集群的工作负载和其他变化自动更新安全报告,生成以下报告:
漏洞扫描
:针对 Kubernetes 工作负载的自动漏洞扫描。
配置审计扫描
:针对具有预定义规则或自定义 Open Policy Agent(OPA)策略的 Kubernetes 资源的自动配置审计。
暴露的 Secret 扫描
:自动扫描可以查找并详细说明集群中暴露的 Secrets 的位置。
RBAC 扫描
:基于角色的访问控制扫描提供有关安装的不同资源的访问权限的详细信息。
K8s 核心组件基础设施评估扫描
: Kubernetes 基础设施核心组件(etcd、apiserver、scheduler、controller-manager 等)的设置和配置。
合规报告
:
trivy-operator-values.yaml
# targetNamespace defines where you want trivy-operator to operate. By
# default, it's a blank string to select all namespaces, but you can specify
# another namespace, or a comma separated list of namespaces.
targetNamespaces: ""
# excludeNamespaces is a comma separated list of namespaces (or glob patterns)
# to be excluded from scanning. Only applicable in the all namespaces install
# mode, i.e. when the targetNamespaces values is a blank string.
excludeNamespaces: ""
# targetWorkloads is a comma seperated list of Kubernetes workload resources
# to be included in the vulnerability and config-audit scans
# if left blank, all workload resources will be scanned
targetWorkloads: "pod,replicaset,replicationcontroller,statefulset,daemonset,cronjob,job"
image:
repository: "artifactory.thomasroot.local/aquasecurity/trivy-operator"
trivy:
# repository of the Trivy image
repository: "artifactory.thomasroot.local/aquasecurity/aquasec/trivy"
# Registries without SSL. There can be multiple registries with different keys.
nonSslRegistries: {
artifactory: "artifactory.thomasroot.local"
}
# The registry to which insecure connections are allowed. There can be multiple registries with different keys.
insecureRegistries: {
artifactory: "artifactory.thomasroot.local"
}
# serverCustomHeaders is a comma separated list of custom HTTP headers sent by
# Trivy client to Trivy server. Only applicable in ClientServer mode.
#
# serverCustomHeaders: "foo=bar"
dbRepository: "artifactory.thomasroot.local/aquasecurity/trivy-db"
# The Flag to enable insecure connection for downloading trivy-db via proxy (air-gaped env)
# Customized because local artifactory repo is "insecure"
dbRepositoryInsecure: "true"
serviceMonitor:
# enabled determines whether a serviceMonitor should be deployed
enabled: true
namespace: monitoring
labels:
release: "prom" #use your own labels
trivy:
ignoreUnfixed: true
operator:
# scanJobTimeout the length of time to wait before giving up on a scan job
scanJobTimeout: 5m
以上values文件
的包含3块内容
Environments
部分配置,如果您使用的是自定义镜像注册表,如 Artifactory 或 Harbor,则有必要更新容器镜像和漏洞数据库的路径。
请务必注意,在激活此设置之前必须已经安装了 Prometheus
Prometheus serviceMonitor
配置是给Prometheus
做自动发现的,
以及Prometheus
通过serviceMonitorSelector
的标签选择器来过滤监控项。
Restricting and excluding resources
部分配置,当您不想扫描某些名称空间或工作负载时很有用。
Timeout
部分配置,某些情况下,有必要增加scanJobTimeout
默认值 5m
helm repo add aqua https://aquasecurity.github.io/helm-charts/
helm repo update
helm upgrade -i trivy-operator aqua/trivy-operator \
--namespace trivy-system \
--create-namespace \
--version 0.12.0 \
--set="trivy.resources.requests.memory=1G" \
--set="trivy.resources.limits.memory=1G" \
--values trivy-operator-values.yaml
安装后,Trivy Operator 会扫描集群中的所有图像,并将结果存储在各个pod命名空间中的 k8s的CRD资源中。
root@node1:~/trivy-operator# kubectl get crd | grep aqua
clustercompliancereports.aquasecurity.github.io 2023-03-03T08:30:39Z
clusterconfigauditreports.aquasecurity.github.io 2023-03-03T08:30:39Z
clusterinfraassessmentreports.aquasecurity.github.io 2023-03-08T05:38:27Z
clusterrbacassessmentreports.aquasecurity.github.io 2023-03-03T08:30:40Z
configauditreports.aquasecurity.github.io 2023-03-03T08:30:40Z
exposedsecretreports.aquasecurity.github.io 2023-03-03T08:30:40Z
infraassessmentreports.aquasecurity.github.io 2023-03-03T08:30:40Z
rbacassessmentreports.aquasecurity.github.io 2023-03-03T08:30:40Z
vulnerabilityreports.aquasecurity.github.io 2023-03-03T08:30:40Z
clustercompliancereports
:根据CIS 基准和NSA Kubernetes 强化指南创建报告。
clusterrbacassessmentreports& rbacassessmentreports
:扫描提供有关已安装的不同资源的访问权限的详细信息,并突出显示与ClusterRoles或权限过高的任何问题Roles。
clusterconfigauditreports
:使用预定义规则或自定义 Open Policy Agent (OPA) 策略对 Kubernetes 资源进行自动配置审计。
exposedsecretreports
:自动扫描,定位并详细说明集群中暴露的 Secret 的位置。
infraassessmentreports
:扫描 Kubernetes 核心组件(etcd、apiserver、scheduler、controller-manager 等)设置和配置。
vulnerabilityreports
:自动扫描容器镜像中的漏洞。
Aqua Trivy
仪表板的 Grafana ID: 17813
Grafana Dashboard for Trivy Operator
https://aquasecurity.github.io/trivy-operator/v0.12.0/tutorials/grafana-dashboard/ https://medium.com/datev-techblog/trivy-operator-improve-container-runtime-security-2a1f647dcab https://community.cloudogu.com/t/continuously-scan-your-kubernetes-cluster-for-security-issues-using-trivy-operator/962