Secrets management for small teams: getting passwords and API keys out of Git and .env files

Almost every small codebase we review has the same secret history: a database password in a .env file, an API key pasted into a CI variable two years ago by someone who has since left, and at least one token that was committed to Git “just for a minute”. None of this feels urgent until a laptop is stolen, a repository is made public by mistake, or a former contractor still has working credentials. This article is about fixing that without buying an enterprise platform.
What counts as a secret
A secret is anything that grants access on its own: database passwords, API keys, SMTP credentials, cloud access keys, SSH private keys, OAuth client secrets, webhook signing keys, session encryption keys (for WordPress, the salts in wp-config.php) and TLS private keys. A server IP address or a username is not a secret. Treating everything as secret makes people stop taking the real ones seriously.
Where secrets actually leak
- Git history. Removing a file in a new commit leaves the secret in every clone, fork and CI cache. Rewriting history with
git filter-repohelps hygiene, but you must assume the secret is already copied. - CI logs. A debug step that prints the environment, or a tool that echoes its command line, writes the token into logs that many people can read.
- Chat and tickets. “Here is the password” in a team chat lives forever in search results and exports.
- Container images. A secret copied in during the build stays in an image layer even if a later step deletes it. Anyone who can pull the image can extract it.
- Backups and laptops. Unencrypted backups of a project folder include every
.envfile in it.
The first rule: a leaked secret is rotated, not hidden
When a secret leaks, the only real fix is to issue a new one and revoke the old one. Deleting the commit, making the repository private again or editing the chat message does not undo the exposure. Automated scanners watch public GitHub repositories and can find a new AWS key within minutes. So the first thing to design is not storage but rotation: for every secret, you should know who can issue a new one, which systems use it and how long a change takes.
A practical maturity path
Level 1: stop new leaks
- Add
.env,*.pemand key files to.gitignore, and commit a.env.examplewith names but no values. - Run a secret scanner such as gitleaks or TruffleHog in a pre-commit hook and in CI. Enable GitHub or GitLab push protection where available.
- Scan the full history once. Treat every finding as leaked and rotate it.
Level 2: encrypted secrets in the repository
For small teams, SOPS with age keys is often the sweet spot. Secrets stay in Git, but encrypted, so changes are reviewed like code, and each server or CI runner gets its own key to decrypt them.
# .sops.yaml
creation_rules:
- path_regex: secrets/prod.yaml$
age: age1prodserverkey...,age1adminkey...
sops --encrypt --in-place secrets/prod.yaml
Removing a person means removing their key and re-encrypting, plus rotating whatever they could read. That last part is easy to forget.
Level 3: a secret manager
When you run on one cloud, its native service (AWS Secrets Manager or SSM Parameter Store, Azure Key Vault, Google Secret Manager) is usually the simplest choice: access is controlled by the same identity system as everything else, and every read is logged. HashiCorp Vault or OpenBao make sense when you are multi-cloud or need dynamic secrets, but they are a service you must run, back up and patch. We do not recommend self-hosting Vault for a team without someone who owns it.
Level 4: no long-lived secrets at all
The best secret is one that does not exist. CI pipelines can authenticate to AWS, Azure and Google Cloud with OIDC federation and short-lived tokens instead of stored access keys. Servers can use instance roles or managed identities. Databases can issue temporary credentials. Each long-lived key you replace is one less thing to rotate.
How applications should receive secrets
- Inject at runtime, not at build time. An image should be the same in staging and production; only its configuration changes.
- Prefer files mounted with restricted permissions (Docker and Kubernetes secrets) over environment variables for highly sensitive values. Environment variables are easy to dump through debug pages, crash reports and
docker inspect. - Give each application and environment its own credentials. A shared “admin” database user across staging and production turns a staging leak into a production incident.
Rotation that actually happens
Rotation policies fail when they depend on memory. What works:
- Keep an inventory: secret, owner, where it is used, how to rotate, last rotated.
- Rotate on events, not only on a calendar: when someone leaves, when a supplier changes, after any suspected leak.
- Support two valid credentials during a change, so you can roll out the new one before revoking the old one without downtime.
- Practise once on a low-risk secret. The first real rotation should not be during an incident.
Our take
For most teams of 2 to 20 developers, the right answer is boring: secret scanning in CI, SOPS or the cloud provider’s secret manager, OIDC for pipelines, and a one-page rotation inventory. A full vault platform is rarely the missing piece. The missing piece is almost always an owner and a habit of rotating after people leave.
Need a second pair of eyes?
We review repositories and pipelines for leaked and long-lived credentials as part of our DevOps plans. Start with the free IT audit or see the pricing.


