Azure Tips and Tricks - Remove Azure Secrets committed to GitHub

Remove Azure Secrets committed to GitHub
Remove passwords committed to GitHub on accident
Writing code day after day means secrets, connection strings and more get added to your code accidentally. And if you are like me, they get committed to your GitHub repo and then you have to live in shame. =) In this post, I'll walk you through removing secrets from a GitHub repo that you've already committed the secret to.
Part 1 - Initial setup:
Scenario: You have committed a password with the value of qph@}uC,7cGLBdsX
to your GitHub repo. This password should be confidential and not stored in the code.
How do you fix it?
- Ensure you have the repo on your local disk or clone a fresh copy with HTTPS or SSH. I'll use SSH
git clone [email protected]:mbcrump/crumpbot.git
as a sample. - Clone a copy of your repo that has the secret stored using the mirror option, like the following
git clone --mirror [email protected]:mbcrump/crumpbot.git
. - You'll now have a BARE repo. CD into it with
cd crumpbot.git
and runls -l
to list out the contents on macOS ordir
on Windows.
Below is an example of my repo.
Part 2 - Create a file of passwords that you'd like to remove:
- Create a
passwords.txt
file and place and enter the passwords that you'd like to remove from your GitHub repo.
I created mine on macOS with touch passwords.txt
or echo some-text > passwords.txt
on Windows and added the password that I accidentally committed:
- Save the file.
Part 3 - Install BFG:
Enter BFG (opens new window). According to the author:
BFG is a simpler, faster alternative to git-filter-branch for cleansing bad data out of your Git repository history: Removing Crazy Big Files Removing Passwords, Credentials & other Private data
- Install BFG with
brew install bfg
assuming you have Homebrew installed and using a Mac or download the JAR file if you are on Windows.
Part 4 - Clean up the passwords previously committed:
-
Run
bfg --replace-text passwords.txt crumpbot.git
on Mac orjava -jar bfg.jar --replace-text passwords.txt crumpbot.git
if using the JAR file. -
Below is output from that command:
Part 5 - Pushing to GitHub:
- Run
git reflog expire --expire=now --all && git gc --prune=now --aggressive
as indicated by the output. - Run
git push
to push it to your repo.
Part 6 - Wrap-up and verify your repo was updated successfully:
If you go back to your GitHub repo and look at prior commits, then you should see REMOVED like the following:
I hope this helps someone out there and if you want to stay in touch then I can be found on Twitch, Twitter or GitHub.
Create a trial account today and go and check it out!
Published on:
Learn moreRelated posts
Record Scanner for vinyl collectors cuts costs with Azure Cosmos DB vector search
by Artur Drozdz, Founder of Record Scanner (recordscanner.com) If you’re like me, there’s at least one room in your home with an entire cabine...
🚀 Introducing the New VS Code Extension for Azure Cosmos DB
We’re excited to share that the Azure Databases extension for Visual Studio Code is now officially rebranded as the Azure Cosmos DB extension!...
AI-based T-SQL Refactoring: an automatic intelligent code optimization with Azure OpenAI
This article presents an AI-powered approach to automating SQL Server code analysis and refactoring. The system intelligently identifies ineff...
Azure Boards integration with GitHub Copilot (Private Preview)
Several months ago, GitHub introduced the public preview of its Copilot coding agent, a powerful new capability that allows you to assign GitH...
What is Azure Key Vault and How It Secures Microsoft Dynamics 365 CRM Systems?
Azure Key Vault is a service by Microsoft Azure that helps securely store and manage sensitive information such as API keys, connection string...
Azure AI Foundry Model In Copilot Studio Custom Prompts
Any custom model created in Azure AI Foundry can be used in Copilot Studio. This ... The post Azure AI Foundry Model In Copilot Studio Custom ...
Running Teams PowerShell Cmdlets in Azure Automation
This article describes the prerequisites and how to run cmdlets from the Teams PowerShell module in Azure Automation runbooks. We also conside...