More Info:
Workloads should not run under the namespaces default ServiceAccount. Mounting tokens from the default SA to every pod blurs blast-radius and breaks per-workload least privilege.Risk Level
MediumAddress
Compliance, SecurityCompliance Standards
- CIS OKE
Triage and Remediation
- Remediation
Remediation
Using Console
Using Console
In OKE this is a Kubernetes-level issue, so you remediate it by changing service accounts and RBAC inside the cluster. You can start from the OCI Console, but the actual fix is done via
And always define explicit service accounts + RBAC for new applications.
If you share how your workloads are structured (namespaces, critical apps), I can give you concrete
kubectl (e.g., from OCI Cloud Shell).Below are the steps doing everything initiated from the OCI Console.1. Open Cloud Shell and connect to the OKE cluster
- Sign in to the OCI Console.
- Open the navigation menu → Developer Services → Kubernetes Clusters (OKE).
- Select the Compartment and click your cluster.
- On the cluster details page, click Access Cluster.
-
In the panel that opens, click Cloud Shell Access (or open Cloud Shell from the top-right “>_” icon and follow the displayed
oci ce cluster create-kubeconfigcommand). -
Run the suggested
oci ce cluster create-kubeconfigcommand in Cloud Shell, for example: -
Verify access:
2. Disable token auto-mount for the default service account
You need to patch thedefault service account in each namespace where workloads run. Commonly at least default and any custom namespaces.-
List namespaces:
-
For each relevant namespace (e.g.
default,production,staging), run:Example for the default namespace:
3. Create dedicated, least-privilege service accounts
Instead of relying on the default service account, create service accounts per application with minimal RBAC.-
Create a service account:
-
Define an RBAC role (example: read-only access to ConfigMaps in that namespace). Create a YAML file
role.yamlin Cloud Shell:Apply it: -
Bind the role to the new service account. Create
rolebinding.yaml:Apply it:
4. Update workloads to stop using the default service account
For each deployment/statefulset/daemonset, explicitly set a non-default service account and (optionally) ensure auto-mount is disabled if not needed.-
Edit the deployment (example):
-
Under
spec.template.spec, add or change: - Save and exit; Kubernetes will roll out the updated pods.
-
Verify:
5. (Optional) Enforce this pattern for new namespaces
For each new namespace you create, immediately:If you share how your workloads are structured (namespaces, critical apps), I can give you concrete
kubectl patches tailored to your setup.Using CLI
Using CLI
You can’t directly change Kubernetes service accounts with
Verify:
Optional: verify
Then delete or replace those bindings as appropriate, for example:
These steps, driven via OCI CLI → kubeconfig → kubectl, will effectively limit use and privileges of the default service account in your OKE cluster.
oci itself; you use oci to get kubeconfig, then kubectl to do the remediation on the OKE cluster.Below are the minimal CLI steps to limit default service account usage in OKE.1. Get kubeconfig for your OKE cluster (with OCI CLI)
2. Disable token automount on the default service account
Run this for each namespace where you want to restrict the default SA (includingdefault and any app namespaces):3. Ensure workloads don’t use the default SA
For each Deployment/StatefulSet/DaemonSet, patch them to either:Option A – Explicitly disable token mounting (if they don’t need K8s API access)
Option B – Use a dedicated least-privilege service account
-
Create a new service account:
-
Bind only needed permissions (example: read-only in namespace):
-
Patch the workload to use this SA:
4. (Optional) Restrict the default service account’s RBAC rights
If thedefault service account already has bindings, remove or tighten them:These steps, driven via OCI CLI → kubeconfig → kubectl, will effectively limit use and privileges of the default service account in your OKE cluster.
Using Python
Using Python
Here’s how to remediate “OCI OKE Should Limit Default Service Account Usage” using Python and the Kubernetes API.
Make sure your local
2. Disable token auto-mounting for the
This script:This makes the default service account safer (no token auto-mount), but it does not prevent workloads from explicitly specifying
3. Detect pods using the
You should also identify existing pods and controllers using the default SA so you can fix manifests (Deployments, StatefulSets, Jobs, etc.) to use dedicated service accounts.Use this output to:
Minimal remediation steps in OKE:
Goal
- Stop the
defaultServiceAccount from automatically getting tokens. - Detect workloads still using the
defaultServiceAccount so you can fix them.
1. Prerequisites
Install the Kubernetes Python client:kubectl can access the OKE cluster (e.g., via oci ce cluster create-kubeconfig ... and KUBECONFIG or ~/.kube/config).2. Disable token auto-mounting for the default ServiceAccount in all namespaces
This script:- Lists all namespaces
- Patches the
defaultServiceAccount in each namespace to setautomountServiceAccountToken: false
serviceAccountName: default or inheriting it.3. Detect pods using the default ServiceAccount
You should also identify existing pods and controllers using the default SA so you can fix manifests (Deployments, StatefulSets, Jobs, etc.) to use dedicated service accounts.- Create dedicated service accounts with minimal RBAC.
- Update Deployment/Job/StatefulSet specs to use those service accounts.
- Redeploy workloads so new pods don’t run with
default.
4. (Optional) Enforce at Namespace Level
You can also setautomountServiceAccountToken: false at the namespace level as a default:Minimal remediation steps in OKE:
- Run the script to set
automountServiceAccountToken: falseon alldefaultServiceAccounts. - Identify pods using the
defaultSA and update their controllers to use dedicated service accounts with least-privilege RBAC. - (Optional) Annotate namespaces to default to no token auto-mount.
Using Terraform
Using Terraform

