More Info:
Roles that allow get, list, or watch on secrets effectively expose every credential they reference. Limit secret access to controllers and service accounts that strictly need it and audit changes to those bindings.Risk Level
HighAddress
Compliance, SecurityCompliance Standards
- CIS OKE
Triage and Remediation
- Remediation
Remediation
Using Console
Using Console
Below are concrete, console-based steps to restrict access to OCI Vault secrets for OKE (Oracle Kubernetes Engine).Assumptions:
Write down:
If you want to restrict to a single vault only (where conditions supported):If only some users need to manage secrets (not all devs):
If you can share the current policy text you’re using for OKE to read secrets, I can give you an exact minimal replacement policy statement.
- OKE worker nodes use Dynamic Groups + IAM policies to access Vault.
- The misconfiguration is that these policies are too broad (e.g.,
read secret-bundleson entire compartment/tenancy).
1. Identify who currently has access to secrets
- Sign in to OCI Console.
- Open the navigation menu → Identity & Security → Policies.
- In the Compartment dropdown, select the compartment where your OKE policies live.
- Find policies that contain actions like:
read secret-bundlesmanage secret-familymanage vaultsorread vaults
- Look for statements that reference:
dynamic-group <your-oke-nodes-dg>- or groups used by your platform/team for OKE access.
- The dynamic group names (e.g.,
oke-nodes). - The compartments and vaults they can access.
2. Confirm which dynamic groups are tied to your OKE clusters
- Go to Identity & Security → Dynamic Groups.
- Open each suspected dynamic group (e.g.,
oke-nodes). - Check Matching Rules:
- Typical OKE node rule looks like:
or:
- Typical OKE node rule looks like:
- Confirm these are indeed the worker node instances (used by your OKE node pools).
3. Scope Vault access to the smallest necessary compartment/vault
If workers currently have wide access (e.g., whole compartment), narrow that scope.A. Optionally move secrets into a dedicated “app-secrets” compartment
- Navigation menu → Identity & Security → Compartments.
- Create a new compartment (e.g.,
app-secrets). - Go to Security → Vault → select your Vault.
- For each secret that should be tightly controlled:
- Click the secret → Move Resource (if available) → move it into
app-secrets. - If “Move” is not available, create a new secret in
app-secretsand start using that in your apps, then delete the old one when no longer needed.
- Click the secret → Move Resource (if available) → move it into
app-secrets.4. Replace broad IAM policies with least-privilege ones
A. Edit or create a new policy with narrow permissions
- Go to Identity & Security → Policies.
-
Either:
- Edit the existing broad policy (preferred), or
- Create a new policy (e.g.,
oke-app-secrets-policy) in the root or relevant parent compartment.
- Use narrow statements such as:
- Remove or comment out (delete) existing overly broad rules, for example:
Allow dynamic-group oke-nodes to read secret-bundles in tenancyAllow group devs to manage secret-family in tenancyAllow dynamic-group oke-nodes to manage vaults in tenancy
5. Restrict who can manage Vaults and Keys
- Go to Security → Vault.
- For each vault:
- Note its compartment.
- Return to Identity & Security → Policies and ensure:
- Only a small admin group (e.g.,
security-admins) can manage vaults and keys: - Regular users or OKE node dynamic groups should not have
manage vaultsormanage keys.
- Only a small admin group (e.g.,
6. Validate OKE access from a sample pod
- Apply a simple test pod/deployment in the OKE cluster that uses the OCI SDK or Secrets Store CSI Driver to read a specific secret.
- Ensure:
- The pod can only read the secrets it is supposed to.
- Attempts to read secrets outside
app-secrets(or outside allowed vault) fail withNotAuthorizedOrNotFound.
7. Ongoing hardening
- Keep secrets in a separate secrets-only compartment per application or environment.
- Avoid
manage secret-familyfor dynamic groups; usually they only needread secret-bundles. - Periodically review:
- Policies under Identity & Security.
- Dynamic Groups associated with OKE nodes.
- Audit logs (Identity & Security → Audit) for who is reading secrets.
If you can share the current policy text you’re using for OKE to read secrets, I can give you an exact minimal replacement policy statement.
Using CLI
Using CLI
Below is a practical, CLI-focused way to tighten access to OCI Vault secrets and Kubernetes Secrets in OKE.
Inspect each:You’re looking for rules like:That’s likely your OKE worker node dynamic group.
For each policy:Look for broad statements involving These are what you will tighten.
Replace with:Update with CLI:Or per vault:You still use the same
Change Update via the same
Now
Find any with Look for things like:Especially on
If it is not needed, delete:Or rebind it only to specific service account(s):
Prefer specific secret keys instead of whole-secret or whole-namespace access.
1. Restrict OCI Vault Secret Access for OKE Nodes
1.1. Identify dynamic groups used by OKE
OKE worker nodes usually belong to a dynamic group. List dynamic groups:1.2. List policies that grant vault/secret access
List policies (tenant‑wide or per compartment):secret-bundles or vaults, e.g.:1.3. Replace broad policies with least‑privilege ones
a) Narrow to specific compartment
If currently:- Get existing statements into a JSON file:
-
Edit
statements.jsonlocally:- Remove overly broad lines
- Add the narrowed lines you want.
- Update the policy:
b) Limit to specific vault or secret (optional, more strict)
Use a policy with conditions (if you want only specific secret(s)):Example (per secret):oci iam policy update procedure, but with the conditioned statements.1.4. Remove unneeded manage permissions
If you see:manage to read for worker nodes:statements.json + oci iam policy update method.2. Restrict Kubernetes Secret Access Inside OKE
OCI CLI is used to configure kubeconfig, thenkubectl enforces RBAC.2.1. Get kubeconfig via OCI CLI
kubectl uses that config.2.2. Audit who can read secrets
List ClusterRoles and RoleBindings:secrets and broad verbs:system:authenticated, system:serviceaccounts, etc.2.3. Remove or tighten overly broad bindings
Example: if a ClusterRoleBinding gives all service accounts cluster‑wide access to secrets:- Create a YAML file (e.g.
restricted-sa-binding.yaml):
- Apply:
- Remove any old RoleBindings/ClusterRoleBindings that granted wider access than necessary.
2.4. Avoid mounting all secrets as environment variables
Check Deployments:3. Summary of CLI Commands Used
- IAM / Vault via OCI CLI:
oci iam dynamic-group list/getoci iam policy list/get/update
- OKE / Kubernetes:
oci ce cluster create-kubeconfig- Then
kubectlfor RBAC and secret usage.
statements.json you can paste into oci iam policy update.Using Python
Using Python
Below is a practical, step‑by‑step way to restrict access to Kubernetes Secrets in OCI OKE using Python.
This focuses on tightening Kubernetes RBAC (what workloads and users can
Use this to identify overly permissive roles (e.g.,
Now only
Be careful: do this only after verifying no critical workloads rely on that access.
You can apply this YAML via Python using the Kubernetes client if desired, but usually
Then your pod uses this method instead of relying on Kubernetes Secret objects.
If you share your current RBAC definitions (or an example of a failing security check), I can give a concrete Python script tailored to that configuration.
This focuses on tightening Kubernetes RBAC (what workloads and users can
get/list/watch secrets).1. Prerequisites
- An OKE cluster is already created.
kubeconfigfor the cluster is available (e.g.~/.kube/config).- Python packages installed:
- Your local environment can talk to the OKE API (e.g.,
kubectl get podsworks).
2. Principle: Least-Privilege RBAC on Secrets
You want:- Only specific service accounts / users / groups to:
get,list,watch,create,update,deleteSecrets.
- All others should have no secret permissions (or only what is strictly required).
- Auditing current bindings.
- Creating minimal
Role/ClusterRoledefinitions. - Adjusting
RoleBinding/ClusterRoleBindingobjects via Python.
3. Configure Kubernetes Python Client
4. Audit Current Secret Access
List allClusterRoles and Roles that touch secrets:* verbs on secrets, or broad ClusterRole bindings).5. Create a Least‑Privilege Role for Secrets (Namespace Scoped)
Example: allow only a specific service account to read secrets in namespaceprod.5.1 Create Role
5.2 Bind Role to a Service Account
app-sa in prod has get/list for secrets in that namespace.6. Remove / Restrict Broad Secret Permissions
Typical bad pattern:ClusterRoleBinding to system:authenticated or system:serviceaccounts with a role that grants secrets access.- Identify dangerous bindings:
- Inspect the
ClusterRolethey refer to. If it hassecretspermissions and is too broad, either:- Create new, narrower
ClusterRoles and rebind. - Or patch/remove the binding if not needed.
- Create new, narrower
Example: Patch a ClusterRole to Remove Secrets Access
7. Use Dedicated Service Accounts per App
For each deployment needing secret access:- Create a dedicated service account.
- Bind only the minimal secret permissions to that SA.
app-sa:kubectl apply -f is simpler.8. (Optional) Move Sensitive Data to OCI Vault and Narrow Access
For especially sensitive secrets:- Store them in OCI Vault (KMS).
- Grant only needed OKE node pool instances / dynamic groups permissions to read those secrets via IAM policies.
- App accesses Vault with the OCI SDK from inside the pod instead of Kubernetes Secrets.
9. Verification
- Attempt to list secrets with a service account or user that should not have access; verify it fails:
- Verify permitted SA works:
If you share your current RBAC definitions (or an example of a failing security check), I can give a concrete Python script tailored to that configuration.
Using Terraform
Using Terraform
oci_containerengine_cluster itself; it only adds/updates Kubernetes RBAC objects on the existing OKE cluster.To verify, terraform plan should show the kubernetes_cluster_role, kubernetes_cluster_role_binding, and (if used) kubernetes_role/kubernetes_role_binding being created or updated, with no destroy/replace on oci_containerengine_cluster.OKE_CLUSTER.
