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
CriticalAddress
Compliance, SecurityCompliance Standards
- CIS OKE
Triage and Remediation
- Remediation
Remediation
Using Console
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
- Sign in to the OCI Console.
- From the left menu: Developer Services → Kubernetes Clusters (OKE).
- Select the Compartment that contains your cluster.
- Click the name of the cluster you want to secure.
2. Enable / configure the Gatekeeper add‑on
- In the cluster details page, go to the Add‑ons (or Add‑ons & Security) tab.
-
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.
- If Gatekeeper is not enabled:
-
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 usuallyallowPrivilegeEscalation: true) is enabled/enforced.
- Choose the policy profile that blocks privileged containers. Depending on the UI version, this is typically:
-
Click Save, Update, or Apply to reconfigure the cluster.
- The cluster control plane will roll out the updated admission policy.
3. Confirm enforcement
- After the add‑on update completes, try to deploy (or redeploy) a pod that uses:
- 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:- In the console, under the cluster, go to Workloads or Deployments.
- Identify any pods/deployments/DaemonSets that:
- Use HostPath volumes with root access and
- Have Privileged containers (visible in the workload details).
- Edit or redeploy those workloads (via your normal CI/CD or
kubectl) to remove:
Using CLI
Using CLI
To minimize admission of privileged containers on OCI OKE, you use the OPA Gatekeeper admission controller and define a policy that denies pods with
Verify it’s enabled:
3. Configure
Apply:
Apply:
You should see an admission error from Gatekeeper denying the pod.
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.
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
kubectlconfigured for the cluster (oci ce cluster create-kubeconfig)
2. Enable the Admission Controller (OPA Gatekeeper) via OCI CLI
- Get the OKE cluster OCID (if you don’t already have it):
- Enable the admission controller:
3. Configure kubectl Access (once per admin machine)
4. Create a Gatekeeper ConstraintTemplate to Deny Privileged Containers
Save asct-deny-privileged-containers.yaml:5. Create a Constraint to Enforce the Template Cluster-wide
Save asc-deny-privileged-containers.yaml:6. Test the Policy
Try to create a privileged pod:7. (Optional) Scope / Soften the Policy
- To allow specific namespaces, add them under
spec.match.namespaces. - To exclude system namespaces:
That configuration (enabled via OCI CLI and enforced via OPA Gatekeeper) ensures OKE minimizes and typically blocks admission of privileged containers.
Using Python
Using Python
Below is a practical way to remediate “privileged containers” in OCI OKE using Python, by:
Run it and review output. Confirm which workloads truly need privilege (ideally none).
3. Python: Patch Workloads to Remove
Below is a targeted patch for Deployments; you can adapt the same logic for StatefulSets, DaemonSets, and Jobs.This:Extend this pattern for other controller types by using:
After applying:
- Auditing for privileged containers.
- Patching workloads to remove
privileged: true. - Optionally enforcing Kubernetes Pod Security “restricted” mode at namespace level.
1. Prerequisites
- Ensure you can run
kubectlagainst your OKE cluster: - Install Kubernetes Python client:
- 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 forsecurityContext.privileged: true at:- container level
- pod-level
securityContext(for whole pod)
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.privilegedtofalse. - Patches the Deployment.
apps.read_namespaced_stateful_set/patch_namespaced_stateful_setapps.read_namespaced_daemon_set/patch_namespaced_daemon_setbatch.read_namespaced_job/patch_namespaced_job
4. Enforce “No Privileged” Using Pod Security Admission (Recommended)
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:- Any new Pod/Deployment/Job with
securityContext.privileged: truewill be rejected by the API server.
5. Operational Flow
- Audit: Run the audit script to identify all privileged containers.
- Discuss/validate: Confirm with app owners which workloads (if any) truly need elevated privileges.
- Patch: Use the patch script to remove
privileged: truefrom those that don’t need it. - Enforce: Label namespaces with Pod Security restricted using the last script so future privileged pods are blocked in OKE.
- CI/CD integration (optional): Run the audit-or-fail script in your pipeline to prevent regressions.
Using Terraform
Using Terraform

