3 ms·
> A safer alternative (and one we normally practice) is to start a fresh repo for the open source variant. Note that it's also possible to go back and rewrite
by danudey 6y ago
> A safer alternative (and one we normally practice) is to start a fresh repo for the open source variant.
Note that it's also possible to go back and rewrite history (e.g. if you know what the tokens are and where/when they were committed), to preserve Git history while cleaning out tokens. It can be mildly slow or complicated, but there are tools to automate it, such as BFG Repo Cleaner[0] which is relatively easy to use (once you learn it).
There are other awesome rewriting tools, like git filter-repo[1], but that operates solely on the structure of the repository (i.e. it can manipulate basically anything except file contents). Great for removing unwanted files or directories extremely fast, but not good for removing tokens (unless you want to remove the entire file the token was in).
[0] https://rtyley.github.io/bfg-repo-cleaner/
[1] https://github.com/newren/git-filter-repo
- amichal 6y agoLearning so many options from this thread. I've used these tools when I knew what to look for but thats been the tricky bit. psanford also mentioned truffleHog and others, lstamour mentioned https://github.com/cloud-gov/caulking https://github.com/cloud-gov/caulking which is built on gitleaks which looks good. caulking's customized list of patterns for gitleaks is here https://github.com/cloud-gov/caulking/blob/master/local.toml https://github.com/cloud-gov/caulking/blob/master/local.toml Looks like it would have found the keys in my example case no problem.
- deleted 6y ago[deleted]
- nyanpasu64 6y agoI've found that git filter-repo actually can modify file contents, using --replace-text and a file containing replacements.