git sensitive data

11
Git hardly forgets Ombu Labs, January 2016

Upload: ombu-labs-the-lean-software-boutique

Post on 12-Apr-2017

282 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Git Sensitive Data

Git hardly forgets

Ombu Labs, January 2016

Page 2: Git Sensitive Data

The Problem

$ echo "secret data" > id_rsa

$ git add id_rsa

$ git commit -m "bad commit"

Page 3: Git Sensitive Data

$ git rm id_rsa

$ git show d6ec68dd6ec68d - bad commitdiff --git a/id_rsa b/id_rsasecret data

The Data remains

Page 4: Git Sensitive Data

$ git filter-branch --tree-filter 'rm -f id_rsa' HEADRewrite f5741346a28c65097b2a4e1ac9d9f31ca99ce43e (4/4)Ref 'refs/heads/master' was rewritten

$ git log0849436 - (HEAD -> master) remove id_rsa file1ec887c - another file7108ca8 - bad commit474db38 - initial commit

$ git show 7108ca87108ca8 - bad commit

Rewrite the history

Page 5: Git Sensitive Data

$ git show d6ec68dd6ec68d - bad commitsecret data

Rewrite the history

Seems that the history still exists …

Page 6: Git Sensitive Data

$ git push

$ git clone [email protected]:git-demo.git

$ git show d6ec68dfatal: ambiguous argument 'd6ec68d': unknown revision or path not in the working tree.

Local vs Remote

Page 7: Git Sensitive Data

$ git filter-branch --tree-filter 'git ls-files -z "*.rb" | xargs -0 perl -p -i -e "s#(12345)#REMOVED#g"' -- --allRewrite 051fdf0ac67128a918dd703e26df5737cf6f39da (8/8)...Ref 'refs/remotes/origin/awesome-feature' was rewrittenRef 'refs/remotes/origin/master' was rewritten

$ git gc --aggressive —prune$ git push -f

Filter Passwords

Page 8: Git Sensitive Data

$ git logbba8283 - replace api key with env var7152c92 - add api key to demo.rb

$ git show 7152c927152c92 - add api key to demo.rb

+API_KEY=REMOVED

The Result

Page 9: Git Sensitive Data

Safest Solution

• change all current Keys & Passwords

• rm -rf .git/

Page 10: Git Sensitive Data

Thank you!

Page 11: Git Sensitive Data

Questions?