pod安全配置SecurityContext

132 阅读2分钟

SecurityContext

官方文档https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.29/#securitycontext-v1-core

相关博客https://www.qikqiak.com/k3s/security/security-context/

kubernetes目前针对于Pod和Container的安全配置主要有SecurityContextPodSecurityContext,当同时存在时,以SecurityContext配置优先。

该能力不是Kubernetes或者容器runtime本身的能力,而是kubernetes和runtime通过用户的配置,最后下传到内核里,再通过内核的机制让其生效。

此字段包含的子字段如下

allowPrivilegeEscalation

值为boolean类型,标识进程是否可以获得比其父进程更多的特权,会控制是否在容器进程上设置no_new_privs标志

capabilities

默认为容器运行时授予的默认功能集。

FieldDescription
add string arrayAdded capabilities
drop string arrayRemoved capabilities

privileged

值为boolean类型,特权容器中的进程本质上等同于主机上的根进程。

procMount

值为string类型,procMount表示用于容器的进程挂载类型。默认是DefaultProcMount,它使用容器运行时默认的只读路径和掩码路径。

readOnlyRootFilesystem

值为boolean类型,该容器是否具有只读根文件系统。默认为false。

runAsGroup

值为integer类型,用于运行容器进程入口点的GID。

runAsNonRoot

值为boolean类型,指示容器必须以非root用户运行。如果为true, Kubelet将在运行时验证映像,以确保它不是作为UID 0 (root)运行

runAsUser

值为integer类型,用于运行容器进程入口点的UID。

seLinuxOptions

要应用于容器的SELinux上下文。如果未指定,容器运行时将为每个容器分配一个随机SELinux上下文。

FieldDescription
level stringLevel is SELinux level label that applies to the container.
role stringRole is a SELinux role label that applies to the container.
type stringType is a SELinux type label that applies to the container.
user stringUser is a SELinux user label that applies to the container.

seccompProfile

FieldDescription
localhostProfile string配置文件路径
type stringlocalhost标识使用本机配置文件;RuntimeDefault标识使用默认配置;

windowsOptions

用于设置windows选项