They assume the runtime lookup is the control, when it is only the retrieval method. os.environ does not provide ownership, audit logging, or revocation. Those controls must exist in the system that supplies the values, otherwise the application is still relying on unmanaged secret distribution.
Why This Matters for Security Teams
The common mistake is treating OWASP Non-Human Identity Top 10 guidance as if environment variables were a secret control, rather than a delivery mechanism. That misunderstanding leaves teams exposed to the same problems they were trying to avoid: uncontrolled distribution, weak ownership boundaries, and no dependable revocation path. Secrets pulled from process state can still be copied, inherited, logged, or exposed through child processes and debug tooling.
NHI Management Group’s research on the Guide to the Secret Sprawl Challenge shows why the issue persists: teams often centralize storage in theory, but operational reality still fragments secret handling across code, CI/CD, and runtime configuration. The result is that os.environ becomes a convenient retrieval path for applications, not a governance boundary for secrets. Current guidance suggests that the control plane must own issuance, rotation, auditability, and revocation, while the application only reads short-lived values at runtime.
In practice, many security teams discover secret leakage only after a build log, crash dump, or compromised service account has already exposed the value.
How It Works in Practice
Using os.environ safely starts with a simple principle: the application should never be the authority for the secret. The secret should be issued by a managed system, injected at startup or on demand, and revoked independently of the process that consumes it. That is where controls from NIST SP 800-53 Rev 5 Security and Privacy Controls become relevant, especially around least privilege, auditability, and configuration integrity.
Operationally, teams should distinguish between retrieval and governance:
-
Retrieval: The app reads a value from
os.environbecause that is how the runtime receives configuration. -
Issuance: A secrets manager or workload identity system generates and scopes the value.
-
TTL: The secret should be short-lived where possible, especially for automated workloads.
-
Revocation: Rotation must happen outside the app, so compromise of the process does not freeze the secret lifecycle.
-
Audit: Access to the value should be logged by the source system, not inferred from environment use.
This distinction matters because environment variables are inherited by child processes and can surface in diagnostics, memory inspection, or misconfigured support tooling. The risk is not theoretical: the 52 NHI Breaches Analysis and supply-chain incidents such as the Reviewdog GitHub Action supply chain attack show how quickly a single leaked value can spread through automation layers. Best practice is to pair environment injection with centralized secret management, ephemeral credentials, and strict process isolation. These controls tend to break down in containerized CI/CD runners and shared build agents because environment state is easy to copy and hard to govern once execution starts.
Common Variations and Edge Cases
Tighter secret handling often increases delivery overhead, requiring organisations to balance deployment simplicity against exposure reduction. That tradeoff is why os.environ is still used widely, but the acceptable use cases are narrower than many teams assume. For example, environment variables can be reasonable for low-risk configuration flags, but they are a poor default for high-value credentials unless the source system enforces short TTLs and ownership.
There is no universal standard for this yet, but current guidance suggests the following boundaries:
-
Use
os.environas a transport, not as a storage model. -
Prefer short-lived tokens over long-lived static secrets.
-
Avoid writing secrets into logs, crash dumps, or shell histories during troubleshooting.
-
Use workload identity and secret broker systems where the runtime can authenticate without embedding durable credentials.
The edge cases appear when teams run many ephemeral workloads, multiple build stages, or service meshes that rotate credentials rapidly. In those environments, environment variables can lag behind the actual trust model, especially when rotation is frequent or when processes cache values longer than intended. The Ultimate Guide to NHIs — Static vs Dynamic Secrets is useful here because it frames the real issue: static delivery patterns do not match dynamic trust needs. In short, if the secret lifecycle is not governed outside the process, os.environ only hides the problem until the next incident.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
OWASP Non-Human Identity Top 10 and CSA MAESTRO address the attack and risk surface, while NIST CSF 2.0, NIST AI RMF and NIST Zero Trust (SP 800-207) set the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| OWASP Non-Human Identity Top 10 | NHI-03 | Environment variables often mask unmanaged secret rotation and lifecycle gaps. |
| NIST CSF 2.0 | PR.AC-1 | Secret use via env vars still depends on proper identity and access governance. |
| NIST AI RMF | Runtime secret handling for automated systems requires governed, context-aware trust decisions. | |
| NIST Zero Trust (SP 800-207) | Zero trust requires denying implicit trust in inherited process state like env vars. | |
| CSA MAESTRO | Agentic and cloud-native workloads need runtime controls beyond static environment injection. |
Use workload-aware controls, short-lived credentials, and policy checks before exposing secrets to runtime.
Related resources from NHI Mgmt Group
- What do teams get wrong about using Secrets Manager for every sensitive value?
- What do security teams get wrong about secrets in third-party code and integrations?
- What do teams get wrong about rotating NHI secrets after compromise?
- What do teams get wrong about sharing secrets through collaboration tools?