Skip to main content

More Info:

Each workload should run under a dedicated ServiceAccount with the minimum role bindings it needs, instead of sharing accounts across apps. This makes per-workload audit and revocation tractable.

Risk Level

Medium

Address

Compliance, Security

Compliance Standards

  • CIS OKE

Triage and Remediation

Remediation

Using Console

In OKE this is a Kubernetes-level fix, but you can drive it from the OCI Console (using Cloud Shell or downloaded kubeconfig). Below are the steps using the OCI Console.

1. Open your OKE cluster from the OCI Console

  1. Sign in to OCI Console.
  2. In the left menu: Developer Services → Kubernetes Clusters (OKE).
  3. Select the Compartment that contains your cluster.
  4. Click your cluster name.

2. Get access to the cluster (from the Console)

You have two easy options:

Option A – Use OCI Cloud Shell (no local setup)

  1. On the top-right of the console, click the Cloud Shell icon (a >_ terminal).
  2. In Cloud Shell, generate kubeconfig for this OKE cluster:
  3. Test access:

Option B – Download kubeconfig for local use

  1. In the OKE cluster details page, click Access Cluster.
  2. Click Local Access and follow the instructions:
    • Download the kubeconfig file.
    • Set the KUBECONFIG environment variable or merge into ~/.kube/config.
  3. Test with:

3. Create a dedicated Service Account for each workload

Repeat per application / microservice.
  1. Decide the namespace and SA name (for example: namespace prod-apps, SA orders-sa).
  2. If the namespace doesn’t exist, create it:
  3. Create a ServiceAccount YAML file in Cloud Shell (or locally), e.g. orders-sa.yaml:
  4. Apply it:

4. Grant least-privilege RBAC to the Service Account

Create a Role/ClusterRole and RoleBinding/ClusterRoleBinding for each SA.Example (namespace-scoped permissions):
  1. Create orders-role.yaml:
  2. Create orders-rolebinding.yaml:
  3. Apply them:

5. Configure workloads to use the dedicated Service Account

For each Deployment/StatefulSet/Job, set serviceAccountName.Example deployment manifest snippet:
Apply the updated deployment:
Verify the pods use the correct SA:

6. Restrict or avoid the default Service Account

To enforce dedicated SAs:
  1. Remove unnecessary permissions from the namespace’s default SA:
    • Inspect bindings:
    • Remove any bindings that grant elevated rights to default ServiceAccounts.
  2. Optionally, use an admission controller (e.g., OPA Gatekeeper or Kyverno) to deny pods that don’t specify serviceAccountName.
    This is configured inside the cluster, but can also be applied using manifests via Cloud Shell from the OCI Console.

If you share how your workloads are currently defined (Deployment YAML or Helm chart), I can give you the exact edits needed to switch them to dedicated Service Accounts.
Below are step‑by‑step remediation instructions to ensure OCI OKE workloads use dedicated Kubernetes service accounts (not the default one), starting from OCI CLI and then using kubectl.

1. Get kubeconfig for your OKE cluster via OCI CLI

  1. Identify your OKE cluster OCID:
  2. Generate/update kubeconfig for that cluster:
  3. Test connectivity:

2. Identify workloads using the default service account

Check each namespace (or target namespaces):
Any pod with empty SA or default in the SA column is using the default service account.

3. Create a dedicated service account per application

Example for a namespace prod and app my-app:
Confirm:

Create a minimal Role and RoleBinding for that service account.
  1. Create a Role manifest (file: my-app-role.yaml):
  2. Apply the Role:
  3. Create a RoleBinding (file: my-app-rolebinding.yaml):
  4. Apply the RoleBinding:

5. Update workloads to use the dedicated service account

Edit each Deployment/StatefulSet/Job/etc. so the pod spec uses your new service account.Example patch for a Deployment:
Or edit directly:
Add under spec.template.spec:
The Deployment rollout will recreate pods with the new service account.

6. Verify that pods are no longer using the default service account

Ensure the relevant pods show my-app-sa (or another dedicated SA), not default.

7. (Optional) Enforce policy to prevent using default SA

If you use OPA Gatekeeper or Kyverno, deploy a policy that rejects workloads using default service accounts. Example (Gatekeeper ConstraintTemplate snippet-style):
Apply the template and a corresponding Constraint to enforce it across namespaces.
Summary of OCI CLI involvement:
  • Use OCI CLI to get kubeconfig for the OKE cluster.
  • Perform the Kubernetes changes (kubectl) to create dedicated service accounts, bind RBAC, and update workloads.
To remediate “OCI OKE Should Use Dedicated Service Accounts” you need to:
  1. Stop using the default service account for Pods/Deployments.
  2. Create dedicated service accounts per workload (or per trust boundary).
  3. Bind only the minimal RBAC permissions to each service account.
  4. Patch workloads to use those service accounts.
Below is a step‑by‑step guide and Python examples using the Kubernetes Python client.

1. Prerequisites

Install the Kubernetes Python client:
Make sure your environment can authenticate to the OKE cluster, e.g. by:
The Python client will reuse this kubeconfig.

2. Detect workloads using the default service account


3. Create a dedicated service account (per workload or per app)

Example: one dedicated service account per deployment:

4. Bind minimal RBAC permissions to the service account

Define Role and RoleBinding (adjust rules for what the workload actually needs):
Customize example_rules per application’s real needs.

5. Patch workloads to use the dedicated service account

After patching, Kubernetes will roll Pods so they run with the new service account.

6. Validation

Ensure that no application Pods are using the default service account (except where strictly intended, and ideally never in production namespaces).
This approach is generic for any OKE cluster, since OKE exposes a standard Kubernetes API; the Python code above can be run from any environment that has network access to the cluster and valid kubeconfig.
This finding cannot be remediated on the oci_containerengine_cluster (OKE cluster) Terraform resource, because Kubernetes ServiceAccounts are workload-level objects inside the cluster, not an OCI cluster setting.To fix it in Terraform you must manage the workloads themselves (via the Kubernetes provider or Helm), and for each workload define and reference its own ServiceAccount, for example:
Replace:
  • MY_CLUSTER / MY_CLUSTER_KUBECONFIG with your actual oci_containerengine_cluster and kubeconfig data source.
  • APP_A_NAMESPACE with the namespace of each workload.
  • APP_A_IMAGE with the container image for the app.
No resource replacement of the OKE cluster is required; only workloads and their RBAC objects are created/updated.Verification: terraform plan should show new kubernetes_service_account, kubernetes_role, kubernetes_role_binding, and updated workload specs (e.g., Deployment) using service_account_name per workload, with no changes to oci_containerengine_cluster.