Skip to main content

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

Medium

Address

Compliance, Security

Compliance Standards

  • CIS OKE

Triage and Remediation

Remediation

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 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

  1. Sign in to the OCI Console.
  2. Open the navigation menuDeveloper ServicesKubernetes Clusters (OKE).
  3. Select the Compartment and click your cluster.
  4. On the cluster details page, click Access Cluster.
  5. 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-kubeconfig command).
  6. Run the suggested oci ce cluster create-kubeconfig command in Cloud Shell, for example:
  7. Verify access:

2. Disable token auto-mount for the default service account

You need to patch the default service account in each namespace where workloads run. Commonly at least default and any custom namespaces.
  1. List namespaces:
  2. For each relevant namespace (e.g. default, production, staging), run:
    Example for the default namespace:
This prevents pods in that namespace from automatically mounting the default token unless explicitly overridden.

3. Create dedicated, least-privilege service accounts

Instead of relying on the default service account, create service accounts per application with minimal RBAC.
  1. Create a service account:
  2. Define an RBAC role (example: read-only access to ConfigMaps in that namespace). Create a YAML file role.yaml in Cloud Shell:
    Apply it:
  3. 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.
  1. Edit the deployment (example):
  2. Under spec.template.spec, add or change:
  3. Save and exit; Kubernetes will roll out the updated pods.
  4. Verify:

5. (Optional) Enforce this pattern for new namespaces

For each new namespace you create, immediately:
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 patches tailored to your setup.
You can’t directly change Kubernetes service accounts with 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)

Verify:

2. Disable token automount on the default service account

Run this for each namespace where you want to restrict the default SA (including default and any app namespaces):
Optional: verify

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

  1. Create a new service account:
  2. Bind only needed permissions (example: read-only in namespace):
  3. Patch the workload to use this SA:

4. (Optional) Restrict the default service account’s RBAC rights

If the default service account already has bindings, remove or tighten them:
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.
Here’s how to remediate “OCI OKE Should Limit Default Service Account Usage” using Python and the Kubernetes API.

Goal

  1. Stop the default ServiceAccount from automatically getting tokens.
  2. Detect workloads still using the default ServiceAccount so you can fix them.

1. Prerequisites

Install the Kubernetes Python client:
Make sure your local 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 default ServiceAccount in each namespace to set automountServiceAccountToken: false
This makes the default service account safer (no token auto-mount), but it does not prevent workloads from explicitly specifying 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.
Use this output to:
  • 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 set automountServiceAccountToken: false at the namespace level as a default:

Minimal remediation steps in OKE:
  1. Run the script to set automountServiceAccountToken: false on all default ServiceAccounts.
  2. Identify pods using the default SA and update their controllers to use dedicated service accounts with least-privilege RBAC.
  3. (Optional) Annotate namespaces to default to no token auto-mount.