Kubernetes SecurityContext(s)
Tip
学习并练习 AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
学习并练习 GCP Hacking:HackTricks Training GCP Red Team Expert (GRTE)
学习并练习 Az Hacking:HackTricks Training Azure Red Team Expert (AzRTE)
支持 HackTricks
- 查看 subscription plans!
- 加入 💬 Discord group 或者 telegram group 或 关注 我们的 Twitter 🐦 @hacktricks_live.
- 通过向 HackTricks 和 HackTricks Cloud github 仓库 提交 PRs 来分享 hacking tricks。
PodSecurityContext
在指定 Pod 的安全上下文时,可以使用多个属性。从防御安全的角度来看,您应该考虑:
- 将 runASNonRoot 设置为 True
- 配置 runAsUser
- 如果可能,考虑 限制 权限,指明 seLinuxOptions 和 seccompProfile
- 不要 通过 runAsGroup 和 supplementaryGroups 授予 特权 组 访问权限
| 参数 | 描述 | |
fsGroup
integer
适用于所有容器的特殊补充组。某些卷类型允许 Kubelet 更改该卷的所有权,使其归 Pod 所有:
1. 拥有的 GID 将是 FSGroup
2. 设置 setgid 位(在卷中创建的新文件将由 FSGroup 拥有)
3. 权限位与 rw-rw–– 进行 OR 操作。如果未设置,Kubelet 将不会修改任何卷的所有权和权限
|
fsGroupChangePolicy
string
runAsGroup
integer
runAsNonRoot
boolean
runAsUser
integer
seLinuxOptions
SELinuxOptions
有关 seLinux 的更多信息
seccompProfile
SeccompProfile
有关 Seccomp 的更多信息
supplementalGroups
integer array
windowsOptions
WindowsSecurityContextOptions
SecurityContext
此上下文设置在 容器定义 内。从防御安全的角度来看,您应该考虑:
- allowPrivilegeEscalation 设置为 False
- 不要添加敏感的 capabilities(并删除不需要的)
- privileged 设置为 False
- 如果可能,将 readOnlyFilesystem 设置为 True
- 将 runAsNonRoot 设置为 True 并设置 runAsUser
- 如果可能,考虑 限制 权限,指明 seLinuxOptions 和 seccompProfile
- 不要 通过 runAsGroup 授予 特权 组 访问权限。
请注意,在 SecurityContext 和 PodSecurityContext 中设置的属性,SecurityContext 中指定的值具有 优先权。
|
allowPrivilegeEscalation | AllowPrivilegeEscalation 控制进程是否可以 获得比其父进程更多的权限。此布尔值直接控制是否将在容器进程上设置 no_new_privs 标志。当容器以 Privileged 身份运行或具有 CAP_SYS_ADMIN 时,AllowPrivilegeEscalation 始终为 true |
|---|---|
|
capabilities | 运行容器时添加/删除的能力。默认为默认的能力集。 |
|
privileged | 以特权模式运行容器。特权容器中的进程基本上 等同于主机上的 root。默认为 false。 |
|
procMount | procMount 表示 用于容器的 proc 挂载类型。默认值为 DefaultProcMount,它使用容器运行时的默认只读路径和屏蔽路径。 |
|
readOnlyRootFilesystem | 此 容器是否具有只读根文件系统。默认值为 false。 |
|
runAsGroup | 运行容器进程的入口点的 GID。如果未设置,则使用运行时默认值。 |
|
runAsNonRoot | 表示容器必须 以非根用户身份运行。如果为 true,Kubelet 将在运行时验证映像,以确保它不以 UID 0(根)身份运行,如果是,则无法启动容器。 |
|
runAsUser | 运行容器进程的入口点的 UID。如果未指定,则默认为映像元数据中指定的用户。 |
|
seLinuxOptions | 应用于容器的 SELinux 上下文。如果未指定,容器运行时将为每个容器分配一个随机的 SELinux 上下文。 |
| 此容器使用的 seccomp 选项。 | |
| 应用于所有容器的 Windows 特定设置。 |
References
- https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#podsecuritycontext-v1-core
- https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#securitycontext-v1-core
Tip
学习并练习 AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
学习并练习 GCP Hacking:HackTricks Training GCP Red Team Expert (GRTE)
学习并练习 Az Hacking:HackTricks Training Azure Red Team Expert (AzRTE)
支持 HackTricks
- 查看 subscription plans!
- 加入 💬 Discord group 或者 telegram group 或 关注 我们的 Twitter 🐦 @hacktricks_live.
- 通过向 HackTricks 和 HackTricks Cloud github 仓库 提交 PRs 来分享 hacking tricks。
HackTricks Cloud

