BM: Baca dalam Bahasa Melayu
World 8: Shields: Security
Leaked a key? Rotate first
You will learn: what to do, in what order, when a key leaks.
The problem
Oh no. This commit went to a public repo an hour ago. It holds .env and its key. Assume someone already copied it.
Watch
Step one: rotate (a key): Cancel a leaked key and make a new one, so the old copy is useless. the key. Go to the service that gave it to you. Cancel the old key and make a new one. Now the leaked copy is useless.
Try it
Some people just stop tracking .env in a new commit. Is the key gone? Slide back in time.
c005c2c Stop tracking .env · Commit 5 of 5
.env—
The newest commit has no .env. One step back, the key is still there. Anyone can look.
Try it
Here is the full rescue plan. Put it in order, first step at the top.
First step at the top. Put these in order. Use the arrows, or drag.
- Rotate the key: cancel it, make a new one
- Untrack .env and add it to .gitignore
- Force-push and tell your team
- Rewrite history with git filter-repo
- Check the secret scanning alert, then close it
Hint
The leaked key must stop working before anything else.Try it
git filter-repo: A separate tool that rewrites history, for example to wipe a file from every commit. rewrites every commit. It is a separate tool you install. Build the command that wipes .env from all history.
Tap the pieces in the right order.
Predict
You rewrote history and force-pushed. But you never rotated the old key. Is it safe now?
Pick one answer.
Check
Good move, or needs work? Swipe each one.
Swipe right for good, left for needs work. Or use the buttons.
Rotate the key right away
You did it!
You can now handle a leaked key in the right order.
Go deeper (optional)
Rotating is the must. Rewriting history is extra clean-up, and it changes every later commit id. Key inside a normal file, like app.js? Use --replace-text with a list of secrets. --sensitive-data-removal needs git filter-repo 2.47 or newer. Old pull requests may still show the key. GitHub Support can help clear those.
Bahasa Melayu
Alamak. Commit ini dah masuk ke repo awam sejam yang lalu. Ia ada .env dan kuncinya. Anggap ada orang dah salin.
Langkah pertama: rotate (tukar) kunci itu. Pergi ke servis yang beri kunci itu. Batalkan kunci lama dan buat kunci baru. Sekarang salinan yang bocor tak berguna lagi.
Ada orang cuma berhenti jejak .env dalam commit baru. Kunci dah hilang? Leret balik ke masa lalu.
Commit terbaru tiada .env. Satu langkah ke belakang, kunci masih ada. Sesiapa pun boleh tengok.
Ini pelan penyelamat penuh. Susun ikut urutan, langkah pertama di atas.
git filter-repo tulis semula setiap commit. Ia alat berasingan yang anda pasang sendiri. Bina arahan yang padam .env dari seluruh sejarah.
Anda dah tulis semula sejarah dan force-push. Tapi kunci lama tak pernah di-rotate. Selamatkah sekarang?
Langkah bagus, atau perlu baiki? Leret setiap satu.
Kini anda boleh uruskan kunci yang bocor ikut urutan yang betul.
You finished this before. Practice is always welcome!
Official docs: Removing sensitive data from a repository · About secret scanning · git rm
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?