Back to controls

Apply Security Context correctly to Pods and Containers

A security context defines the operating system security settings (uid, gid, capabilities, SELinux role, etc..) applied to a container. When designing your containers and pods, make sure that you configure the security context for your pods, containers, and volumes. A security context is a property defined in the deployment yaml. It controls the security parameters that will be assigned to the pod/container/volume. There are two levels of security context: pod level security context, and container level security context.

Category

Controls

Low

Applies to

Kubernetes

Coverage

null controls, 12 queries

Asset types

6 covered

Overview

A security context defines the operating system security settings (uid, gid, capabilities, SELinux role, etc..) applied to a container. When designing your containers and pods, make sure that you configure the security context for your pods, containers, and volumes. A security context is a property defined in the deployment yaml. It controls the security parameters that will be assigned to the pod/container/volume. There are two levels of security context: pod level security context, and container level security context.

Remediation guidance

Follow the Kubernetes documentation and apply security contexts to your pods. For a suggested list of security contexts, you may refer to the CIS Security Benchmark for Docker Containers.

https://workbench.cisecurity.org/sections/1126667/recommendations/1838636

Multiple Remediation Paths

SERVICE-WIDE (RECOMMENDED when many resources are affected): Apply organization/tenant-level guardrails and baseline policies for the entire platform.

ASSET-LEVEL: Fix only the affected resources identified by this control.

PREVENTIVE: Add preventive policy checks to CI/CD and periodic posture scans.

References for Service-Wide Patterns

  • Platform policy/governance and preventive control patterns should be applied tenant-wide where supported.

Query logic

These are the stored checks tied to this control.

Kubernetes Deployments with ContainersTemplates that have permissive security context

Connectors

Kubernetes

Covered asset types

Deployment

Expected check: eq []

{
  deployments(
    where: {
      podTemplate: {
        containersTemplates_SOME: {
          securityContext: {
            OR: [
              { isSeccompProfileSet: false }
              { isSELinuxOptionsSet: false }
              { allowPrivilegeEscalation: true }
              { runAsNonRoot: false }
              { runAsUser_GTE: 1000 }
              { runAsGroup_GTE: 1000 }
              { readOnlyRootFilesystem: false }
              { capabilitiesAdd_INCLUDES: "SYS_ADMIN" }
              { privileged: true }              
              {
                NOT: {
                  OR: [
                    { capabilitiesDrop_INCLUDES: "NET_RAW" }
                    { capabilitiesDrop_INCLUDES: "ALL" }
                    { capabilitiesDrop_INCLUDES: "all" }
                  ]
                }
              }
            ]
          }
        }
      }
    }
  ) {
    ...AssetFragment
  }
}
Kubernetes StatefulSets with ContainersTemplates that have permissive security context

Connectors

Kubernetes

Covered asset types

StatefulSet

Expected check: eq []

{
  statefulSets(
    where: {
      podTemplate: {
        containersTemplates_SOME: {
          securityContext: {
            OR: [
              { isSeccompProfileSet: false }
              { isSELinuxOptionsSet: false }
              { allowPrivilegeEscalation: true }
              { runAsNonRoot: false }
              { runAsUser_GTE: 1000 }
              { runAsGroup_GTE: 1000 }
              { readOnlyRootFilesystem: false }
              { capabilitiesAdd_INCLUDES: "SYS_ADMIN" }
              { privileged: true }              
              {
                NOT: {
                  OR: [
                    { capabilitiesDrop_INCLUDES: "NET_RAW" }
                    { capabilitiesDrop_INCLUDES: "ALL" }
                    { capabilitiesDrop_INCLUDES: "all" }
                  ]
                }
              }
            ]
          }
        }
      }
    }
  ) {
    ...AssetFragment
  }
}
Kubernetes ReplicaSets with ContainersTemplates that have permissive security context

Connectors

Kubernetes

Covered asset types

ReplicaSet

Expected check: eq []

{
  replicaSets(
    where: {
      deploymentName: ""
      podTemplate: {
        containersTemplates_SOME: {
          securityContext: {
            OR: [
              { isSeccompProfileSet: false }
              { isSELinuxOptionsSet: false }
              { allowPrivilegeEscalation: true }
              { runAsNonRoot: false }
              { runAsUser_GTE: 1000 }
              { runAsGroup_GTE: 1000 }
              { readOnlyRootFilesystem: false }
              { capabilitiesAdd_INCLUDES: "SYS_ADMIN" }
              { privileged: true }              
              {
                NOT: {
                  OR: [
                    { capabilitiesDrop_INCLUDES: "NET_RAW" }
                    { capabilitiesDrop_INCLUDES: "ALL" }
                    { capabilitiesDrop_INCLUDES: "all" }
                  ]
                }
              }
            ]
          }
        }
      }
    }
  ) {
    ...AssetFragment
  }
}
Kubernetes DaemonSets with ContainersTemplates that have permissive security context

