agentleFS
everywan-deveverywan-dev/claude-code-engineering/skills/keep-secrets-out-of-the-repository/SKILL.md

keep-secrets-out-of-the-repository

Skill2 starsChanged 3 months agoApache-2.0View on GitHub

Use before committing configuration, when a secret has already been committed, or when adding a secret scanner. Covers why rotation beats scrubbing and why most scanners get switched off.

  • Reads credentials

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Environment or a manager, never the repository: If the deployment needs it, the deployment supplies it.

    line 53

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Keep secrets out of the repository

Two facts do most of the work here.

A secret that reached a repository is compromised, not "at risk". Clones, forks, CI caches, backups, editor histories and mirrors all copied it while you were deciding what to do.

Rewriting history does not undo that. It makes the repository look clean, which is a different thing, and an actively dangerous one if it lets you skip the step that matters.

🔴 Rotate first. Scrub second, if at all. The scrub is cosmetic; the rotation is the fix. Doing them in the other order means the credential is still valid while you are busy tidying.

When to use this

  • You are about to commit a config file, an .env, a compose file, a notebook
  • A secret is already committed, in history, or was pasted into an issue or chat
  • You are adding or fixing a secret scanner
  • A token was shared to unblock someone and never revoked
  • A test fixture contains "a fake key" that is not fake

If one is already committed

1. Rotate it. Now, before anything else. New credential issued, old one revoked at the source. Until that is done, everything else is theatre.

2. Check whether it was used. Access logs at the provider, not guesses. A rotation without a look at the logs answers "can they still get in?" but not "did they?".

3. Only then decide about history. Rewriting is expensive: it changes every commit id, breaks every open branch and fork, and requires a force-push that everyone must recover from. It is worth it for a public repository. It is often not worth it for a private one where the credential is already dead.

4. If you do rewrite, say so. People with clones need to know their history diverged and how to recover. A silent force-push turns one incident into several.

Preventing the next one

Keep the shape of a secret out of the file, not just the value. A config.example with PASSWORD=changeme teaches the pattern; a real file committed once teaches nothing but costs everything.

Environment or a manager, never the repository. If the deployment needs it, the deployment supplies it. The repository holds the name of the variable, and that is all.

Add a scanner — and read the next section before you do.

Why most scanners get switched off

A scanner that fires on things that are not secrets gets disabled within a week, and then you have no scanner and a false sense of having one.

Three failure modes, in the order they actually happen:

FailureWhy it happensFix
It reports itselfIts own pattern list contains example secretsBuild the patterns at runtime from parts; never store a literal example
It flags every long stringEntropy heuristics on code, not configRestrict entropy rules to config files; require a recognisable prefix elsewhere
It flags the code that reads the secretTOKEN = os.environ.get("TOKEN") looks like an assignmentRequire plausible secret material, not just the word

The first one is the one to watch for, because it fails permanently and looks like a bug in the scanner rather than in its design.

Anti-patterns

  • "It's only in a private repo." Private today. Contractors, forks, an accidental visibility change, an acquisition.
  • "It's a low-value key." Then it is cheap to rotate. Rotate it.
  • Scrubbing and calling it fixed. The credential is what matters, not the file.
  • A test fixture with a real value because "the test needs a realistic one". It needs a well-formed one, which is not the same thing.

The incident

A repository received a routine commit that included configuration with live credentials. It was caught, the history was rewritten with a history-rewriting tool and force-pushed, and the repository was clean afterwards.

The part worth remembering is what the clean repository did not change: for the entire window between commit and rotation, the credentials were valid and had been distributed to every clone and CI cache. The scrub made the evidence disappear, not the exposure.

Separately, a secret scanner added to the same organisation failed on its very first run — on itself. Its pattern list contained example prefixes, so it detected its own source. Fixed by requiring plausible material after a prefix, restricting entropy checks to configuration files, and assembling the control strings at runtime so the file never contains one.

Related

  • validate-your-validator — the scanner that incriminated itself, in full
  • write-the-rollback-plan-first — a history rewrite needs a recovery path written before the force-push
  • map-the-attack-surface — where the credential could be used, once you know it leaked
  • review-code-you-did-not-write — generated config files are a common way secrets arrive

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.