[CKS] Audit Log Policy

最近准备花一周的时间准备CKS考试,在准备考试中发现有一个题目关于audit policy的题目。

​ 专栏其他文章:

What's the audit policy

使用K8s Audit Policy,管理员可以定义哪些操作需要被审计,包括创建、删除、更新和查看集群中的资源。审计记录包括操作的时间戳、执行操作的用户、操作的命令和参数等信息。

审计记录可以被发送到不同的目标,例如日志文件、集中式日志管理系统或外部审计系统,以供后续分析和调查使用。

通过使用K8s Audit Policy,管理员可以获得对集群中操作的更大可见性和可追踪性,以增强安全性和合规性。

Question 1

The cluster has an audit policy configured. The audit policy file is located at /etc/kubernetes/audit-policy.yaml. Add the following rules to the audit policy:

  • Log the request and response body for changes to configmaps.
  • Log the request body for changes to services and pods in the web namespace.
  • Log metadata for changes to secrets.
  • Create a catch-all rule to log metadata for all remaining requests.

这里要求我们在audit-policy.yaml文件中创建如下的audit log规则

  • 记录对configmaps进行更改的请求和响应体。
  • 记录对web命名空间中服务和pod进行更改的请求体。
  • 记录对secrets进行更改的元数据。
  • 创建一个捕获所有其他请求的规则,并记录其元数据。

Practice

更改audit-policy.yaml文件内容如下

Question 2

Configure audit logging for the cluster.

  • Direct audit log output to a file located at /var/log/kubernetes/audit.log.
  • Maintain old log files for a maximum of 10 days.
  • Keep a maximum of 1 old log files.

这里要求配置审计日志记录如下:

  • 将审计日志输出到位于/var/log/kubernetes/audit.log的文件中。
  • 保留旧日志文件的最长时间为10天。
  • 保留最多1个旧日志文件。

Practice

修改kube-apiserver的配置文件如下:

shell 复制代码
sudo vi /etc/kubernetes/manifests/kube-apiserver.yaml

如何进行验证

shell 复制代码
sudo tail -f /var/log/kubernetes/audit.log
相关推荐
百年੭ ᐕ)੭*⁾⁾1 天前
docker使用neo4j
docker·容器·neo4j
BenSmith1 天前
从零上手嵌入式 RTOS:以 Raspberry Pi Pico 2 WH 为例的烧录、定制构建与多系统对比指南
安全
汇智信科1 天前
训练安全管理系统:赋能军消装备训练,实现全流程智能化管控
安全·训练安全管理·装备训练智能化·军事训练保障·消防训练管理
春风有信1 天前
【2026.05.01】Windows10安装Docker Desktop 4.71.0.0步骤及问题解决
运维·docker·容器
其实防守也摸鱼1 天前
CTF密码学综合教学指南--第三章
开发语言·网络·python·安全·网络安全·密码学
其实防守也摸鱼1 天前
CTF密码学综合教学指南--第四章
网络·笔记·安全·网络安全·密码学·ctf
DevilSeagull1 天前
电脑上安装的服务会自动消失? 推荐项目: localhostSCmanager. 更好管理你的服务!
测试工具·安全·react·vite·localhost·hono·trpc
@insist1231 天前
信息安全-防火墙技术演进全景:从代理NAT 到下一代及专项防火墙
网络·安全·web安全·软考·信息安全工程师·软件水平考试
sthnyph1 天前
docker compose安装redis
redis·docker·容器