Connectors

Kubernetes

Covered asset types

DaemonSet

Expected check: eq []

{
  daemonSets(
    where: {
      podTemplate: {
        containersTemplates_SOME: {
          securityContext: {
            OR: [
              { isSeccompProfileSet: false }
              { isSELinuxOptionsSet: false }
              { allowPrivilegeEscalation: true }
              { runAsNonRoot: false }
              { runAsUser_GTE: 1000 }
              { runAsGroup_GTE: 1000 }
              { readOnlyRootFilesystem: false }
              { capabilitiesAdd_INCLUDES: "SYS_ADMIN" }
              { privileged: true }              
              {
                NOT: {
                  OR: [
                    { capabilitiesDrop_INCLUDES: "NET_RAW" }
                    { capabilitiesDrop_INCLUDES: "ALL" }
                    { capabilitiesDrop_INCLUDES: "all" }
                  ]
                }
              }
            ]
          }
        }
      }
    }
  ) {
    ...AssetFragment
  }
}
Kubernetes Jobs with ContainersTemplates that have permissive security context

Connectors

Kubernetes

Covered asset types

Job

Expected check: eq []

{
  jobs(
    where: {
      cronJobName: ""
      podTemplate: {
        containersTemplates_SOME: {
          securityContext: {
            OR: [
              { isSeccompProfileSet: false }
              { isSELinuxOptionsSet: false }
              { allowPrivilegeEscalation: true }
              { runAsNonRoot: false }
              { runAsUser_GTE: 1000 }
              { runAsGroup_GTE: 1000 }
              { readOnlyRootFilesystem: false }
              { capabilitiesAdd_INCLUDES: "SYS_ADMIN" }
              { privileged: true }              
              {
                NOT: {
                  OR: [
                    { capabilitiesDrop_INCLUDES: "NET_RAW" }
                    { capabilitiesDrop_INCLUDES: "ALL" }
                    { capabilitiesDrop_INCLUDES: "all" }
                  ]
                }
              }
            ]
          }
        }
      }
    }
  ) {
    ...AssetFragment
  }
}
Kubernetes CronJobs with ContainersTemplates that have permissive security context

Connectors

Kubernetes

Covered asset types

CronJob

Expected check: eq []

{
  cronJobs(
    where: {
      podTemplate: {
        containersTemplates_SOME: {
          securityContext: {
            OR: [
              { isSeccompProfileSet: false }
              { isSELinuxOptionsSet: false }
              { allowPrivilegeEscalation: true }
              { runAsNonRoot: false }
              { runAsUser_GTE: 1000 }
              { runAsGroup_GTE: 1000 }
              { readOnlyRootFilesystem: false }
              { capabilitiesAdd_INCLUDES: "SYS_ADMIN" }
              { privileged: true }              
              {
                NOT: {
                  OR: [
                    { capabilitiesDrop_INCLUDES: "NET_RAW" }
                    { capabilitiesDrop_INCLUDES: "ALL" }
                    { capabilitiesDrop_INCLUDES: "all" }
                  ]
                }
              }
            ]
          }
        }
      }
    }
  ) {
    ...AssetFragment
  }
}
Kubernetes StatefulSets PodTemplates with permissive security context

Connectors

Kubernetes

Covered asset types

StatefulSet

Expected check: eq []

{
  statefulSets(
    where: {
      podTemplate: {
        securityContext: {
          OR: [
            { supplementalGroups: [] }
            { isSysctlsContainingElements: false }
            { isSeccompProfileSet: false }
            { isFSGroupChangePolicySet: false }
            { isFSGroupSet: false }
            {
              NOT: {
                OR: [
                  {
                    isFSGroupChangePolicySet: true
                    fsGroupChangePolicy_CONTAINS: "Always"
                  }
                  {
                    isFSGroupChangePolicySet: true
                    fsGroupChangePolicy_CONTAINS: "OnRootMismatch"
                  }
                ]
              }
            }
            { AND: [{ isFSGroupSet: true }, { fsGroup_LTE: 0 }] }
          ]
        }
      }
    }
  ) {
    ...AssetFragment
  }
}
Kubernetes ReplicaSets PodTemplates with permissive security context

Connectors

Kubernetes

Covered asset types

ReplicaSet

Expected check: eq []

