Skip to content
MyDSHMy DSH Field Notes
中文
Independently maintained; not affiliated with DeepSeek. No association with mydsh.dev or other MyDSH sites.

Home/Models, permissions & security/API keys & credentials

Emergency checklist after committing a key to a repo

A key just turned up in commit history, or got pushed to a public repo.

VerifiedVersion and environmentChecked 2026-11-14
Scope
any case where a key reached a file
Checked
2026-11-14

Copyable command

git log --all -p -S 'sk-' --oneline | head
Order matters: revoke first, clean second. Reversed, cleanup takes half an hour and the key stays valid the whole time.

Step one: revoke now (two minutes)

  1. Disable or delete the key in the gateway console.
  2. Issue a new one.
  3. Keep the new one in an environment variable or a secret manager, never in a file.

Do these three before touching the repo. The window between a leaked key being scraped and abused is often tens of minutes.

Step two: clean history, not just the file

Delete the line and commit again and the key is still in history: anyone who clones can run git log -p. Clean the history:

git log --all -p -S 'sk-' --oneline | head       # confirm which commits hold it
git filter-repo --path-glob '*.yaml' --invert-paths  # or rewrite selectively with filter-repo

Rewriting history affects every collaborator, so notify first and take a full mirror backup before you start.

Step three: assume it leaked

Even in a private repo, assume compromise. Everyone who ever cloned has that history locally and you cannot recall it. Revocation is the only reliable stop.

Step four: check for use

  • Look for abnormal peaks in gateway usage.
  • Check the calling IPs recorded for that key, if any.
  • Treat anomalies as a security incident, not just a key rotation.

Step five: prevent the next one

  • Add a pre-commit hook that scans for sk- style prefixes.
  • Separate templates from credentials: templates in the repo, values injected from the environment.
  • Put .credentials.yaml in .gitignore — it is a key, not a config file.

What counts as working

Check every line. All of them pass or the job is not done.

  • The old key fails at the gateway
  • The new key appears in no commit
  • Searching history with -S finds nothing
  • Collaborators have all re-synced the rewritten history

Where it fails

Symptom, cause, what to do — written in the order it actually happens.

SymptomCauseWhat to do
Deleted the file but history still has itOnly the working tree changedRewrite with filter-repo; back up before and after
It is a private repo, so it is fineEveryone who cloned has a local copyRevoke and rotate anyway; private lowers probability, not fact

Sources

Verified means measured here. Compiled means every line carries a source.