小知识:Kubernetes 资源清单静态分析工具 – KubeLinter

%小知识:Kubernetes 资源清单静态分析工具 – KubeLinter-猿站网-插图

KubeLinter 是一种开源静态分析工具,用于识别 Kubernetes 对象中的错误配置。KubeLinter 提供了对 Kubernetes YAML 文件和 Helm Chart 的安全检查的能力,验证集群配置是否遵循最佳安全实践。通过内置检查,可以获得有关错误配置和违反 Kubernetes 策略的反馈。这提高了开发人员的工作效率,将安全即代码与 DevOps 和 DevSecOps 流程集成,同时确保为 Kubernetes 应用程序自动实施强化的安全策略。

KubeLinter 分析 YAML 文件和 Helm Chart 并运行 Kubernetes 原生安全检查,以识别提升的访问权限、错误配置和一般的最佳实践违规行为。KubeLinter 是一个基于 Go 的二进制文件,用于命令行或 CI 管道的一部分,并在允许任何 Kubernetes 配置更改之前为开发人员提供必要的安全检查。目前,CLI 中内置了 19 项安全检查,包括:

使用默认ServiceAccount 不匹配的选择器 以 root 身份运行容器 设置可写的 host 主机挂载

安装 KubeLinter

使用 Go 安装

GO111MODULE=on go get golang.stackrox.io/kube-linter/cmd/kube-linter 

或者直接从 Release 页面(https://github.com/stackrox/kube-linter/releases/tag/0.2.2)下载最新的二进制文件添加到 PATH 路径下即可。

使用 brew 安装

在 macOS 下使用 Homebrew 或者在 Linux 下使用 LinuxBrew 安装:

brew install kube-linter 

使用 KubeLinter

运行 KubeLinter 对 YAML 文件进行 Lint 只需要最基本的两个步骤即可:

1. 找到您要测试安全性和生产就绪最佳实践的 YAML 文件

2. 执行命令 kube-linter lint /path/to/your/yaml.yaml

例如下面的的 pod.yaml 资源文件,该文件存在几个问题:

安全问题

1. 这个 pod 中的容器不是作为只读文件系统运行的,这可能允许它写入 root 文件系统。

生产就绪

1. 容器的 CPU 限制未设置,这可能会使其消耗过多的 CPU2. 未设置容器的内存限制,这可能会使其消耗过多内存

apiVersion: v1  kind: Pod  metadata:  name: security-context-demo  spec:  securityContext:      runAsUser: 1000      runAsGroup: 3000      fsGroup: 2000  volumes:  – name: sec-ctx-vol      emptyDir: {}  containers:  – name: sec-ctx-demo      image: busybox      resources:      requests:          memory: “64Mi”         cpu: “250m”     command: [ “sh”“-c”“sleep 1h” ]      volumeMounts:      – name: sec-ctx-vol      mountPath: /data/demo      securityContext:      allowPrivilegeEscalation: false

3. 拷贝上面的 pod.yaml 文件执行下面的命令进行 lint

kube-linter lint pod.yaml 

4. KubeLinter 运行默认检查,会输出如下所示的结果

pod.yaml: (object: <no namespace>/security-context-demo /v1, Kind=Pod) container “sec-ctx-demo” does not have a readonly root file system (checknoreadonly-root-fs, remediation: Set readOnlyRootFilesystem totruein your containers securityContext.)  pod.yaml: (object: <no namespace>/security-context-demo /v1, Kind=Pod) container “sec-ctx-demo” has cpu limit 0 (check: unset-cpu-requirements, remediation: Set    your containers CPU requests and limits depending on its requirements. See    https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/   #requests-and-limits for more details.)  pod.yaml: (object: <no namespace>/security-context-demo /v1, Kind=Pod) container “sec-ctx-demo” has memory limit 0 (check: unset-memory-requirements, remediation:    Set your containers memory requests and limits depending on its requirements.    See https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/   #requests-and-limits for more details.)  Error: found 3 lint errors 

原文链接:https://mp.weixin.qq.com/s/7MqRoVN5hiytLKXIO5cBwQ

声明: 猿站网有关资源均来自网络搜集与网友提供,任何涉及商业盈利目的的均不得使用,否则产生的一切后果将由您自己承担! 本平台资源仅供个人学习交流、测试使用 所有内容请在下载后24小时内删除,制止非法恶意传播,不对任何下载或转载者造成的危害负任何法律责任!也请大家支持、购置正版! 。本站一律禁止以任何方式发布或转载任何违法的相关信息访客发现请向站长举报,会员发帖仅代表会员个人观点,并不代表本站赞同其观点和对其真实性负责。本网站的资源部分来源于网络,如有侵权烦请发送邮件至:2697268773@qq.com进行处理。
建站知识

小知识:3389 远程桌面连接的使用技巧

2023-3-21 12:23:22

建站知识

小知识:Zabbix 6.0LTS疑似发布第一个alpha版本,暂无太大改变

2023-3-21 12:37:59

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索