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
HighAddress
Compliance, SecurityCompliance Standards
- CIS OKE
Triage and Remediation
- Remediation
Remediation
Using Console
Using Console
To meet “OKE should use Network Policies to control traffic,” you need to:
-
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).
-
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.
-
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.
-
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.
-
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:
- Example: default deny all ingress within a namespace:
- Save as
default-deny-ingress.yamland apply:
- Example: allow ingress to pods labeled
app: myapponly from pods labeledrole: frontend: - Apply:
-
Validate enforcement
- From Cloud Shell or a test pod:
- Confirm that denied traffic is blocked and allowed traffic works:
- Confirm that denied traffic is blocked and allowed traffic works:
- From Cloud Shell or a test pod:
- 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.
Using CLI
Using CLI
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:
If you see
Then run:Check that network policies are enabled:You should see:
Wait until the node pool is
Then add more granular
If you share your current cluster’s
- Verify the current cluster’s setting
- Create a new OKE cluster with network policies enabled (via OCI CLI)
- Migrate workloads and delete the old cluster
1. Verify if Network Policy is Enabled on Current Cluster
"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:3. Create Node Pool(s) for the New Cluster
ACTIVE:4. Point kubectl to the New Cluster
5. Deploy/Enforce Kubernetes NetworkPolicies
Network policies themselves are standard Kubernetes resources and are applied withkubectl, not OCI CLI. Example:NetworkPolicy manifests to allow needed traffic.6. Migrate Workloads and Delete Old Cluster
- Export and reapply manifests (or use Helm/ArgoCD/etc.) into the new cluster.
- Verify apps and traffic behavior under network policies.
- 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.Using Python
Using Python
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.
(You only need the OCI Python SDK if you also want to automate kubeconfig generation or cluster creation.)
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.
If your kubeconfig isn’t in the default path, pass it explicitly:
Apply it:
Python to apply:
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.
1. Prerequisites
- An existing OKE cluster with:
- Worker nodes running
kubectlaccess working from your machine
kubeconfigfor the OKE cluster (usually generated via OCI Console or CLI).- Python packages installed:
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:3. Python: Connect to OKE via Kubernetes Client
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 namespaceproduction: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:7. Verification
After applying via Python: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.
Using Terraform
Using Terraform
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.
