Skip to content
ShipFastDev
All posts

Article

Where to keep API keys and passwords: secrets management for small teams

, 5 min read

Aymane handles DevOps and cloud work on ShipFastDev projects, joining when a project needs it.

Keep API keys and passwords out of your code and your repository, in one secret store per environment, readable only by what needs them. Rotate them on a schedule, and know in advance what you will do the day one leaks. Leaks are common and they last: GitGuardian counted 28,649,024 new secrets in public GitHub commits in 2025, and found that 64% of valid secrets it detected in 2022 were still valid four years later. This guide covers where secrets should live at each stage of a product, who should be able to read them, and what to do when one escapes.

What counts as a secret

Anything that grants access: database passwords, API keys for payment, e-mail or AI services, signing keys for sessions and tokens, cloud service account files and webhook secrets. Plain configuration, such as a feature flag or the name of a region, is not a secret; mixing the two in one file is how secrets end up in places they shouldn't.

Rule 1: never in the code

The Twelve-Factor App, a well-known set of principles for web services, requires strict separation of config from code and offers a simple test: could the codebase be made open source at any moment, without compromising any credentials? If not, secrets are in the code.

Private repositories are not a safe exception. GitGuardian found that 32.2% of internal repositories contain at least one secret, compared with 5.6% of public ones: by its count, internal repositories are six times more likely to contain hardcoded secrets. In practice:

  • Commit a .env.example with the names of the variables and fake values, and keep the real .env in .gitignore.
  • Turn on secret scanning before a push, not after. GitHub's push protection for users is on by default for public repositories on every plan; for private repositories the repository-level version is part of the paid GitHub Secret Protection.
  • Never bake secrets into container images. OWASP's cheat sheet says secrets "should never be hardcoded using docker ENV or docker ARG commands", because they easily leak with the container definitions.

Rule 2: one store, separate values per environment

Where secrets should live depends on the size of the product:

  • Starting out: your hosting platform's secret settings and your CI system's secret store, with separate values for staging and production. That is enough for one app and a small team.
  • Several services or people: a cloud secret manager. AWS Secrets Manager, for example, charges $0.40 per secret per month and $0.05 per 10,000 API calls, so 20 secrets cost about $8 a month before API calls. You get versioning, access control and an audit trail in one place.
  • Many services, strict compliance: a dedicated system such as HashiCorp Vault, which provides "centralized, well-audited privileged access and secret management", audits all activity whether or not a request is allowed, and has database plugins that manage dynamic credentials for clients.

One nuance on environment variables. Twelve-Factor stores config in them, while OWASP's cheat sheet, focused on secrets, recommends against environment variables unless other methods are not possible, because they are generally accessible to all processes and may end up in logs or system dumps. A practical middle ground is to keep the value in a secret store and inject it at runtime, never in the image or the repository, and to make sure your error reporting doesn't dump the environment.

Rule 3: least access, with a trail

OWASP's guidance is plain: "engineers should not have access to all secrets in the secrets management system". Production secrets are read by the production app and the deploy pipeline, not by every developer's laptop. Give people access per environment, remove it the day they leave a project, and keep an audit log of who read or changed what, stored where it can't be quietly deleted. The same habit makes onboarding a remote developer safer: they get staging access on day one and production access only when they need it.

Rule 4: plan the whole lifecycle

The OWASP cheat sheet describes four stages every secret goes through:

  • Creation: generated securely and strong enough for its purpose.
  • Rotation: changed regularly "so that any stolen credentials will only work for a short time". Rotation by hand leads to mistakes, so automate it where the service allows.
  • Revocation: removed as soon as it is no longer needed or may be compromised.
  • Expiration: set to expire after a defined time where possible.

The day a secret leaks

  1. Revoke or rotate it first. Deleting the commit is not enough: the value stays in Git history, forks and caches, and the 64% still-valid figure above shows how long leaked keys keep working.
  2. Check the service's logs for use of the key since it leaked, and for unexpected charges.
  3. Deploy the new value through the normal pipeline, so nothing is fixed by hand on a server.
  4. Find how it leaked (a committed file, a log line, a screenshot, a chat message) and close that path.
  5. Add the check that would have caught it, usually push protection or a scanner in CI.

AI services deserve special care. GitGuardian counted 1,275,105 leaked secrets for AI-related services in 2025, 81% more than the year before. If you are adding AI features, treat the model provider's key like a payment key, and use the usage limits the provider offers.

Frequently asked questions

Is a .env file safe?

On a developer's machine and kept out of Git, it is a reasonable way to hold development values. It should never be committed, never hold production secrets on a laptop, and never be copied into a container image.

Are environment variables secure enough for production?

They are widely used and acceptable when injected at runtime from a secret store. OWASP's cheat sheet recommends other methods where possible, because environment variables are generally accessible to all processes and can end up in logs or system dumps.

Do we need HashiCorp Vault?

Not for one app and a small team; your platform's secret settings or a cloud secret manager are enough. Vault earns its place with many services, many people and requirements for central audit and dynamic credentials.

We pushed a key to GitHub. What now?

Revoke or rotate it immediately, before cleaning the history. Then check the service's logs for misuse, deploy the new key, and turn on push protection or a scanner so it can't happen the same way again.

Sources

  1. The State of Secrets Sprawl 2026, GitGuardian, 2026
  2. III. Config, The Twelve-Factor App
  3. Secrets Management Cheat Sheet, OWASP Cheat Sheet Series, 2026
  4. GitHub security features, GitHub Docs, 2026
  5. AWS Secrets Manager pricing, Amazon Web Services, 2026
  6. What is Vault?, HashiCorp Developer, 2026

Want this kind of work on your product?

Tell Adil what you’re building. You get a reply within 1 business day with times for a 15-minute video call.