{
  replicaSets(
    where: {
      deploymentName: ""
      podTemplate: {
        securityContext: {
          OR: [
            { supplementalGroups: [] }
            { isSysctlsContainingElements: false }
            { isSeccompProfileSet: false }
            { isFSGroupChangePolicySet: false }
            { isFSGroupSet: false }
            {
              NOT: {
                OR: [
                  {
                    isFSGroupChangePolicySet: true
                    fsGroupChangePolicy_CONTAINS: "Always"
                  }
                  {
                    isFSGroupChangePolicySet: true
                    fsGroupChangePolicy_CONTAINS: "OnRootMismatch"
                  }
                ]
              }
            }
            { AND: [{ isFSGroupSet: true }, { fsGroup_LTE: 0 }] }
          ]
        }
      }
    }
  ) {
    ...AssetFragment
  }
}
Kubernetes Deployments PodTemplates with permissive security context

Connectors

Kubernetes

Covered asset types

Deployment

Expected check: eq []

{
  deployments(
    where: {
      podTemplate: {
        securityContext: {
          OR: [
            { supplementalGroups: [] }
            { isSysctlsContainingElements: false }
            { isSeccompProfileSet: false }
            { isFSGroupChangePolicySet: false }
            { isFSGroupSet: false }
            {
              NOT: {
                OR: [
                  {
                    isFSGroupChangePolicySet: true
                    fsGroupChangePolicy_CONTAINS: "Always"
                  }
                  {
                    isFSGroupChangePolicySet: true
                    fsGroupChangePolicy_CONTAINS: "OnRootMismatch"
                  }
                ]
              }
            }
            { AND: [{ isFSGroupSet: true }, { fsGroup_LTE: 0 }] }
          ]
        }
      }
    }
  ) {
    ...AssetFragment
  }
}
Kubernetes DaemonSets PodTemplates with permissive security context

Connectors

Kubernetes

Covered asset types

DaemonSet

Expected check: eq []

{
  daemonSets(
    where: {
      podTemplate: {
        securityContext: {
          OR: [
            { supplementalGroups: [] }
            { isSysctlsContainingElements: false }
            { isSeccompProfileSet: false }
            { isFSGroupChangePolicySet: false }
            { isFSGroupSet: false }
            {
              NOT: {
                OR: [
                  {
                    isFSGroupChangePolicySet: true
                    fsGroupChangePolicy_CONTAINS: "Always"
                  }
                  {
                    isFSGroupChangePolicySet: true
                    fsGroupChangePolicy_CONTAINS: "OnRootMismatch"
                  }
                ]
              }
            }
            { AND: [{ isFSGroupSet: true }, { fsGroup_LTE: 0 }] }
          ]
        }
      }
    }
  ) {
    ...AssetFragment
  }
}
Kubernetes Jobs PodTemplates with permissive security context

Connectors

Kubernetes

Covered asset types

Job

Expected check: eq []

{
  jobs(
    where: {
      cronJobName: ""
      podTemplate: {
        securityContext: {
          OR: [
            { supplementalGroups: [] }
            { isSysctlsContainingElements: false }
            { isSeccompProfileSet: false }
            { isFSGroupChangePolicySet: false }
            { isFSGroupSet: false }
            {
              NOT: {
                OR: [
                  {
                    isFSGroupChangePolicySet: true
                    fsGroupChangePolicy_CONTAINS: "Always"
                  }
                  {
                    isFSGroupChangePolicySet: true
                    fsGroupChangePolicy_CONTAINS: "OnRootMismatch"
                  }
                ]
              }
            }
            { AND: [{ isFSGroupSet: true }, { fsGroup_LTE: 0 }] }
          ]
        }
      }
    }
  ) {
    ...AssetFragment
  }
}
Kubernetes CronJobs templates with permissive security context

Connectors

Kubernetes

Covered asset types

CronJob

Expected check: eq []

{
  cronJobs(
    where: {
      podTemplate: {
        securityContext: {
          OR: [
            { supplementalGroups: [] }
            { isSysctlsContainingElements: false }
            { isSeccompProfileSet: false }
            { isFSGroupChangePolicySet: false }
            { isFSGroupSet: false }
            {
              NOT: {
                OR: [
                  {
                    isFSGroupChangePolicySet: true
                    fsGroupChangePolicy_CONTAINS: "Always"
                  }
                  {
                    isFSGroupChangePolicySet: true
                    fsGroupChangePolicy_CONTAINS: "OnRootMismatch"
                  }
                ]
              }
            }
            { AND: [{ isFSGroupSet: true }, { fsGroup_LTE: 0 }] }
          ]
        }
      }
    }
  ) {
    ...AssetFragment
  }
}
Cyscale Logo
Cyscale is an agentless cloud-native application protection platform (CNAPP) that automates the contextual analysis of cloud misconfigurations, vulnerabilities, access, and data, to provide an accurate and actionable assessment of risk.

Stay connected

Receive new blog posts and product updates from Cyscale

By clicking Subscribe, I agree to Cyscale’s Privacy Policy


© 2026 Cyscale Limited

LinkedIn icon
Twitter icon
Facebook icon
crunch base icon
angel icon