Skip to main content

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

High

Address

Compliance, Security

Compliance Standards

  • Cloudanix Best Practice

Triage and Remediation

Remediation

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.

1. Confirm your OKE cluster supports Pod Security Admission

  1. In the OCI Console, open the navigation menu.
  2. Go to Developer Services → Kubernetes Clusters (OKE).
  3. Click your cluster name.
  4. 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:
  1. From the Cluster details page, look for a section or tab such as Security, Pod Security, or Add-ons (naming can vary by release).
  2. 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.
If your UI version exposes it at namespace level only, continue directly to the next step.

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).
  1. In the OCI Console, still under your OKE cluster, go to the Workloads or Kubernetes Resources section.
  2. Click Namespaces.
  3. 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
    • Save or Update the namespace.
Some console builds may show pod security as dropdowns instead of raw labels; in that case, select:
  • Enforce level: restricted
  • (Optional) Audit level: restricted
  • Warn level: restricted

4. Effect on privilege escalation

Once restricted is enforced on the namespace:
  • Pods that attempt to set:
    • securityContext.allowPrivilegeEscalation: true, or
    • securityContext.privileged: true,
    • or other restricted capabilities
  • will be rejected by the API server at admission time.
This directly prevents privilege‑escalating container configurations in that namespace.

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:
  1. Under your cluster, go to Workloads → Deployments (or Pods).
  2. Try to create a deployment (via “Create deployment”) with a container security context that requests privilege escalation.
  3. 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.
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.

1. Get kubeconfig for your OKE cluster via OCI CLI

Verify access:

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:
Check:
Any new pod in those namespaces will be denied if it requests privilege escalation or privileged mode.

3. Ensure new workloads cannot request privilege escalation

Update your deployment specs so containers explicitly set:
Apply via kubectl:

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

Wait for pods:

4.2 Create a ConstraintTemplate

4.3 Create the Constraint (enforce everywhere or per-namespace)

Cluster-wide:
Now any pod without allowPrivilegeEscalation: false will be rejected.

5. Validate

Try to create a non-compliant pod:
You should see an admission error (from PSA or Gatekeeper) blocking the pod.
Summary:
  1. Use OCI CLI to generate kubeconfig and connect to the OKE cluster.
  2. Use Kubernetes Pod Security Admission with restricted labels on namespaces.
  3. Update workloads to set securityContext.allowPrivilegeEscalation: false.
  4. Optionally enforce globally via Gatekeeper + constraint.
To prevent container privilege escalation in OCI OKE using Python, you typically do two things:
  1. Enforce the policy at admission time (recommended, cluster-wide).
  2. Fix existing workloads (patch Deployments, StatefulSets, etc. to set allowPrivilegeEscalation: false).
Below are step‑by‑step instructions for both, focused on Python where applicable.

1. Enforce “no privilege escalation” via Kubernetes policy

Option A – Use Kubernetes Pod Security Admission (if available in your OKE version)

Define a PodSecurity enforce level of restricted (which includes allowPrivilegeEscalation=false) at namespace level.
  1. Label the namespace:
This does not require Python; it’s a cluster configuration step. All new Pods in that namespace must comply (i.e., 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.allowPrivilegeEscalation is not set or is true.
Example Gatekeeper ConstraintTemplate (YAML) or Kyverno policy can be applied via 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

Ensure your kubeconfig points to the OKE cluster:

2.2. Python script to set allowPrivilegeEscalation: false

Run:
This will trigger a rollout for each modified Deployment, recreating Pods with allowPrivilegeEscalation: false.

3. (Optional) Extend to StatefulSets / DaemonSets / Jobs

Use the same pattern with:
  • apps_v1.list_namespaced_stateful_set + patch_namespaced_stateful_set
  • apps_v1.list_namespaced_daemon_set + patch_namespaced_daemon_set
  • batch_v1.list_namespaced_job + patch_namespaced_job
Reuse ensure_no_priv_escalation and adjust the API calls.

4. Validate

  1. Describe a Pod:
You should see:
  1. Try to deploy a workload that sets allowPrivilegeEscalation: true and ensure it is blocked (if you enabled Pod Security Admission / policy).