Secrets in configuration files

Files such as config.yaml, application.yml, .env and settings.json can contain database passwords, API keys and OAuth secrets. Committing the real configuration alongside a sample can expose these values to anyone with repository access.

If a secret was exposed

  1. Revoke or disable the exposed credential immediately and issue a replacement.
  2. Remove live values from configuration and stop tracking production files in Git. Adding a file to .gitignore leaves past commits intact, so assess whether history needs cleaning.
  3. Choose a guide below to deliver the replacement in your environment.

Choose a detailed guide

Developer responsibilities

  • Keep only keys and structure in samples such as config.yaml.example. Have the application read live values from environment variables or a runtime configuration file.
  • Keep full configuration objects out of logs. Check debug output and error responses as well.

Infrastructure and platform responsibilities

  • Supply values using Kubernetes Secrets, a secret manager or protected file delivery. A ConfigMap or Docker image can expose a production configuration file.
  • Check that the deployment pipeline keeps production files out of Git. Document how to redeploy or reload configuration after rotation.

Verification

  • Check Git history for production files such as .env and inspect sample files for real values.
  • After deployment, verify that the application reads the replacement and that logs and error responses do not disclose it.

Example instructions for the owner

Please rotate the exposed credential and keep only the structure in config.yaml.example. If the application requires a real config.yaml, mount it at deployment.

Related documentation