Back to Blog
Software

Your Database Password Is in the Source Code: Designing Secrets Management and Key Rotation for Business Systems

Database passwords and API keys often stay in repositories and chat logs long after an outsourced project ends, unchanged even when vendors change. This guide covers how secrets leak, the levels of secret storage, zero-downtime key rotation, least privilege, and a checklist you can use today.

POLYGLOTSOFT Tech Team2026-11-307 min read9
Secrets ManagementCredential SecurityKey RotationEnvironment VariablesDevSecOps

The Secrets Left Behind After an Outsourced Project

When a system is handed over, the screens and features end up in the handover document. The secrets usually don't. Database passwords and API keys for payments or SMS stay where they were: in config files in the repository, in `.env` files on servers, and in messenger chats where someone pasted them.

The bigger problem is that the keys don't change when the people do. Even after you switch vendors or a developer leaves, it is common to find the production database password unchanged for years. A contractor whose engagement ended long ago can, technically, still reach your production data.

How Secrets Leak

  • Git commit history: Deleting a password from a file doesn't remove it from past commits, and everyone who cloned the repository has that history
  • Shared documents and chats: A "server access info" document spreads through share links
  • Log output: Code that dumped full connection strings or request headers for debugging makes it into production
  • Build artifacts: A server-side key bundled into a frontend build or mobile app can be extracted by anyone
  • Security firm GitGuardian counted roughly 23.8 million secrets exposed on public GitHub in 2024 alone. Private repositories aren't immune either. The more people who have access, the wider the exposure.

    Sharing the same keys between production and development makes things worse. Compromise one loosely protected dev server and production opens up with it. Issuing separate keys per environment should be the baseline.

    Levels of Secret Storage

  • Hardcoded: Written straight into the source. Access to the repository means access to production
  • Environment variables or server config files: Separated from the code, but readable by anyone with server access, and there's no record of who read them or when
  • Secrets management tools: HashiCorp Vault, AWS Secrets Manager, Azure Key Vault, GCP Secret Manager, and similar. They provide encrypted storage, access control, audit trails, and automated rotation
  • Realistic Options by Company Size

  • Small (1–3 servers): Start by moving every secret out of the repository and into your deployment platform's environment variables
  • Mid-sized: A cloud secrets manager fits well. AWS Secrets Manager costs about $0.40 per secret per month, so even dozens of secrets stay in the tens of dollars
  • Large or hybrid on-premises: Consider Vault's dynamic secrets, which issue a database account on request and revoke it after a set time
  • Designing Key Rotation

    The main reason teams put off rotation is fear of an outage. The moment a password changes, every server still using the old value fails to connect. Running two keys at once avoids this.

  • Create a new key (or a second database account) and keep it valid alongside the old one
  • Point the application configuration at the new key and redeploy servers one by one
  • Confirm from the access logs that every instance connects with the new key, then revoke the old one
  • For databases, alternating between two accounts with identical privileges (say, `app_a` and `app_b`) is simple and reliable.

    Set rotation intervals by risk. For example, rotate production database and payment keys every 90 days and internal integration keys every 180 days. Keys that can rotate automatically can go even shorter. More important than the interval is an emergency rotation procedure. If you suspect exposure: (1) issue and deploy a new key, (2) revoke the old one, (3) review access logs for the exposure window, and (4) clean up the repository history. Clones may already exist, so rotate first and scrub history second. Write this procedure down ahead of time and rehearse it at least once.

    Least Privilege and Access Logging

  • A dedicated account per application: If the website, the ERP integration, and batch jobs all share one admin account, you can't tell which one caused an incident
  • Separate read and write: Run reporting and analytics on a read-only account, and grant schema-change rights only during migrations
  • Audit logs for secret access: Record every secret retrieval and alert when a person or server that normally never reads a key suddenly does
  • A Checklist for Today

  • Have you scanned the entire history of your repositories with tools like gitleaks or TruffleHog?
  • Are production and development keys separate?
  • Did you rotate every key when you changed vendors or when someone left?
  • Are frontend bundles and apps free of server-side keys?
  • Is your emergency rotation procedure documented?
  • At POLYGLOTSOFT, our subscription development service designs this in from day one: secrets kept out of the repository, separate keys per environment, and a dedicated account for each application. After delivery, our SM (maintenance) plans take on the ongoing operational work, including scheduled key rotation, repository secret scanning, and full key rotation at every handover. If you're unsure how your current system handles its secrets, reach out through our contact page for a consultation.