【云原生-K8s】Kubernetes安全组件CIS基准kube-beach安装及使用

基础介绍

  • 为了保证集群以及容器应用的安全,Kubernetes 提供了多种安全机制,限制容器的行为,减少容器和集群的攻击面,保证整个系统的安全性。
  • 互联网安全中心(CIS,Center for Internet Security),是一个非盈利组织,致力为互联网提供免费的安全防御解决方案
  • 官网https://www.cisecurity.org/
  • k8s安全基准https://www.cisecurity.org/benchmark/kubernetes

kube-beach介绍

kube-beach 下载

百度网盘下载

链接:https://pan.baidu.com/s/17AGxkwTDUkiDYSSZpPu45A?pwd=vqew
提取码:vqew
–来自百度网盘超级会员V7的分享

wget下载
wget https://github.com/aquasecurity/kube-bench/releases/download/v0.6.19/kube-bench_0.6.19_linux_amd64.tar.gz

kube-beach安装

  • 解压
tar -zxf kube-bench_0.6.19_linux_amd64.tar.gz
  • 创建默认配置路径
mkdir -p /etc/kube-bench
  • 复制配置文件至默认目录
mv cfg /etc/kube-bench/cfg
  • 设置为系统命令
mv kube-bench /usr/bin/

kube-beach使用

基础参数

  • 使用kube-bench run进行测试,该指令有以下常用参数

  • –targets 指定要基础测试的目标,默认配置目标包括:master, controlplane, node, etcd, policies

  • –version:指定k8s版本,如果未指定会自动检测

  • –benchmark:手动指定CIS基准版本,不能与–version一起使用

  • 查看帮助信息

kube-bench --help

在这里插入图片描述

配置信息解读

  • 在该目录下 /etc/kube-bench/cfg
    在这里插入图片描述
  • 该版本默认使用 cis-1.7
  • 也支持其他 云厂商的验证基准 【ack-1.0 容器服务 Kubernetes 版 ACK】

示例

  • 检查master组件安全配置
kube-bench run --targets=master

在这里插入图片描述
在这里插入图片描述

修复建议

在这里插入图片描述

修复一个安全漏洞【1.2.18】

  • 安全漏洞
[FAIL] 1.2.18 Ensure that the --profiling argument is set to false (Automated)
  • 修复建议
1.2.18 Edit the API server pod specification file /etc/kubernetes/manifests/kube-apiserver.yaml
on the control plane node and set the below parameter.
--profiling=false
  • 编辑 kube-apiserver.yaml ,增加 --profiling=false
    在这里插入图片描述
  • 修改完后 kube-apiserver 静态pod进行重启
  • 已通过安全扫描
    在这里插入图片描述

结果说明

  • [PASS]:测试通过
  • [FAIL]:测试未通过,重点关注,在测试结果会给出修复建议
  • [WARN]:警告,可做了解
  • [INFO]:信息
  • 大家可以根据实际情况,推荐的修复方案进行实际的修复措施。

kube-beach跳过漏洞

  • kube-beach 所有扫描出来的漏洞不一定需要全部修复,如果需要跳过我们需要修改kube-beach的漏洞定义配置文件

漏洞定义

[FAIL] 1.4.1 Ensure that the --profiling argument is set to false (Automated)
  • 在 /etc/kube-bench/cfg/cis-1.23【具体k8s版本】 目录编辑 master.yaml
  • 找到 1.4.1 配置信息
- id: 1.4.1
        text: "Ensure that the --profiling argument is set to false (Automated)"
        audit: "/bin/ps -ef | grep $schedulerbin | grep -v grep"
        tests:
          test_items:
            - flag: "--profiling"
              compare:
                op: eq
                value: false
        remediation: |
          Edit the Scheduler pod specification file $schedulerconf file
          on the control plane node and set the below parameter.
          --profiling=false
        scored: true

漏洞定义yaml说明

  • id:编号
  • text:提示的文本
  • tests:测试项目
  • remediation:修复方案
  • scored:如果为true,kube-bench无法正常测试,则会生成FAIL,如果为false,无法正常测试,则会生成WARN。
  • type:如果为manual则会生成WARN,如果为skip,则会生成INFO

漏洞生成为INFO

在这里插入图片描述
在这里插入图片描述

  • 修改后的yaml
- id: 1.4.1
        text: "Ensure zhangzihao that the --profiling argument is set to false (Automated)"
        audit: "/bin/ps -ef | grep $schedulerbin | grep -v grep"
        tests:
          test_items:
            - flag: "--profiling"
              compare:
                op: eq
                value: false
        remediation: |
          Edit the Scheduler pod specification file $schedulerconf file
          on the control plane node and set the below parameter.
          --profiling=false
        scored: true
        type: "skip"

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
THE END
分享
二维码
< <上一篇
下一篇>>