Skip to main content

More Info:

Privileged containers run with all Linux capabilities and bypass most container isolation. They must be denied at admission time and only allowed via narrow exceptions tied to specific signed workloads.

Risk Level

Critical

Address

Compliance, Security

Compliance Standards

  • CIS OKE

Triage and Remediation

Remediation

Using Console

To minimize admission of privileged containers in an OCI OKE cluster using the OCI Console, you do this by enabling and configuring the OPA Gatekeeper add‑on with restrictive policies.

1. Open your OKE cluster in the OCI Console

  1. Sign in to the OCI Console.
  2. From the left menu: Developer ServicesKubernetes Clusters (OKE).
  3. Select the Compartment that contains your cluster.
  4. Click the name of the cluster you want to secure.

2. Enable / configure the Gatekeeper add‑on

  1. In the cluster details page, go to the Add‑ons (or Add‑ons & Security) tab.
  2. Look for Gatekeeper or Policy / Security related add‑on:
    • If Gatekeeper is not enabled:
      • Click Enable / Install Add‑on.
      • Choose Gatekeeper.
    • If Gatekeeper is already enabled:
      • Click Edit configuration or the equivalent action for that add‑on.
  3. In the Gatekeeper configuration:
    • Choose the policy profile that blocks privileged containers. Depending on the UI version, this is typically:
      • Restricted (or similar) Pod Security profile, or
      • A checkbox / toggle like Disallow privileged containers, Block privileged containers, or Disallow privilege escalation.
    • Make sure the setting that forbids securityContext.privileged: true (and usually allowPrivilegeEscalation: true) is enabled/enforced.
  4. Click Save, Update, or Apply to reconfigure the cluster.
    • The cluster control plane will roll out the updated admission policy.

3. Confirm enforcement

  1. After the add‑on update completes, try to deploy (or redeploy) a pod that uses:
  2. The deployment should now be rejected by admission control with an error from Gatekeeper / policy enforcement.

4. Clean up existing workloads (if any)

Admission control only blocks new or updated workloads:
  1. In the console, under the cluster, go to Workloads or Deployments.
  2. Identify any pods/deployments/DaemonSets that:
    • Use HostPath volumes with root access and
    • Have Privileged containers (visible in the workload details).
  3. Edit or redeploy those workloads (via your normal CI/CD or kubectl) to remove:
If you can share what you see under Add‑ons or Security for the cluster in the console (names of toggles / profiles), I can map it to the exact click-path and profile name for your tenancy’s OKE version.
To minimize admission of privileged containers on OCI OKE, you use the OPA Gatekeeper admission controller and define a policy that denies pods with securityContext.privileged: true.Below are the steps, with OCI CLI where applicable.

1. Prerequisites

  • OCI CLI installed and configured (oci setup config)
  • You have permissions to update the OKE cluster
  • kubectl configured for the cluster (oci ce cluster create-kubeconfig)

2. Enable the Admission Controller (OPA Gatekeeper) via OCI CLI

  1. Get the OKE cluster OCID (if you don’t already have it):
  1. Enable the admission controller:
Verify it’s enabled:

3. Configure kubectl Access (once per admin machine)


4. Create a Gatekeeper ConstraintTemplate to Deny Privileged Containers

Save as ct-deny-privileged-containers.yaml:
Apply:

5. Create a Constraint to Enforce the Template Cluster-wide

Save as c-deny-privileged-containers.yaml:
Apply:

6. Test the Policy

Try to create a privileged pod:
You should see an admission error from Gatekeeper denying the pod.

7. (Optional) Scope / Soften the Policy

  • To allow specific namespaces, add them under spec.match.namespaces.
  • To exclude system namespaces:
Re-apply the constraint if you modify it:

That configuration (enabled via OCI CLI and enforced via OPA Gatekeeper) ensures OKE minimizes and typically blocks admission of privileged containers.
Below is a practical way to remediate “privileged containers” in OCI OKE using Python, by:
  1. Auditing for privileged containers.
  2. Patching workloads to remove privileged: true.
  3. Optionally enforcing Kubernetes Pod Security “restricted” mode at namespace level.
This uses the official Kubernetes Python client against your OKE cluster.

1. Prerequisites

  1. Ensure you can run kubectl against your OKE cluster:
  2. Install Kubernetes Python client:
  3. Make sure your kubeconfig is available (typically ~/.kube/config) and points to the OKE cluster.

2. Python: Find All Privileged Containers

This script inspects Pods, Deployments, StatefulSets, DaemonSets, and Jobs for securityContext.privileged: true at:
  • container level
  • pod-level securityContext (for whole pod)
Run it and review output. Confirm which workloads truly need privilege (ideally none).

3. Python: Patch Workloads to Remove privileged: true

Below is a targeted patch for Deployments; you can adapt the same logic for StatefulSets, DaemonSets, and Jobs.This:
  • Loads the Deployment.
  • Iterates containers and initContainers.
  • Deletes or sets securityContext.privileged to false.
  • Patches the Deployment.
Extend this pattern for other controller types by using:
  • apps.read_namespaced_stateful_set / patch_namespaced_stateful_set
  • apps.read_namespaced_daemon_set / patch_namespaced_daemon_set
  • batch.read_namespaced_job / patch_namespaced_job

For Kubernetes 1.25+ (where PodSecurityPolicy is removed), use Pod Security Admission labels.At the namespace level, you can enforce the restricted profile (which denies privileged containers) using Python:
After applying:
  • Any new Pod/Deployment/Job with securityContext.privileged: true will be rejected by the API server.

5. Operational Flow

  1. Audit: Run the audit script to identify all privileged containers.
  2. Discuss/validate: Confirm with app owners which workloads (if any) truly need elevated privileges.
  3. Patch: Use the patch script to remove privileged: true from those that don’t need it.
  4. Enforce: Label namespaces with Pod Security restricted using the last script so future privileged pods are blocked in OKE.
  5. CI/CD integration (optional): Run the audit-or-fail script in your pipeline to prevent regressions.
If you share your Kubernetes version and whether you’re already using Gatekeeper/OPA on OKE, I can tailor this to that setup as well.