Skip to main content

More Info:

Secrets injected as environment variables show up in process listings, container metadata, and many crash dumps. Mount them as files (tmpfs volumes) so they remain inside the containers view of /proc and not in the wider environment.

Risk Level

Medium

Address

Compliance, Security

Compliance Standards

  • CIS OKE

Triage and Remediation

Remediation

Using Console

To remediate this in OCI OKE, you don’t change a “setting” in the OKE console; you change how your Pods use secrets (volume mounts instead of env). You’ll do it by:
  1. Ensuring your cluster is accessible.
  2. Creating/updating Kubernetes Secrets.
  3. Updating your Pod/Deployment manifests to use those secrets as files via volumes.
Below are step‑by‑step instructions, starting from the OCI Console.

1. Get kubeconfig for your OKE cluster via OCI Console

  1. Sign in to OCI Console.
  2. Open the Navigation menuDeveloper ServicesKubernetes Clusters (OKE).
  3. Choose the correct Compartment.
  4. Click your Cluster.
  5. On the cluster details page, click Access Cluster.
  6. Choose your method:
    • If you’re on Cloud Shell: click Cloud Shell Access → follow on-screen instructions to set KUBECONFIG.
    • If you’re on your local machine:
      • Click Local Access.
      • Download the kubeconfig using the provided oci ce cluster create-kubeconfig command.
      • Export KUBECONFIG environment variable to point to that file.
Example (local machine):

2. Create or verify the Kubernetes Secret

If you currently inject secrets as env vars, you already have K8s Secrets. You can re-use them. If not, create one.Example: create a secret from literal values:
Or from a file:
Verify:

3. Update Deployment / Pod spec to mount secrets as files

Identify the workloads currently using env vars like:
You’ll change them to a volume and volumeMount.

3.1. Edit the existing Deployment using kubectl (from OCI console access)

From Cloud Shell or your local environment (after step 1):
Replace the env: usage with a secret volume. Example:
Your application will see:
  • /etc/myapp/secrets/db-username
  • /etc/myapp/secrets/db-password
Update your application configuration to read from those files instead of environment variables.Save and exit the editor; Kubernetes will roll out a new ReplicaSet with the change.

4. (Optional) Remove secret environment variables

Once your application is confirmed working using files:
  1. Edit the Deployment again:
  2. Remove any env: entries that reference Secrets.
This ensures secrets are not present in the environment anymore.

5. (Optional) Use OCI Vault via Secrets Store CSI Driver

If you’re using OCI Vault and want dynamic mount from Vault instead of K8s Secret:
  1. In OCI Console: ensure Vault and Secrets are created:
    • Identity & SecurityVault → Create vault and secrets.
  2. Install and configure Secrets Store CSI Driver for OKE (follow OCI docs).
  3. Configure a SecretProviderClass and a Pod volume like:
This way secrets are only mounted as files from Vault.

6. Validate

From a running Pod:

If you paste a current Deployment manifest, I can show an exact before/after YAML diff tailored to your setup.
Below is how to remediate this in OCI OKE using the OCI CLI plus kubectl (which is how you actually modify Kubernetes objects).Goal: stop injecting secrets as environment variables and instead mount them as files from Kubernetes Secrets.

1. Get kubeconfig for the OKE cluster (using OCI CLI)

If you don’t already have kubectl access to the cluster, generate kubeconfig via OCI CLI:
Verify access:

2. Identify workloads using Secrets as environment variables

List all namespaces and check workloads:
For a particular Deployment (example):
Look for patterns like:
These must be removed and replaced with a volume/volumeMount.

3. Create or confirm the Secret

If the Secret already exists, you can reuse it. To check:
To create/update a Secret:

4. Modify the workload to mount the Secret as files

Edit the YAML you exported (deployment.yaml) and change:
  1. Remove env/envFrom entries referencing the Secret.
    Example to delete:
  2. Add a volume that uses the Secret: Under spec.template.spec.volumes:
  3. Mount the volume in the container: Under spec.template.spec.containers[].volumeMounts:
After this, your application should read the secret from files like:

5. Apply the updated manifest

Apply the edited file back to the cluster:
Verify:
Confirm that env / envFrom entries referencing Secrets are gone and the Secret is only used as a volume.

6. Optional: Scripted remediation (using kubectl + yq)

For many Deployments, you may script transformation, but conceptually it remains:
  1. Use OCI CLI to get kubeconfig for each OKE cluster.
  2. For each namespace/workload:
    • Export YAML
    • Remove env/envFrom with secretKeyRef/secretRef
    • Add volumes[].secret and volumeMounts[]
    • Reapply YAML

Summary:
Using OCI CLI you obtain cluster credentials; the actual remediation is done via kubectl by replacing env/secretKeyRef or envFrom/secretRef with Secret-backed volumes and volumeMounts, so secrets are consumed as files instead of environment variables.
Below are the key steps and a Python example using the Kubernetes Python client to ensure OCI OKE pods mount secrets as files instead of using environment variables.

1. Prerequisites

  1. Have kubectl working against your OKE cluster.
  2. Python 3.8+.
  3. Install Kubernetes Python client:
  1. Ensure your kubeconfig is accessible (usually ~/.kube/config) or you are running in a pod with in-cluster credentials.

2. Create / Ensure the Secret Exists

If you already have a Secret, skip to step 3.Example: create a secret with two keys (username, password):

3. Python: Create a Deployment That Mounts the Secret as Files

This example shows a Deployment whose pods mount my-app-secret at /etc/myapp-secrets instead of using env vars.

4. Python: Migrating an Existing Deployment from Env Vars to Secret Files

If your existing Deployment uses secret-based env vars like:
you should:
  1. Remove those env entries.
  2. Add a volume referencing the secret.
  3. Add volumeMounts in containers.
  4. Update your application to read the secret from files.
Example patch in Python (simplified: assumes single container):

5. Application-Side Change

Inside the container, read secrets from files, for example (Python app):
This pattern satisfies “mount secrets as files instead of environment variables” for OCI OKE using Python-based automation.
This change is applied at the workload level; the oci_containerengine_cluster resource does not expose any argument that can force “secrets as files” across the cluster. No cluster replacement is required; only affected Pods/Deployments are recreated. After updating, terraform plan should show changes only to the kubernetes_* workload resources that drop secret-based env vars and add secret volumes.