Skip to main content

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

High

Address

Compliance, Security

Compliance Standards

  • CIS OKE

Triage and Remediation

Remediation

Using Console

Below are concrete, console-based steps to restrict access to OCI Vault secrets for OKE (Oracle Kubernetes Engine).Assumptions:
  • OKE worker nodes use Dynamic Groups + IAM policies to access Vault.
  • The misconfiguration is that these policies are too broad (e.g., read secret-bundles on entire compartment/tenancy).

1. Identify who currently has access to secrets

  1. Sign in to OCI Console.
  2. Open the navigation menu → Identity & SecurityPolicies.
  3. In the Compartment dropdown, select the compartment where your OKE policies live.
  4. Find policies that contain actions like:
    • read secret-bundles
    • manage secret-family
    • manage vaults or read vaults
  5. Look for statements that reference:
    • dynamic-group <your-oke-nodes-dg>
    • or groups used by your platform/team for OKE access.
Examples of risky policies:
Write down:
  • 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

  1. Go to Identity & SecurityDynamic Groups.
  2. Open each suspected dynamic group (e.g., oke-nodes).
  3. Check Matching Rules:
    • Typical OKE node rule looks like:
      or:
  4. 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

  1. Navigation menu → Identity & SecurityCompartments.
  2. Create a new compartment (e.g., app-secrets).
  3. Go to SecurityVault → select your Vault.
  4. 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-secrets and start using that in your apps, then delete the old one when no longer needed.
This allows you to apply stricter policies only on app-secrets.

4. Replace broad IAM policies with least-privilege ones

A. Edit or create a new policy with narrow permissions

  1. Go to Identity & SecurityPolicies.
  2. 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.
  3. Use narrow statements such as:
Only allow OKE nodes to read secrets in one compartment:
If you want to restrict to a single vault only (where conditions supported):
If only some users need to manage secrets (not all devs):
  1. Remove or comment out (delete) existing overly broad rules, for example:
    • Allow dynamic-group oke-nodes to read secret-bundles in tenancy
    • Allow group devs to manage secret-family in tenancy
    • Allow dynamic-group oke-nodes to manage vaults in tenancy
Save the policy.

5. Restrict who can manage Vaults and Keys

  1. Go to SecurityVault.
  2. For each vault:
    • Note its compartment.
  3. Return to Identity & SecurityPolicies 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 vaults or manage keys.

6. Validate OKE access from a sample pod

  1. 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.
  2. Ensure:
    • The pod can only read the secrets it is supposed to.
    • Attempts to read secrets outside app-secrets (or outside allowed vault) fail with NotAuthorizedOrNotFound.
If unauthorized access still works, revisit which policies grant access and further tighten them.

7. Ongoing hardening

  • Keep secrets in a separate secrets-only compartment per application or environment.
  • Avoid manage secret-family for dynamic groups; usually they only need read 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.
Below is a practical, CLI-focused way to tighten access to OCI Vault secrets and Kubernetes Secrets in OKE.

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:
Inspect each:
You’re looking for rules like:
That’s likely your OKE worker node dynamic group.

1.2. List policies that grant vault/secret access

List policies (tenant‑wide or per compartment):
For each policy:
Look for broad statements involving secret-bundles or vaults, e.g.:
These are what you will tighten.

1.3. Replace broad policies with least‑privilege ones

a) Narrow to specific compartment

If currently:
Replace with:
Update with CLI:
  1. Get existing statements into a JSON file:
  1. Edit statements.json locally:
    • Remove overly broad lines
    • Add the narrowed lines you want.
  2. 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):
Or per vault:
You still use the same oci iam policy update procedure, but with the conditioned statements.

1.4. Remove unneeded manage permissions

If you see:
Change manage to read for worker nodes:
Update via the same statements.json + oci iam policy update method.

2. Restrict Kubernetes Secret Access Inside OKE

OCI CLI is used to configure kubeconfig, then kubectl enforces RBAC.

2.1. Get kubeconfig via OCI CLI

Now kubectl uses that config.

2.2. Audit who can read secrets

List ClusterRoles and RoleBindings:
Find any with secrets and broad verbs:
Look for things like:
Especially on 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:
If it is not needed, delete:
Or rebind it only to specific service account(s):
  1. Create a YAML file (e.g. restricted-sa-binding.yaml):
  1. Apply:
  1. Remove any old RoleBindings/ClusterRoleBindings that granted wider access than necessary.

2.4. Avoid mounting all secrets as environment variables

Check Deployments:
Prefer specific secret keys instead of whole-secret or whole-namespace access.

3. Summary of CLI Commands Used

  • IAM / Vault via OCI CLI:
    • oci iam dynamic-group list/get
    • oci iam policy list/get/update
  • OKE / Kubernetes:
    • oci ce cluster create-kubeconfig
    • Then kubectl for RBAC and secret usage.
If you share an example of your current IAM policy and dynamic group for OKE, I can give you an exact statements.json you can paste into oci iam policy update.
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 get/list/watch secrets).

1. Prerequisites

  1. An OKE cluster is already created.
  2. kubeconfig for the cluster is available (e.g. ~/.kube/config).
  3. Python packages installed:
  4. Your local environment can talk to the OKE API (e.g., kubectl get pods works).

2. Principle: Least-Privilege RBAC on Secrets

You want:
  • Only specific service accounts / users / groups to:
    • get, list, watch, create, update, delete Secrets.
  • All others should have no secret permissions (or only what is strictly required).
We’ll do this by:
  1. Auditing current bindings.
  2. Creating minimal Role / ClusterRole definitions.
  3. Adjusting RoleBinding / ClusterRoleBinding objects via Python.

3. Configure Kubernetes Python Client


4. Audit Current Secret Access

List all ClusterRoles and Roles that touch secrets:
Use this to identify overly permissive roles (e.g., * 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 namespace prod.

5.1 Create Role

5.2 Bind Role to a Service Account

Now only 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.
  1. Identify dangerous bindings:
  1. Inspect the ClusterRole they refer to. If it has secrets permissions and is too broad, either:
    • Create new, narrower ClusterRoles and rebind.
    • Or patch/remove the binding if not needed.

Example: Patch a ClusterRole to Remove Secrets Access

Be careful: do this only after verifying no critical workloads rely on that access.

7. Use Dedicated Service Accounts per App

For each deployment needing secret access:
  1. Create a dedicated service account.
  2. Bind only the minimal secret permissions to that SA.
Example: ensure a Deployment uses the app-sa:
You can apply this YAML via Python using the Kubernetes client if desired, but usually kubectl apply -f is simpler.

8. (Optional) Move Sensitive Data to OCI Vault and Narrow Access

For especially sensitive secrets:
  1. Store them in OCI Vault (KMS).
  2. Grant only needed OKE node pool instances / dynamic groups permissions to read those secrets via IAM policies.
  3. App accesses Vault with the OCI SDK from inside the pod instead of Kubernetes Secrets.
Python snippet (OCI Vault read example – high level):
Then your pod uses this method instead of relying on Kubernetes Secret objects.

9. Verification

  1. Attempt to list secrets with a service account or user that should not have access; verify it fails:
  2. 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.
This change does not replace the 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.