Skip to main content

More Info:

Define NetworkPolicy resources to allow only required ingress and egress per namespace and workload. Default-deny policies prevent compromised pods from pivoting laterally to other services or the internet.

Risk Level

High

Address

Compliance, Security

Compliance Standards

  • CIS OKE

Triage and Remediation

Remediation

Using Console

To meet “OKE should use Network Policies to control traffic,” you need to:
  1. Make sure your OKE cluster supports network policies
    • In OCI Console: go to Developer Services → Kubernetes Clusters (OKE).
    • Open your cluster.
    • On the Cluster Information page, check:
      • Cluster Type must be VCN-native (pod VNIC) (network policies are not supported on “Classic” clusters).
    • If your cluster is “Classic”, you must:
      • Create a new VCN-native OKE cluster and migrate workloads (there’s no in-place conversion).
  2. Enable Network Policies on the OKE cluster (Console)
    • In the same cluster page, click Edit Details (or Update Cluster depending on UI version).
    • Look for Network Configuration / Network Policies section.
    • Enable or check:
      • Kubernetes Network Policy Enforcement (or similar wording).
    • Save the changes.
    • Wait for the cluster state to return to Active.
  3. Ensure node pools are updated
    • Within the cluster page, go to Node Pools.
    • For each node pool:
      • Check Kubernetes version and image; ensure they meet the minimum version required for network policy support (generally any recent OKE version will).
      • If needed, click Edit / Upgrade to update node pool version and image.
    • Allow node pools to complete upgrade / rolling replacement.
  4. Verify network plugin / CNI
    • On the cluster page, confirm that it uses VCN-native CNI (Pod VNICs). This is implicit for VCN-native clusters.
    • Classic Flannel-based clusters do not support network policies.
  5. Create Kubernetes NetworkPolicy objects (kubectl) This part is not done in the OCI Console UI; you use kubectl against your OKE cluster, but it’s required to actually enforce traffic rules. 5.1. Get kubeconfig from OCI Console
    • In your cluster page, click Access Cluster.
    • Follow the instructions to:
      • Download/update your kubeconfig (e.g., using the Cloud Shell or your local machine).
      • Example (Cloud Shell):
      • Then:
    5.2. Apply an initial restrictive NetworkPolicy
    • Example: default deny all ingress within a namespace:
    • Save as default-deny-ingress.yaml and apply:
    5.3. Add allow rules as needed
    • Example: allow ingress to pods labeled app: myapp only from pods labeled role: frontend:
    • Apply:
  6. Validate enforcement
    • From Cloud Shell or a test pod:
      • Confirm that denied traffic is blocked and allowed traffic works:
Summary of remediation in OCI Console:
  • Ensure cluster is VCN-native.
  • In Cluster → Edit Details, enable Network Policy enforcement.
  • Update node pools if needed.
  • Then define and apply Kubernetes NetworkPolicy resources (kubectl) to actually control pod-to-pod and namespace traffic.
In OCI Container Engine for Kubernetes (OKE), Calico network policies must be enabled at cluster creation time. You cannot turn them on for an existing cluster. So “remediation” means:
  1. Verify the current cluster’s setting
  2. Create a new OKE cluster with network policies enabled (via OCI CLI)
  3. Migrate workloads and delete the old cluster
Below are the key steps and OCI CLI examples.

1. Verify if Network Policy is Enabled on Current Cluster

If you see "isNetworkPolicyEnabled": false or null, it is not enabled and cannot be changed on this cluster.

2. Create a New OKE Cluster with Network Policies Enabled

You must use the --options / kubernetesNetworkConfig with networkPolicyConfig set to true.Prepare a JSON file, e.g. cluster-options.json:
Then run:
Check that network policies are enabled:
You should see:

3. Create Node Pool(s) for the New Cluster

Wait until the node pool is ACTIVE:

4. Point kubectl to the New Cluster


5. Deploy/Enforce Kubernetes NetworkPolicies

Network policies themselves are standard Kubernetes resources and are applied with kubectl, not OCI CLI. Example:
Then add more granular NetworkPolicy manifests to allow needed traffic.

6. Migrate Workloads and Delete Old Cluster

  1. Export and reapply manifests (or use Helm/ArgoCD/etc.) into the new cluster.
  2. Verify apps and traffic behavior under network policies.
  3. Delete old resources:

If you share your current cluster’s oci ce cluster get output (redacted), I can give you an exact cluster-options.json and CLI command tailored to your environment.
To remediate this, you need to define and apply Kubernetes NetworkPolicy resources to your OKE cluster. The Python part is about programmatically creating/applying those policies using the Kubernetes Python client.Below are the minimal practical steps.

1. Prerequisites

  1. An existing OKE cluster with:
    • Worker nodes running
    • kubectl access working from your machine
  2. kubeconfig for the OKE cluster (usually generated via OCI Console or CLI).
  3. Python packages installed:
(You only need the OCI Python SDK if you also want to automate kubeconfig generation or cluster creation.)

2. Ensure Network Policies Are Supported/Enabled in the Cluster

NetworkPolicies are a Kubernetes feature; OKE supports them when using a compatible CNI/network plugin.From the Kubernetes side, you can check quickly:
You should see:
If that’s missing, the cluster/network setup doesn’t support network policies and must be re-created or reconfigured via OCI (do that via console/OCI CLI/SDK according to Oracle docs).Assuming the resource exists, continue.

3. Python: Connect to OKE via Kubernetes Client

If your kubeconfig isn’t in the default path, pass it explicitly:

4. Define a “Default Deny” NetworkPolicy (Ingress + Egress)

This enforces that no pod in a namespace can talk to anything unless explicitly allowed by additional NetworkPolicies.Example for namespace production:
Apply it:

5. Define an Allow Policy (Example: Allow HTTP from Frontend to Backend)

Suppose:
  • All frontend pods have label: app: frontend
  • All backend pods have label: app: backend
  • You want to allow frontend → backend on port 8080 only (in namespace production).

6. (Optional) Apply Policies from YAML Using Python

If you prefer writing YAML files and applying them via Python:netpol-default-deny.yaml:
Python to apply:

7. Verification

After applying via Python:
Test connectivity (e.g., with temporary pods) to verify that only the allowed traffic flows.
If you share your specific traffic matrix (which pods/services should be allowed to talk to which), I can provide tailored Python code to generate those NetworkPolicies.
This finding cannot be fixed directly on the oci_containerengine_cluster (OKE cluster) resource: Oracle’s Terraform provider does not expose Kubernetes NetworkPolicy there. Network policies must be applied as Kubernetes resources using the kubernetes_network_policy_v1 resource against the OKE API as shown.No resource replacement of the OKE cluster is required; only in-cluster policy objects are added/updated. terraform plan should show + (create) or ~ (update) for the kubernetes_network_policy_v1 resources and no changes to oci_containerengine_cluster.