More Info:
allowPrivilegeEscalation=true lets a process gain more privileges than its parent (for example via setuid binaries). Set it to false in pod security policies to enforce no-new-privs and reduce container breakout paths.Risk Level
HighAddress
Compliance, SecurityCompliance Standards
- Cloudanix Best Practice
Triage and Remediation
- Remediation
Remediation
Using Console
Using Console
To prevent container privilege escalation in OCI OKE using the OCI Console, the most practical native method is to use Pod Security Admission (PSA) with a restricted policy on your namespaces.Below are the step‑by‑step console actions.
If your specific OCI Console version does not expose PSA/labels via UI for namespaces, you will need a one‑time
1. Confirm your OKE cluster supports Pod Security Admission
- In the OCI Console, open the navigation menu.
- Go to Developer Services → Kubernetes Clusters (OKE).
- Click your cluster name.
- On the Cluster details page, check the Kubernetes version:
- PSA is supported on recent versions (e.g., 1.25+).
- If you are on an older version, plan to upgrade the cluster (Actions → Upgrade cluster).
2. Enable / Verify Pod Security Admission on the Cluster
Depending on your console view:- From the Cluster details page, look for a section or tab such as Security, Pod Security, or Add-ons (naming can vary by release).
- Ensure that Pod Security Admission (or “Pod Security Standards”) is enabled.
- If there is a toggle or configuration option to enable pod security, turn it ON and save.
3. Apply a “restricted” Pod Security profile to namespaces (console)
You want the restricted profile in enforce mode on the namespaces where you run workloads. This profile disallows privilege escalation (and other unsafe settings).- In the OCI Console, still under your OKE cluster, go to the Workloads or Kubernetes Resources section.
- Click Namespaces.
- For each target namespace:
- Click the namespace name to open its details.
- Look for a section to manage labels or pod security configuration.
- Add/ensure the following labels are set (field names may be “Key” and “Value”):
- Key:
pod-security.kubernetes.io/enforce
Value:restricted - (Optional, but recommended for consistency/preview):
Key:pod-security.kubernetes.io/audit
Value:restricted
Key:pod-security.kubernetes.io/warn
Value:restricted
- Key:
- Save or Update the namespace.
- Enforce level:
restricted - (Optional) Audit level:
restricted - Warn level:
restricted
4. Effect on privilege escalation
Oncerestricted is enforced on the namespace:- Pods that attempt to set:
securityContext.allowPrivilegeEscalation: true, orsecurityContext.privileged: true,- or other restricted capabilities
- will be rejected by the API server at admission time.
5. (Optional) Validate via the Console
You can confirm that the policy works by attempting to deploy a workload via the console that includes a privileged/privilege‑escalating container:- Under your cluster, go to Workloads → Deployments (or Pods).
- Try to create a deployment (via “Create deployment”) with a container security context that requests privilege escalation.
- The pod creation should fail with an error referencing pod security / restricted policy.
If your specific OCI Console version does not expose PSA/labels via UI for namespaces, you will need a one‑time
kubectl command to add the pod‑security labels; the enforcement behavior in the cluster is the same once labels are present.Using CLI
Using CLI
To prevent container privilege escalation on OKE, you must enforce Kubernetes security controls on the cluster. OCI CLI is used to connect to the cluster; the actual enforcement is done via Kubernetes (kubectl) once connected.Below are minimal, concrete steps.
Verify access:
2.1 Label current namespaces to
For each workload namespace:Check:Any new pod in those namespaces will be denied if it requests privilege escalation or privileged mode.
Apply via kubectl:
Wait for pods:Now any pod without
You should see an admission error (from PSA or Gatekeeper) blocking the pod.
Summary:
1. Get kubeconfig for your OKE cluster via OCI CLI
2. Enforce Pod Security Admission (PSA) – “restricted” Profile
This prevents privileged containers and privilege escalation at the namespace level.2.1 Label current namespaces to restricted
For each workload namespace:3. Ensure new workloads cannot request privilege escalation
Update your deployment specs so containers explicitly set:4. Optionally, block privilege escalation cluster‑wide via a Validating Admission (Gatekeeper)
If you want a strict policy everywhere, deploy Gatekeeper and a constraint:4.1 Install Gatekeeper
4.2 Create a ConstraintTemplate
4.3 Create the Constraint (enforce everywhere or per-namespace)
Cluster-wide:allowPrivilegeEscalation: false will be rejected.5. Validate
Try to create a non-compliant pod:Summary:
- Use OCI CLI to generate kubeconfig and connect to the OKE cluster.
- Use Kubernetes Pod Security Admission with
restrictedlabels on namespaces. - Update workloads to set
securityContext.allowPrivilegeEscalation: false. - Optionally enforce globally via Gatekeeper + constraint.
Using Python
Using Python
To prevent container privilege escalation in OCI OKE using Python, you typically do two things:
This does not require Python; it’s a cluster configuration step. All new Pods in that namespace must comply (i.e.,
Ensure your kubeconfig points to the OKE cluster:2.2. Python script to set
Run:This will trigger a rollout for each modified Deployment, recreating Pods with
You should see:
- Enforce the policy at admission time (recommended, cluster-wide).
- Fix existing workloads (patch Deployments, StatefulSets, etc. to set
allowPrivilegeEscalation: false).
1. Enforce “no privilege escalation” via Kubernetes policy
Option A – Use Kubernetes Pod Security Admission (if available in your OKE version)
Define aPodSecurity enforce level of restricted (which includes allowPrivilegeEscalation=false) at namespace level.- Label the namespace:
allowPrivilegeEscalation must be false, among other things).Option B – Use OPA Gatekeeper / Kyverno (if you already use them)
If you’re using Gatekeeper or Kyverno on OKE, create a policy that:- Denies Pods/Deployments where:
securityContext.allowPrivilegeEscalationis not set or istrue.
kubectl apply. You can also apply them with a Python script using the Kubernetes Python client’s create_namespaced_custom_object, but most teams manage these as YAML in Git.2. Remediate existing workloads with Python (Kubernetes Python client)
Below is a Python approach that:- Connects to your OKE cluster
- Lists Deployments (you can extend to StatefulSets, DaemonSets, Jobs)
- Patches pod specs so every container and initContainer has:
securityContext.allowPrivilegeEscalation = False
2.1. Install Python dependencies
2.2. Python script to set allowPrivilegeEscalation: false
allowPrivilegeEscalation: false.3. (Optional) Extend to StatefulSets / DaemonSets / Jobs
Use the same pattern with:apps_v1.list_namespaced_stateful_set+patch_namespaced_stateful_setapps_v1.list_namespaced_daemon_set+patch_namespaced_daemon_setbatch_v1.list_namespaced_job+patch_namespaced_job
ensure_no_priv_escalation and adjust the API calls.4. Validate
- Describe a Pod:
- Try to deploy a workload that sets
allowPrivilegeEscalation: trueand ensure it is blocked (if you enabled Pod Security Admission / policy).
Using Terraform
Using Terraform

