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
MediumAddress
Compliance, SecurityCompliance Standards
- CIS OKE
Triage and Remediation
- Remediation
Remediation
Using Console
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
1. Get
Or from a file:Verify:
You’ll change them to a volume and volumeMount.3.1. Edit the existing Deployment using
From Cloud Shell or your local environment (after step 1):Replace the Your application will see:
This way secrets are only mounted as files from Vault.
If you paste a current Deployment manifest, I can show an exact before/after YAML diff tailored to your setup.
env). You’ll do it by:- Ensuring your cluster is accessible.
- Creating/updating Kubernetes Secrets.
- Updating your Pod/Deployment manifests to use those secrets as files via volumes.
1. Get kubeconfig for your OKE cluster via OCI Console
- Sign in to OCI Console.
- Open the Navigation menu → Developer Services → Kubernetes Clusters (OKE).
- Choose the correct Compartment.
- Click your Cluster.
- On the cluster details page, click Access Cluster.
- 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
kubeconfigusing the providedoci ce cluster create-kubeconfigcommand. - Export
KUBECONFIGenvironment variable to point to that file.
- If you’re on Cloud Shell: click Cloud Shell Access → follow on-screen instructions to set
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:3. Update Deployment / Pod spec to mount secrets as files
Identify the workloads currently using env vars like:3.1. Edit the existing Deployment using kubectl (from OCI console access)
From Cloud Shell or your local environment (after step 1):env: usage with a secret volume. Example:/etc/myapp/secrets/db-username/etc/myapp/secrets/db-password
4. (Optional) Remove secret environment variables
Once your application is confirmed working using files:-
Edit the Deployment again:
-
Remove any
env:entries that reference Secrets.
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:- In OCI Console: ensure Vault and Secrets are created:
- Identity & Security → Vault → Create vault and secrets.
- Install and configure Secrets Store CSI Driver for OKE (follow OCI docs).
- Configure a
SecretProviderClassand a Pod volume like:
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.
Using CLI
Using CLI
Below is how to remediate this in OCI OKE using the OCI CLI plus
Verify access:
For a particular Deployment (example):Look for patterns like:These must be removed and replaced with a volume/volumeMount.
To create/update a Secret:
Verify:Confirm that
Summary:
Using OCI CLI you obtain cluster credentials; the actual remediation is done via
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 havekubectl access to the cluster, generate kubeconfig via OCI CLI:2. Identify workloads using Secrets as environment variables
List all namespaces and check workloads:3. Create or confirm the Secret
If the Secret already exists, you can reuse it. To check:4. Modify the workload to mount the Secret as files
Edit the YAML you exported (deployment.yaml) and change:-
Remove env/envFrom entries referencing the Secret.
Example to delete: -
Add a volume that uses the Secret:
Under
spec.template.spec.volumes: -
Mount the volume in the container:
Under
spec.template.spec.containers[].volumeMounts:
5. Apply the updated manifest
Apply the edited file back to the cluster: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:- Use OCI CLI to get kubeconfig for each OKE cluster.
- For each namespace/workload:
- Export YAML
- Remove
env/envFromwithsecretKeyRef/secretRef - Add
volumes[].secretandvolumeMounts[] - 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.Using Python
Using Python
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.
you should:
This pattern satisfies “mount secrets as files instead of environment variables” for OCI OKE using Python-based automation.
1. Prerequisites
- Have
kubectlworking against your OKE cluster. - Python 3.8+.
- Install Kubernetes Python client:
- 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 aSecret, 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 mountmy-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:- Remove those
enventries. - Add a
volumereferencing the secret. - Add
volumeMountsin containers. - Update your application to read the secret from files.
5. Application-Side Change
Inside the container, read secrets from files, for example (Python app):Using Terraform
Using Terraform
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.
