More Info:
Public Kubernetes API endpoints are continuously scanned and brute forced. Restrict the API server to private endpoints reachable only via VCN, bastions or Service Gateway to dramatically reduce attack surface.Risk Level
CriticalAddress
Compliance, SecurityCompliance Standards
- CIS OKE
Triage and Remediation
- Remediation
Remediation
Using Console
Using Console
Below are the steps to disable the public Kubernetes API endpoint for an OCI OKE cluster using the OCI Console, and move it to a private endpoint only.
Note: Some older / “Basic” clusters or early-generation clusters may not support changing endpoint type in-place. In that case, you must recreate the cluster with a private-only endpoint. I’ll include both paths.
1. Prerequisites
Before disabling the public endpoint, make sure:- You have VCN connectivity from your admin environment (bastion host / VPN / FastConnect / OCI Cloud Shell) to the private subnet where the API will reside.
- You have or will create a private subnet in your VCN for the Kubernetes API endpoint.
- You have required IAM permissions to manage OKE clusters and networking.
2. Check if Your Cluster Allows Editing the Endpoint
- In the OCI Console, go to:
- Main menu → Developer Services → Kubernetes Clusters (OKE).
- Select your Compartment.
- Click your Cluster name.
- On the Cluster details page:
- Look for a button like Edit Kubernetes API endpoint, Update cluster, or similar under More actions.
- If you see an option to change the Kubernetes API endpoint access, you can modify it in place.
- If not, you will need to create a new cluster (see Section 4).
3. Change an Existing Cluster to Private Endpoint Only
3.1 Prepare a Private Subnet (if not existing)
- Go to Networking → Virtual Cloud Networks.
- Select the VCN used by your OKE cluster.
- Under Subnets, create a new private subnet (if you don’t already have one suitable):
- Subnet type: Regional
- Private subnet: Enabled (no public IPs)
- Add appropriate route table and security lists/NSGs so your admins can reach it.
3.2 Edit the Cluster Endpoint
- Go to Kubernetes Clusters (OKE).
- Select the Compartment and click your Cluster.
- On the Cluster details page, click:
- More actions → Edit cluster or
- Edit Kubernetes API endpoint (wording can differ slightly by region / console version).
- In the Kubernetes API endpoint access section:
- Change to Private endpoint only (or uncheck “Public endpoint” if both are enabled).
- Select the VCN and Private Subnet for the API endpoint.
- (Optional) Attach Network Security Groups restricting which IPs / subnets can reach the endpoint.
- Click Save changes / Update.
3.3 Update Your kubeconfig / Access Method
Once the endpoint is private-only:- From a host that has network access to the private subnet (bastion, over VPN, etc.), run:
- In OCI Console → Cluster details → Access Cluster → copy and run the
oci ce cluster create-kubeconfigcommand.
- In OCI Console → Cluster details → Access Cluster → copy and run the
- Confirm:
kubectl get nodesworks from a network path that reaches the private subnet.- Access from the internet without VPN/bastion should no longer be possible.
4. If You Cannot Edit the Endpoint (Recreate Cluster as Private-Only)
If the cluster does not allow editing the endpoint:4.1 Create a New OKE Cluster with Private-Only API Endpoint
- Go to Kubernetes Clusters (OKE) → Create cluster.
- Choose Quick create or Custom create (Custom recommended for control).
- In the Kubernetes API endpoint access section:
- Select Private endpoint (or deselect public so only private is enabled).
- Choose the VCN and appropriate private subnet for the API endpoint.
- Complete other cluster settings (version, node pools, shapes, etc.).
- Create the cluster and wait until its status is Active.
4.2 Migrate Workloads
- Export current workloads from the old cluster (e.g.,
kubectl get all -A -o yamlor your manifests/Helm charts). - Configure kubeconfig for the new cluster (via Access Cluster in cluster details).
- Apply manifests / reinstall Helm charts on the new cluster.
- Test workloads, ingress, services, and networking.
- Decommission the old cluster:
- Drain and delete node pools.
- Delete the old OKE cluster.
5. Validate That the Public Endpoint Is Disabled
- On Cluster details, confirm:
- API Endpoint shows only a private IP / private FQDN.
- No public endpoint is listed.
- From the public internet (without VPN/bastion), verify:
kubectlcannot reach the cluster.- Any previous public FQDN or IP is no longer responsive.
Using CLI
Using CLI
To disable the public Kubernetes API endpoint for an existing OKE cluster using OCI CLI, you update the cluster’s
Note the current
2. Build the new
You want the same subnet and NSGs, but with If you are not using NSGs, omit the
This updates the control plane endpoint to private only in the specified subnet.
Ensure:
endpoint-config and set isPublicIpEnabled to false.Prereqs- OCI CLI installed and configured (
oci setup config) - OCID of the OKE cluster
- OCID of the subnet where the private endpoint will live (usually a private subnet in the same VCN)
1. Get the current cluster configuration (optional but recommended)
endpoint-config values (especially subnetId and any nsgIds).2. Build the new endpoint-config JSON
You want the same subnet and NSGs, but with isPublicIpEnabled set to false.Example (adjust OCIDs and NSGs as needed):nsgIds array:3. Update the cluster to disable the public endpoint
4. Verify the change
5. Update your access method
Once public access is disabled, you must:- Access the API from within the VCN (e.g., bastion host, VPN, FastConnect, VCN peering), and
- Regenerate or update your kubeconfig as needed:
Using Python
Using Python
To remediate “OCI OKE Kubernetes API Public Endpoint Should Be Disabled” using Python, you need to update the OKE cluster’s endpoint configuration so that
isPublicIpEnabled is set to False.Below are the minimal practical steps and a working Python example using the OCI Python SDK.1. Prerequisites
-
Install OCI Python SDK (if not already):
-
Ensure you have:
- A working OCI CLI/config file (typically at
~/.oci/config) with a profile that has permissions to update OKE clusters. - The OCID of the OKE cluster you want to remediate.
- A private subnet OCID for the OKE endpoint (if your cluster is not already using a suitable subnet).
- This subnet must:
- Be in the same VCN/region as the cluster.
- Have appropriate route tables and security lists/NSGs to allow access from your admin nodes/jump hosts.
- This subnet must:
- A working OCI CLI/config file (typically at
2. Core Python Script to Disable Public Endpoint
3. High-Level Step-by-Step
- Identify the OKE cluster: Get its OCID from the console or CLI.
- Select/prepare a private subnet in the same VCN/region for the Kubernetes API endpoint.
- Configure OCI Python SDK:
- Ensure
~/.oci/configexists and the profile hasContainerEnginepermissions (e.g.,MANAGE CLUSTER).
- Ensure
- Run the Python script:
- It:
- Fetches the cluster.
- Sets
endpoint_config.subnet_idto your private subnet. - Sets
endpoint_config.is_public_ip_enabled = False. - Calls
update_cluster.
- It:
- Verify:
- In the OCI Console → Developer Services → Kubernetes Clusters → your cluster:
- Confirm the API endpoint is now private-only (no public IP).
- In the OCI Console → Developer Services → Kubernetes Clusters → your cluster:
Using Terraform
Using Terraform
terraform plan should show endpoint_config.is_public_ip_enabled changing from true to false on oci_containerengine_cluster.oke_cluster and no -/+ replacement indicator for the resource.
