Course contentsShow
← Security
Lesson 1319 of 3,05227. Application Security - Secrets ManagementFree lesson

The Twelve-Factor App and Environment Configuration

Examining the Twelve-Factor methodology's recommendation for config and secrets in environment variables and its context.

The Twelve-Factor App and Environment Configuration

What you'll learn: How the Twelve-Factor methodology approaches configuration and secrets management through environment variables.

The Twelve-Factor Methodology

The Twelve-Factor App is a methodology for building modern, scalable applications, particularly those deployed in cloud environments. One of its core principles directly addresses how applications should handle configuration—including secrets.

Factor III: Configuration

The third factor states: "Store config in the environment." This means:

  • Configuration (including credentials, API keys, database URLs) should live outside the codebase
  • Configuration should be injected at runtime via environment variables
  • This separates concerns: code is constant across deployments; config varies

The analogy: Think of your application as a universal power adapter. The adapter itself (your code) doesn't change, but it accepts different voltages (configuration) depending on which country (environment) you plug it into—development, staging, or production.

Why Environment Variables?

The Twelve-Factor methodology recommends environment variables because they:

  • Are language and OS-agnostic (work everywhere)
  • Prevent hardcoding secrets into code repositories
  • Enable easy deployment across different environments without code changes
  • Are difficult to accidentally commit to version control

The Security Context

From a security perspective, this approach:

  • Enforces separation between code and secrets (concept 1314)
  • Makes configuration explicit rather than hidden in code
  • Supports the principle of least privilege (concept 1313) by allowing different credentials per environment
  • Simplifies secret lifecycle management (concept 1311)

However, as you've learned in lesson 1318, environment variables alone have limitations—they're visible in process listings and don't provide encryption, rotation, or fine-grained access control.

Key Takeaway: The Twelve-Factor App's config-in-environment principle established best practices for separating secrets from code, though modern applications often need dedicated secrets management solutions beyond basic environment variables.