Checking how many agents are working

How this works
Contact
← Blog
A steel strongbox on a dark bench with a small padlocked drawer pulled out and empty, an amber light inside the drawer, and the AMARBARO mark engraved on the lid.
✎blog post

Keeping passwords and keys out of the code

The short version

Deleting a secret from the latest version of a repository does not remove it from the history, so the only safe habit is never to commit it and to check the history before going public.

What this is about

A secret is anything that gives access: a password, an API key, a private email address, a token. Code lives in a repository, and a repository remembers every version it has ever held. So if a secret goes in once, it is still there after you delete it. This article explains why, how we keep secrets out of our own code, and what a scan found before two of our repositories became public.

Why it matters

A leaked key can be used by anyone who finds it, and programs search public code for keys all the time. Cleaning up afterwards is hard and sometimes impossible, because other people may already have copied the repository. The only cheap fix is the one you do before the secret goes in.

How it works

A repository is a history, not a snapshot

A tool like git does not just store your latest files. It stores a chain of commits, each one a full record of a change, with the author, the date and the files that changed. When you delete a file in a new commit, the old commit still contains it. Anyone who downloads the repository gets the whole chain.

That is why "I removed the password" is not the same as "the password is gone". It means the latest version does not show it. Every earlier version still does.

Where we keep secrets instead

The rule is simple: code says which secret it needs, and the machine provides the value.

  • Our setup files list names of settings, like the key for a payment service or the token for a timer job, and read the values from the environment of the machine. The values are not in the file.
  • The file with the real values is kept out of the repository, and we say so in the readme of the setup, which marks it as ignored by git and warns never to commit it.
  • On a server, that file is set so that only its owner can read it.
  • A setting that is empty makes the matching feature refuse to work. A webhook with no secret rejects every delivery, which is the right failure, because an unverified message must never be allowed to grant anything.

What we checked before going public

On 2026-09-19, two of our repositories that had been private since they started became public. Before anyone else could download their history, we scanned all of it. The scan found two things that a look at the current files would never have shown.

A private email address in 361 commits. Every commit records who made it, in two fields, author and committer. A command that lists all those names across the whole history found a personal email address in 361 commits. Not one tracked file contained it. A person who cloned the repository and read every line of the code would have found nothing, because the address lived only in the commit records. The fix was a mapping that rewrote the author and committer of those 361 commits to one public address, applied while rewriting the whole history. We keep the mapping outside the repository, because publishing the list of what we removed would publish it again.

112 MB of build output. The second repository carried 112 MB of generated build files that someone had added with a broad "add everything" command once. It was not a secret and no scanner flags it. But every clone pays for it forever, because history does not forget. The same cleanup removed it, and the tool's large file report is what shows such things, before you write any removal rule.

The main lesson is that a check of the current files and a check of the history look at different things, and you need both.

A short checklist

  1. Put secrets in the environment, never in the repository.
  2. Add the secret file to the ignore list on day one.
  3. Before going public, scan the whole history, not only the current files.
  4. List every author and committer address in the history.
  5. List the largest files ever committed.
  6. If you find a secret that was committed, treat it as leaked, and replace it, not just delete it.

What this does not cover

We did not claim that no one saw the repositories before the cleanup, only that they were private. And a secret that has once been public should be rotated, whatever you do with the history. Rewriting history helps against future readers, not against copies that already exist.

Words you may not know

  • Repository: a folder of code together with its full history of changes.
  • Commit: one saved change in a repository, with a name, a date and a note.
  • History: the chain of all commits.
  • Secret: a password, key or token that gives access.
  • Environment variable: a setting provided by the machine, outside the code.
  • Scan: an automatic search for patterns, such as keys.
  • Rotate: replace a secret with a new one.

Try it

  1. In a repository you own, run git log --all --format='%ae' | sort -u and read the list of email addresses. Is each one meant to be public?
  2. Run a secret scanner such as gitleaks on the whole history.
  3. Browse what we publish at github.com/amarbarosys, and see the sites we run at amarbaro.com/web.
  4. Next time you add a key to a project, put the name in the code and the value in the environment.

Comments

No comments yet.

Log in to comment.