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
MediumAddress
Compliance, SecurityCompliance Standards
- CIS OKE
Triage and Remediation
- Remediation
Remediation
Using Console
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.
Apply the updated deployment:Verify the pods use the correct SA:
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.
1. Open your OKE cluster from the OCI Console
- Sign in to OCI Console.
- In the left menu: Developer Services → Kubernetes Clusters (OKE).
- Select the Compartment that contains your cluster.
- 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)
-
On the top-right of the console, click the Cloud Shell icon (a
>_terminal). -
In Cloud Shell, generate kubeconfig for this OKE cluster:
-
Test access:
Option B – Download kubeconfig for local use
- In the OKE cluster details page, click Access Cluster.
-
Click Local Access and follow the instructions:
- Download the kubeconfig file.
- Set the
KUBECONFIGenvironment variable or merge into~/.kube/config.
-
Test with:
3. Create a dedicated Service Account for each workload
Repeat per application / microservice.-
Decide the namespace and SA name (for example: namespace
prod-apps, SAorders-sa). -
If the namespace doesn’t exist, create it:
-
Create a ServiceAccount YAML file in Cloud Shell (or locally), e.g.
orders-sa.yaml: -
Apply it:
4. Grant least-privilege RBAC to the Service Account
Create aRole/ClusterRole and RoleBinding/ClusterRoleBinding for each SA.Example (namespace-scoped permissions):-
Create
orders-role.yaml: -
Create
orders-rolebinding.yaml: -
Apply them:
5. Configure workloads to use the dedicated Service Account
For each Deployment/StatefulSet/Job, setserviceAccountName.Example deployment manifest snippet:6. Restrict or avoid the default Service Account
To enforce dedicated SAs:-
Remove unnecessary permissions from the namespace’s default SA:
-
Inspect bindings:
-
Remove any bindings that grant elevated rights to
defaultServiceAccounts.
-
Inspect bindings:
-
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.
Using CLI
Using CLI
Below are step‑by‑step remediation instructions to ensure OCI OKE workloads use dedicated Kubernetes service accounts (not the
Any pod with empty
Confirm:
Or edit directly:Add under The Deployment rollout will recreate pods with the new service account.
Ensure the relevant pods show
7. (Optional) Enforce policy to prevent using
If you use OPA Gatekeeper or Kyverno, deploy a policy that rejects workloads using Apply the template and a corresponding
Summary of OCI CLI involvement:
default one), starting from OCI CLI and then using kubectl.1. Get kubeconfig for your OKE cluster via OCI CLI
-
Identify your OKE cluster OCID:
-
Generate/update kubeconfig for that cluster:
-
Test connectivity:
2. Identify workloads using the default service account
Check each namespace (or target namespaces):SA or default in the SA column is using the default service account.3. Create a dedicated service account per application
Example for a namespaceprod and app my-app:4. (Optional but recommended) Bind minimal RBAC permissions
Create a minimalRole and RoleBinding for that service account.-
Create a Role manifest (file:
my-app-role.yaml): -
Apply the Role:
-
Create a RoleBinding (file:
my-app-rolebinding.yaml): -
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:spec.template.spec:6. Verify that pods are no longer using the default service account
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):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.
Using Python
Using Python
To remediate “OCI OKE Should Use Dedicated Service Accounts” you need to:
Make sure your environment can authenticate to the OKE cluster, e.g. by:The Python client will reuse this kubeconfig.
Customize
After patching, Kubernetes will roll Pods so they run with the new service account.
Ensure that no application Pods are using the
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.
- Stop using the
defaultservice account for Pods/Deployments. - Create dedicated service accounts per workload (or per trust boundary).
- Bind only the minimal RBAC permissions to each service account.
- Patch workloads to use those service accounts.
1. Prerequisites
Install the Kubernetes Python client: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
DefineRole and RoleBinding (adjust rules for what the workload actually needs):example_rules per application’s real needs.5. Patch workloads to use the dedicated service account
6. Validation
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.
Using Terraform
Using Terraform
This finding cannot be remediated on the Replace:
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:MY_CLUSTER/MY_CLUSTER_KUBECONFIGwith your actualoci_containerengine_clusterand kubeconfig data source.APP_A_NAMESPACEwith the namespace of each workload.APP_A_IMAGEwith the container image for the app.
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.
