More Info:
hostNetwork=true gives a pod direct access to node interfaces, bypassing NetworkPolicy and potentially exposing kubelet, kube-proxy, and other host services. Restrict this to system add-ons that genuinely require it.Risk Level
HighAddress
Compliance, SecurityCompliance Standards
- CIS OKE
Triage and Remediation
- Remediation
Remediation
Using Console
Using Console
To remediate “OCI OKE should minimize containers sharing the host network namespace” using the OCI Console, you need to:
- Identify workloads using
hostNetwork
- Sign in to the OCI Console.
- In the left menu, go to Developer Services → Containers & Artifacts → Kubernetes Clusters (OKE).
- Click your cluster.
- In the cluster detail page, click Workloads.
- For each Deployment / StatefulSet / DaemonSet / Pod:
- Open the workload.
- Click YAML (or Edit YAML / View YAML, depending on the console version).
- Look for:
- Also check container
portsforhostPortvalues (often appear with hostNetwork).
hostNetwork: true is sharing the host network namespace.- Edit workloads to stop using the host network
- In Workloads, click the workload (e.g., a Deployment).
- Click Edit YAML.
- In the pod spec, change or remove:
to either:or remove the
hostNetworkline entirely (default isfalse). - If possible, also remove any
hostPortmappings under containers: - Click Save / Update to apply the changes.
- The Deployment/StatefulSet/DaemonSet will roll out new pods without
hostNetwork.
hostNetwork: true.- (Optional but recommended) Enforce a policy to prevent future use
hostNetwork, but you can enforce via Kubernetes policy tools (e.g., Gatekeeper/OPA) deployed to your cluster. From the OCI Console you:- Go to your OKE cluster → Access Cluster → use the Cloud Shell or local
kubectl. - Deploy an admission policy that denies pods with
spec.hostNetwork: true.
ConstraintTemplate and Constraint would enforce this at cluster level. (This is done via kubectl apply rather than GUI, but initiated from the Console via Cloud Shell.)- Verify remediation
- In the Workloads view, re-open the YAML for each previously offending workload.
- Confirm:
hostNetworkis not present, or explicitly set tofalse.hostPortis removed where not necessary.
- Optionally, use:
- Cloud Guard (if enabled) → check your target/recipe to ensure the detector for host network sharing is now green/not triggering for the cluster.
Using CLI
Using CLI
In OKE this setting is controlled in the Pod spec (2. Find Pods using
If you want to find the owning controllers (Deployments/DaemonSets/StatefulSets):If the field must exist and be explicit:Repeat similarly for DaemonSets/StatefulSets, changing the resource kind:Note: If containers were binding to host ports (
hostNetwork: true), so the remediation is to update workloads so they no longer request the host network. OCI CLI is only for cluster/infra management, so you use it to get kubeconfig, then use kubectl against the cluster.1. Get kubeconfig for the OKE cluster using OCI CLI
2. Find Pods using hostNetwork: true
3. Update the owning resources to stop using host networking
For each Deployment/DaemonSet/StatefulSet that useshostNetwork: true, remove or set it to false.Example – patch a Deployment:hostPort), you must reconfigure them to use ClusterIP/NodePort/LoadBalancer Services instead.4. (Optional) Enforce policy so new Pods can’t use hostNetwork
You can use Admission Control / Pod Security Standards (if enabled in your OKE version) or a policy engine like Gatekeeper. A simple starting point is to apply aPodSecurity admission config or a Gatekeeper constraint that denies Pods with spec.hostNetwork: true. That’s done with kubectl apply -f <policy.yaml> after preparing the policy YAML; OCI CLI itself does not control that per‑Pod setting.Using Python
Using Python
In OKE this is a standard Kubernetes setting: containers use the host network when the Pod spec has
Make sure your kubeconfig for the OKE cluster is set (e.g. created via OCI CLI) and that
2. Python: Detect Pods Using
This script lists all pods in all namespaces that have
3. Python: Identify Higher-Level Controllers Using
Usually you don’t patch pods directly; you patch Deployments/DaemonSets/StatefulSets/Jobs that create them.Example to scan Deployments and DaemonSets:
4. Python: Patch Workloads to Disable
This will set Notes:
5. Optional: Enforce No
In OKE you can deploy OPA Gatekeeper or Kyverno. With Gatekeeper, you would:(Adjust namespaces and ensure Gatekeeper is already installed.)
hostNetwork: true. To “minimize” it, you must:- Find workloads using
hostNetwork: true. - Update their specs to
hostNetwork: false(or remove the field). - Optionally enforce a policy so it can’t be reintroduced.
1. Prerequisites
kubectl get pods works.2. Python: Detect Pods Using hostNetwork: true
This script lists all pods in all namespaces that have hostNetwork enabled:3. Python: Identify Higher-Level Controllers Using hostNetwork
Usually you don’t patch pods directly; you patch Deployments/DaemonSets/StatefulSets/Jobs that create them.Example to scan Deployments and DaemonSets:4. Python: Patch Workloads to Disable hostNetwork
This will set hostNetwork: false for Deployments and DaemonSets that currently use it.- This will trigger rolling updates; pods will be recreated without host networking.
- Only run this on workloads where host networking is not required (e.g., not node-level agents).
5. Optional: Enforce No hostNetwork via Admission Control (Python + OPA Gatekeeper)
In OKE you can deploy OPA Gatekeeper or Kyverno. With Gatekeeper, you would:- Install Gatekeeper in the OKE cluster.
- Apply a ConstraintTemplate that denies
hostNetwork: true. - Apply a Constraint that targets your namespaces.
Summary
- Use the Kubernetes Python client against your OKE cluster.
- Enumerate and patch any workloads whose Pod templates have
hostNetwork: true. - Optionally deploy an admission policy (Gatekeeper or Kyverno) to prevent future
hostNetworkusage.
Using Terraform
Using Terraform
hostNetwork usage; you must remediate by updating Kubernetes manifests (Deployments, DaemonSets, Pods, Helm charts) so spec.hostNetwork is not set to true, and then re-apply via Terraform. This change does not recreate the cluster, only the affected workloads. After changes, terraform plan should show updates to the specific Kubernetes workload resources where host_network is being changed.
