Configuration tells one application build which services and limits to use in a specific environment. Secrets are a narrower class of configuration that grant access and must stay on trusted servers or secret stores. A browser bundle is public even if a variable name contains 'secret'. Validate required server settings at startup so a missing database name fails early, not during a user request. Rotate credentials without committing them to source control, and restrict each service identity to the operations it needs. Separate local, staging, and production values so a test job cannot accidentally write to live data.
Environment Configuration and Secret Boundaries
Working case
A case API deployment receives a database address and signing key from its runtime environment. Startup checks that both are present and that the signing key meets a length requirement before accepting traffic. The public frontend receives only a non-secret API path. A developer who needs to diagnose a failure logs which setting is missing, not its value. If a credential is compromised, the team rotates it and verifies the old one no longer works. The code demonstrates validation, not a particular secret-management product.
Implementation
function readServerConfig(environment) {
const databaseAddress = environment.CASE_DATABASE_ADDRESS;
const sessionSigningKey = environment.SESSION_SIGNING_KEY;
if (!databaseAddress) throw new Error("Missing case database address");
if (!sessionSigningKey || sessionSigningKey.length < 32) {
throw new Error("Session signing key is not configured safely");
}
return { databaseAddress, sessionSigningKey };
}
const serverConfig = readServerConfig(process.env);Cost and boundaries
Startup validation is O(1) for a fixed set of settings. Secret rotation may require a period when both old and new signing keys are recognized, plus careful expiry of old sessions. A central secret service adds network and operational cost but can improve access control and auditability. Injecting secrets at build time into a browser app leaks them regardless of minification. Keep the number of long-lived secrets small and test staging with credentials that cannot reach production resources.
Common Mistakes
- Do not put credentials in a browser bundle or repository fixture.
- Do not print secret values in startup errors.
- Do not let staging credentials write production data.
Connected lessons
Deployment and Scale; Continuous Integration and Release Gates; Horizontal Scale and Shared State; Backup and Restore Drills; Release checks: prove the critical route and prepare a rollback; Observability: connect user failure to a safe request trace; DevOps: delivery, infrastructure, and reliable operations.
Failure trace
A deployment embeds a service credential into a client bundle because the build system treats every environment variable as public. Anyone downloading the script can read it, and rotating the value requires a new release. Divide configuration by exposure: public flags may be baked into client code, while credentials stay on the server or in a secret store with narrow access.
Verification
- Search built client assets for known secret canary values and fail the release if one appears.
- Boot a staging release with a missing required server secret and confirm it fails clearly before serving traffic.
- Rotate a credential and verify old instances stop using it within the planned interval.
Decision note
An environment name is not a security boundary. Review where a value is read, serialized, logged, and shipped, then give each deployed service only the credentials it needs.
Apply and check
Build Project: release and recovery drill for a content service; then check the boundary with Web Development: offline and delivery contracts quiz.
