Video in progress
You accidentally committed the database password and pushed to GitHub. What do you do first?
First you change the password (rotate it): assume it is already exposed. Then you take it out of the code and move it to the environment or a secret manager, and if needed, clean it out of the history too.
📖 Answer
Most people rush to clean the history first. But the moment you push, bots may have already scanned the secret, and it also remains in forks and CI logs. So the order is:
- Rotate. In the database, in AWS, wherever it is: a new password/key, and delete the old one.
- Remove it from the code:
${DB_PASSWORD}inapplication.yml, and the value in the environment or Vault. - Clean the history (if policy requires it): with
git filter-repoor BFG, then force push and tell the team, since everyone has to clone again.
spring:
datasource:
password: ${DB_PASSWORD}
To prevent it: .env and *-local.yml in .gitignore, a scanner such as gitleaks in a pre-commit hook, and secret scanning turned on in GitHub. A plain git revert does not help here, because the password stays in the old commit.
Sign up to mark studied questions and save your progress.