ARTICLE DETAIL

资讯详情

深耕郑州网站建设与运营推广的一线实战洞察。

kube-prometheus 安全审计指南:kubescape 扫描机制与默认安全例外详解

kube-prometheus 安全审计指南:kubescape 扫描机制与默认安全例外详解 云原生可观测性指标监控监控大盘告警【免费下载链接】kube-prometheusUse Prometheus to monitor Kubernetes and applications running on Kubernetes项目地址https://gitcode.com/gh_mirrors/ku/kube-prometheus点击查看免费下载kube-prometheus 通过 CI 中集成的 kubescape 安全扫描NSA 框架对生成的全部 Kubernetes manifests 进行持续安全审计本文基于 docs/security.md 展开详细解读扫描机制、本地执行方式以及 node-exporter、prometheus-adapter、blackbox-exporter、kube-state-metrics、prometheus-operator 五个组件因功能需要而不得不做出的安全例外帮助你理解默认安全最佳实践与功能必需例外之间的取舍逻辑并能自行运行扫描、解读结果。kube-prometheus 的安全审计机制kube-prometheus 仓库中通过 jsonnet 生成的全部 Kubernetes manifests位于 manifests/ 目录都会在 CI 中接受一次安全审计审计工具为 kubescapeARMO 开源的 Kubernetes 安全扫描工具扫描框架为NSA美国国家安全局 Kubernetes 加固指南框架。这意味着每次代码变更提交后CI 都会重新生成 manifests 并执行安全扫描一旦风险评分超过阈值构建即失败从源头上阻止存在明显安全隐患的配置被合入仓库。该能力的历史引入可见于 CHANGELOG.md 中 Scan generated manifests with kubescape in CI 这一条目。本地运行安全扫描make kubescape除了 CI 自动扫描你可以在本地对当前仓库生成的 manifests 执行同样的安全审计。对应 Makefile 目标定义如下见 Makefile.PHONY: kubescape kubescape: $(KUBESCAPE_BIN) ## Runs a security analysis on generated manifests - failing if risk score is above threshold percentage t $(KUBESCAPE_BIN) scan framework nsa --compliance-threshold $(KUBESCAPE_THRESHOLD) -v --exceptions kubescape-exceptions.json manifests/执行方式make kubescape该命令的构成与含义如下参数值说明scan framework nsa—使用 NSAKubernetes 加固指南框架进行扫描--compliance-threshold1即$(KUBESCAPE_THRESHOLD)见 Makefile合规性阈值百分比扫描结果风险评分高于该值则命令失败-v—输出详细扫描信息--exceptionskubescape-exceptions.json指定例外规则文件用于豁免已知且被接受的检查项扫描目标manifests/对仓库生成的 manifests 目录整体扫描如果本机尚未安装 kubescapeMakefile 中的$(KUBESCAPE_BIN)依赖会自动触发安装脚本见 Makefile安装位置为~/.kubescape/bin/kubescape。例外清单哪些组件突破了默认安全基线仓库目标是默认安全但受限于项目本质监控组件天然需要更深的系统与集群访问权限以下组件必须做出例外。这些例外以显式方式声明在 kubescape-exceptions.json 中被扫描命令通过--exceptions参数加载从而避免误报导致 CI 失败。node-exporterHost 级访问例外node-exporter 作为节点指标采集器是例外最多的组件对应 manifests/nodeExporter-daemonset.yamlHost Port设置为主机端口。文档指出 Kubernetes 本身在启用 Host Network 时就会默认设置 Host Port对应 Kubernetes 源码pkg/apis/core/v1/defaults.go中 HostNetwork 为 true 时自动设置 HostPort 的默认逻辑既然无法避免kube-prometheus 便将其配置为偏好的端口9100Host PID truenode-exporter 需要直接访问宿主机 PID 命名空间以采集进程统计信息Host Network truenode-exporter 需要直接访问宿主机网络命名空间以采集网络统计信息automountServiceAccountToken truePod 层因为 kube-rbac-proxy sidecar 需要连接 Kubernetes API server 完成鉴权。对应生成的 DaemonSet 清单中可见如下字段manifests/nodeExporter-daemonset.yaml、manifests/nodeExporter-daemonset.yamlspec: template: spec: automountServiceAccountToken: true hostNetwork: true hostPID: true # kube-rbac-proxy sidecar 暴露 hostPort: 9100prometheus-adapterAPI server 访问例外prometheus-adapter 作为 metrics API 适配器对应 manifests/prometheusAdapter-deployment.yaml在Pod 层设置automountServiceAccountToken true原因同样是应用本身需要连接 Kubernetes API server它以 APIService 形式注册并提供 custom metrics 接口见 prometheusAdapter-apiService.yaml。blackbox-exporterAPI server 访问例外blackbox-exporter对应 manifests/blackboxExporter-deployment.yaml在Pod 层设置automountServiceAccountToken true因为其 kube-rbac-proxy sidecar 需要连接 Kubernetes API server 完成请求鉴权。kube-state-metricsAPI server 访问例外kube-state-metrics对应 manifests/kubeStateMetrics-deployment.yaml在Pod 层设置automountServiceAccountToken true因为它的两个 kube-rbac-proxy sidecarkube-rbac-proxy-main与kube-rbac-proxy-self需要连接 Kubernetes API server。prometheus-operatorAPI server 访问例外prometheus-operator对应 manifests/prometheusOperator-deployment.yaml在Pod 层设置automountServiceAccountToken true因为其 kube-rbac-proxy sidecar 需要连接 Kubernetes API server。两层 automountServiceAccountToken 设计ServiceAccount 与 Pod 的差异值得注意的细节是上述组件虽然都在Pod 层显式开启了automountServiceAccountToken但它们的ServiceAccount 对象却普遍声明为automountServiceAccountToken: false。例如prometheusOperator-serviceAccount.yaml、prometheusAdapter-serviceAccount.yaml、blackboxExporter-serviceAccount.yaml、kubeStateMetrics-serviceAccount.yaml、nodeExporter-serviceAccount.yaml 均为false而 prometheus-serviceAccount.yaml 为truePrometheus 自身需要访问 Kubernetes API 发现 targets。这种ServiceAccount 层关闭、Pod 层开启的组合是 kube-prometheus 对 Kubernetes 两层覆盖机制的精细利用ServiceAccount 上的automountServiceAccountToken是默认值而 Pod 上的同名字段优先级更高、可以覆盖前者。从 jsonnet 源码可进一步印证这一设计——jsonnet/kube-prometheus/components/blackbox-exporter.libsonnet 与 jsonnet/kube-prometheus/components/prometheus-adapter.libsonnet 中 ServiceAccount 声明automountServiceAccountToken: false而 jsonnet/kube-prometheus/components/node-exporter.libsonnet、jsonnet/kube-prometheus/components/prometheus-operator.libsonnet 中 Pod 层则显式置为true。对照之下grafana 由于既不需要访问 Kubernetes API server也没有 kube-rbac-proxy sidecar在 grafana-deployment.yaml 与 grafana.libsonnet 中同时关闭了 token 自动挂载属于默认安全的典型代表。例外规则的声明方式kubescape-exceptions.json所有被接受的例外都集中声明在 kubescape-exceptions.json 中共包含两类postureExceptionPolicy姿态异常策略动作均为alertOnly即仅告警不阻断exclude-automountServiceAccountToken-checks豁免 6 个资源的 Automatic mapping of service account 控制项资源包括 DaemonSetnode-exporter与 Deploymentblackbox-exporter、kube-state-metrics、prometheus-adapter、prometheus-operator以及 ServiceAccountprometheus-k8sexclude-node-exporter-host-access-checks仅针对 DaemonSetnode-exporter豁免 Container hostPort、Host PID/IPC privileges、HostNetwork access 三个控制项。如果你在 fork 或自定义部署中调整了这些组件的清单可参照该文件的格式增删例外条目再重新运行make kubescape验证。如何验证与扩展安全基线验证当前状态在仓库根目录执行make kubescape观察输出中每个控制项的状态与最终合规性评分阈值 1%见 Makefile理解例外必要性对照本文第二节确认每个例外都与Host 级指标采集或kube-rbac-proxy / 应用连接 API server直接相关属于功能性必需而非配置疏漏保持安全增量在生成清单中加入自定义组件时应优先遵循仓库的既有安全实践——allowPrivilegeEscalation: false、capabilities全部 drop、readOnlyRootFilesystem: true、runAsNonRoot: true、seccompProfile: RuntimeDefault等字段在 manifests/ 各清单中随处可见可作为新的安全默认基线跟踪合规性kube-prometheus 还提供了 security.md 之外的辅助材料如 kubescape-exceptions.json 的维护规则与 CONTRIBUTING.md 中的贡献约定新增例外时必须同时更新该文件以保证 CI 通过。小结kube-prometheus 的安全模型可以概括为默认加固、显式例外、集中豁免、CI 兜底绝大多数组件遵循 NSA 框架的加固建议少数监控组件因功能必须获得 Host 命名空间或 API server 访问权则通过 Pod 层automountServiceAccountToken、hostPID、hostNetwork等字段显式突破并在 kubescape-exceptions.json 中集中登记最终由 CI 中的 kubescape 扫描本地可用make kubescape复现持续把关确保安全状态可审计、可追踪。赞分享云原生可观测性指标监控监控大盘告警【免费下载链接】kube-prometheusUse Prometheus to monitor Kubernetes and applications running on Kubernetes项目地址https://gitcode.com/gh_mirrors/ku/kube-prometheus点击查看免费下载相关推荐Kubescape 入门指南Kubernetes 安全扫描工具详解Kubescape 入门指南Kubernetes 安全扫描工具详解 工具概述 Kubescape 是一款开源的 Kubernetes 安全合规扫描工具能够帮网络安全云原生应用安全运维LunaTranslator视觉小说翻译的终极解决方案5分钟实现游戏实时翻译LunaTranslator视觉小说翻译的终极解决方案5分钟实现游戏实时翻译 你是否曾经因为语言障碍而错过精彩的视觉小说游戏面对日文、英文或其他外语的游戏桌面应用OCR人工智能kinit安全审计安全扫描与加固kinit安全审计安全扫描与加固 前言 在当今数字化转型时代企业级应用系统的安全性已成为不可忽视的重要议题。kinit作为一套基于FastAPI Vue后端前端任务调度认证鉴权移动开发上一篇Grbl_ESP32 项目使用教程下一篇PostgreSQL从入门到精通digoal博客学习路径指南创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表