Website Environment Variables and Secrets Management: A Safe Setup and Rotation Guide
environment variablessecrets managementcloud hostingdeployment securityAPI keysdeveloper infrastructure

Website Environment Variables and Secrets Management: A Safe Setup and Rotation Guide

CComputerTech.cloud Editorial Team
2026-11-21
7 min read

A practical guide to tracking, storing, rotating, and revoking website environment variables and production secrets across every deployment stage.

Environment variables make it possible to configure a website without hard-coding settings, but sensitive values such as API keys, database passwords, SMTP credentials, and signing secrets need deliberate handling. This guide provides a practical system for storing, tracking, rotating, and revoking website secrets across development, staging, and production so deployments remain repeatable without exposing credentials.

Overview

Website environment variables are configuration values supplied to an application at runtime or during a build. A non-sensitive value might identify the application environment, while a secret might authenticate a database connection or sign a user session. Keeping these values outside source code reduces the risk of publishing credentials in a repository and makes it easier to use different settings for each environment.

Environment variables are not automatically secure. A value can still be exposed through a committed .env file, an unprotected hosting-panel screen, a build artifact, a shell history entry, an error message, or overly detailed application logs. The goal is therefore broader than “use environment variables.” A sound production secrets management process answers five questions:

  • What values does the website need?
  • Which values are sensitive, and who may access them?
  • Where is each value stored for development, staging, and production?
  • When was each secret last changed, and when should it change again?
  • How can an exposed value be revoked and replaced without unnecessary downtime?

For a small application, hosting environment variables may be sufficient if access is limited and changes are auditable. Larger or more security-sensitive deployments may use a dedicated secret manager that controls access, records usage, and supplies values to workloads at deployment or runtime. In either case, avoid treating a hosting dashboard as a complete inventory. Maintain a separate, non-secret register of names, owners, environments, purpose, and rotation status.

What to track

Start with an inventory that describes the secret without copying the secret itself. A useful record can include:

  • Variable name: Use the exact name expected by the application, such as DATABASE_URL, SMTP_PASSWORD, or PAYMENT_API_KEY. Confirm framework-specific naming and whether a variable is exposed to browser-side code.
  • Purpose: Explain which service, feature, or integration uses the value.
  • Environment: Record whether it belongs to local development, staging, production, or more than one environment.
  • Classification: Mark it as public configuration, sensitive configuration, or a high-impact secret. Database credentials, signing keys, and production administrator tokens deserve the strongest controls.
  • Owner: Identify the team or role responsible for validating, rotating, and revoking it. Do not rely on one person’s memory.
  • Storage location: Record the secret manager, hosting project, deployment system, or local-only method used to supply it. Never place the value in the inventory.
  • Permissions: Note which application, deployment identity, and human roles can read or update it.
  • Last changed and next review: Track dates, the reason for the change, and whether the old credential was revoked.
  • Validation method: Describe a safe test, such as sending a test message from a restricted mailbox or checking a read-only API call.

Separate values by environment. Development should use a local database, test mailbox, and restricted service account where practical. Staging should not silently share production credentials, because test code, logs, and access patterns are usually different. Production credentials should be limited to production workloads and should not be copied into a developer’s machine unless there is a documented operational need.

Keep local files such as .env out of version control with an appropriate ignore rule, and provide a committed example file containing variable names and safe placeholders only. Review build settings carefully: variables intended for server-side use must not be bundled into client-side JavaScript. If a value is sent to a browser, assume it is public and use a design that does not depend on secrecy.

For related deployment checks, connect this inventory to your monthly maintenance checklist for cloud-hosted websites. Email credentials also belong alongside the authentication and delivery checks described in the transactional email setup guide.

Cadence and checkpoints

Use a monthly or quarterly review cadence, depending on the number of integrations and the impact of the website. The review is not necessarily a requirement to change every secret each time. It is a checkpoint to confirm that the inventory, permissions, deployment configuration, and recovery steps still match reality.

