SELinux options can be used to escalate privileges and should not be allowed. This policy ensures that the `seLinuxOptions` field is undefined.
apiVersion: kyverno.io/v1kind: ClusterPolicymetadata:name: disallow-selinuxannotations:policies.kyverno.io/title: Disallow SELinux in CEL expressionspolicies.kyverno.io/category: Pod Security Standards (Baseline) in CELpolicies.kyverno.io/severity: mediumpolicies.kyverno.io/subject: Podpolicies.kyverno.io/minversion: 1.11.0kyverno.io/kyverno-version: 1.11.0kyverno.io/kubernetes-version: 1.26-1.27policies.kyverno.io/description: SELinux options can be used to escalate privileges and should not be allowed. This policy ensures that the `seLinuxOptions` field is undefined.spec:validationFailureAction: Auditbackground: truerules:- name: selinux-typematch:any:- resources:kinds:- Podoperations:- CREATE- UPDATEvalidate:cel:variables:- name: allContainerTypesexpression: "(object.spec.containers + (has(object.spec.initContainers) ? object.spec.initContainers : []) + (has(object.spec.ephemeralContainers) ? object.spec.ephemeralContainers : []))"- name: seLinuxTypesexpression: "['container_t', 'container_init_t', 'container_kvm_t']"expressions:- expression: (!has(object.spec.securityContext) || !has(object.spec.securityContext.seLinuxOptions) || !has(object.spec.securityContext.seLinuxOptions.type) || variables.seLinuxTypes.exists(type, type == object.spec.securityContext.seLinuxOptions.type)) && variables.allContainerTypes.all(container, !has(container.securityContext) || !has(container.securityContext.seLinuxOptions) || !has(container.securityContext.seLinuxOptions.type) || variables.seLinuxTypes.exists(type, type == container.securityContext.seLinuxOptions.type))message: Setting the SELinux type is restricted. The field securityContext.seLinuxOptions.type must either be unset or set to one of the allowed values (container_t, container_init_t, or container_kvm_t).- name: selinux-user-rolematch:any:- resources:kinds:- Podoperations:- CREATE- UPDATEvalidate:cel:variables:- name: allContainerTypesexpression: "(object.spec.containers + (has(object.spec.initContainers) ? object.spec.initContainers : []) + (has(object.spec.ephemeralContainers) ? object.spec.ephemeralContainers : []))"expressions:- expression: (!has(object.spec.securityContext) || !has(object.spec.securityContext.seLinuxOptions) || (!has(object.spec.securityContext.seLinuxOptions.user) && !has(object.spec.securityContext.seLinuxOptions.role))) && variables.allContainerTypes.all(container, !has(container.securityContext) || !has(container.securityContext.seLinuxOptions) || (!has(container.securityContext.seLinuxOptions.user) && !has(container.securityContext.seLinuxOptions.role)))message: Setting the SELinux user or role is forbidden. The fields seLinuxOptions.user and seLinuxOptions.role must be unset.
This policy prevents the use of the default project in an Application.
This policy prevents updates to the project field after an Application is created.
This policy ensures that the name of the ApplicationSet is the same value provided in the project.