Skip to main content

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

High

Address

Compliance, Security

Compliance Standards

  • CIS OKE

Triage and Remediation

Remediation

Using Console

To remediate “OCI OKE should minimize containers sharing the host network namespace” using the OCI Console, you need to:
  1. Identify workloads using hostNetwork
  1. Sign in to the OCI Console.
  2. In the left menu, go to Developer Services → Containers & Artifacts → Kubernetes Clusters (OKE).
  3. Click your cluster.
  4. In the cluster detail page, click Workloads.
  5. 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 ports for hostPort values (often appear with hostNetwork).
Any workload with hostNetwork: true is sharing the host network namespace.
  1. Edit workloads to stop using the host network
For each offending workload you found:
  1. In Workloads, click the workload (e.g., a Deployment).
  2. Click Edit YAML.
  3. In the pod spec, change or remove:
    to either:
    or remove the hostNetwork line entirely (default is false).
  4. If possible, also remove any hostPort mappings under containers:
  5. Click Save / Update to apply the changes.
  6. The Deployment/StatefulSet/DaemonSet will roll out new pods without hostNetwork.
Repeat for all workloads using hostNetwork: true.
  1. (Optional but recommended) Enforce a policy to prevent future use
OKE does not yet provide a native “checkbox” to forbid hostNetwork, but you can enforce via Kubernetes policy tools (e.g., Gatekeeper/OPA) deployed to your cluster. From the OCI Console you:
  1. Go to your OKE clusterAccess Cluster → use the Cloud Shell or local kubectl.
  2. Deploy an admission policy that denies pods with spec.hostNetwork: true.
Example Gatekeeper 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.)
  1. Verify remediation
  1. In the Workloads view, re-open the YAML for each previously offending workload.
  2. Confirm:
    • hostNetwork is not present, or explicitly set to false.
    • hostPort is removed where not necessary.
  3. 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.
This removes container sharing of the host network namespace for your OKE workloads via changes made through the OCI Console.
In OKE this setting is controlled in the Pod spec (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

If you want to find the owning controllers (Deployments/DaemonSets/StatefulSets):

3. Update the owning resources to stop using host networking

For each Deployment/DaemonSet/StatefulSet that uses hostNetwork: true, remove or set it to false.Example – patch a Deployment:
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 (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 a PodSecurity 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.
In OKE this is a standard Kubernetes setting: containers use the host network when the Pod spec has hostNetwork: true. To “minimize” it, you must:
  1. Find workloads using hostNetwork: true.
  2. Update their specs to hostNetwork: false (or remove the field).
  3. Optionally enforce a policy so it can’t be reintroduced.
Below is how to do this programmatically in Python using the Kubernetes Python client against your OKE cluster.

1. Prerequisites

Make sure your kubeconfig for the OKE cluster is set (e.g. created via OCI CLI) and that 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.
Notes:
  • 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:
  1. Install Gatekeeper in the OKE cluster.
  2. Apply a ConstraintTemplate that denies hostNetwork: true.
  3. Apply a Constraint that targets your namespaces.
The actual Gatekeeper policy is YAML, but you can apply it via Python:
(Adjust namespaces and ensure Gatekeeper is already installed.)

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 hostNetwork usage.
The OCI OKE “cluster” resource cannot enforce 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.