Before each deployment

  • Confirm that required variables exist in the target environment and that names match the application configuration.
  • Check that no secret has been added to source control, deployment output, client bundles, screenshots, or issue comments.
  • Verify that the deployment identity has only the permissions needed for the release.
  • Test a safe path that uses important integrations, such as login, database access, file storage, or transactional email.

Monthly or quarterly

  • Compare the inventory with the variables configured in the hosting platform or secret manager.
  • Remove unused variables, abandoned integrations, and access granted to former team members or retired services.
  • Review access logs where available and investigate unexpected reads or changes.
  • Check that logs, monitoring alerts, crash reports, and support exports redact tokens, passwords, and connection strings.
  • Confirm that backups do not contain unnecessary plaintext copies of secret files and that restore procedures do not publish them.
  • Verify that the documented rotation and rollback procedure still works in a non-production environment.

After personnel or infrastructure changes

Review access after onboarding, offboarding, role changes, vendor changes, repository transfers, hosting migrations, and changes to CI/CD systems. If a person, build runner, plugin, integration, or server may have accessed a secret, assess whether the credential should be rotated rather than merely removing the current permission.

How to interpret changes

A change in the inventory is a signal to investigate, not just an administrative update. A newly added API key should have a documented purpose, owner, scope, and expiration or review date. A variable present in production but absent from staging may indicate an undocumented dependency, while a variable present in all environments may indicate unnecessary sharing of credentials.

Prefer least privilege at both the service and human levels. Use separate credentials for separate environments and integrations where the provider supports it. Prefer read-only access for reporting tasks, narrowly scoped tokens for deployment tasks, and short-lived or renewable credentials when the platform supports them. Do not grant broad administrator permissions simply because they are convenient during initial setup.

Rotation should avoid downtime when possible. A common sequence is:

  1. Create a replacement credential while the old credential remains valid.
  2. Store the replacement in the appropriate secret manager or hosting configuration.
  3. Deploy or restart the application so it reads the new value.
  4. Run a focused health check against the affected feature.
  5. Revoke the old credential only after the new one is confirmed to work.
  6. Update the inventory with the date, reason, owner, and validation result.

Some systems require a coordinated change, so document the expected interruption and rollback plan before rotating. If a secret is suspected to be exposed, do not wait for the normal review date. Revoke or disable it, inspect relevant logs and repositories, replace it, and check whether dependent applications continue to function. Remove the exposed value from future logs and repositories, but remember that deleting a file does not prove that historical copies no longer exist.

Use redaction deliberately. Mask query strings, authorization headers, cookies, connection strings, and request bodies that may contain credentials. Avoid printing the entire environment during troubleshooting. When debugging is complete, remove temporary verbose logging and review any captured output before sharing it.

When to revisit

Revisit this guide before every production deployment that changes configuration, and run the full inventory review monthly or quarterly. Return immediately after a suspected leak, failed authentication event, unexpected vendor notification, staff offboarding, hosting migration, CI/CD change, framework upgrade, or new third-party integration.

Use a short recurring checklist:

  1. Export or inspect the current variable names without revealing their values.
  2. Compare them with the application’s documented requirements and the inventory.
  3. Confirm environment separation, ownership, permissions, and review dates.
  4. Search repositories and build artifacts for likely secret patterns without copying discovered values into tickets.
  5. Test critical integrations in staging, then verify production health after changes.
  6. Rotate credentials whose owner, scope, exposure status, or age is uncertain.
  7. Record the result and assign the next review date.

Hosting providers, secret managers, frameworks, and authentication methods change their interfaces and recommended workflows over time. Refresh the provider-specific steps and framework variable names during semiannual reviews or after major platform releases. Keep the process simple enough to follow during an incident, but detailed enough that another administrator can rotate and revoke a production secret without guessing.

Related Topics

#environment variables#secrets management#cloud hosting#deployment security#API keys#developer infrastructure
C

ComputerTech.cloud Editorial Team

Developer Infrastructure Editor

Senior editor and content strategist. Writing about technology, design, and the future of digital media. Follow along for deep dives into the industry's moving parts.