A team stores database passwords in a `.env` file committed to a private repo. How do you migrate them out?
BeginnerScenarioSecrets and Identity Management
Answer
Situation read → Private does not mean safe. Every clone, fork, laptop and CI cache now holds production credentials.
What I'd do →
- Treat every value in the file as exposed and plan rotation, not just removal.
- Create the secrets in a store (AWS Secrets Manager, Vault, Azure Key Vault):
aws secretsmanager create-secret --name prod/orders/db --secret-string file://db.json. - Change the app or deployment to read from the store (External Secrets Operator, CSI driver or SDK call).
- Rotate each credential, then delete
.envand add it to.gitignore; commit a.env.examplewith placeholders. - Add
gitleaksin pre-commit and CI so it does not come back.
Why → Moving the file without rotating leaves the old values valid in git history forever.
Interview tip → Always say "rotate first, clean history second".
More on Secrets and Identity Management
Your CI pipeline uses long-lived AWS access keys stored as repository secrets. How do you replace them?IntermediateAn auditor asks how often you rotate database credentials. You currently never do. What do you build?IntermediatePods need AWS access. A developer mounted an IAM user's keys as a Kubernetes Secret. What do you propose instead?BeginnerShould you use Kubernetes Secrets, Sealed Secrets, External Secrets Operator or the Secrets Store CSI driver?IntermediateA Slack webhook URL and a Stripe live key were posted in a public GitHub issue. What is your response sequence?BeginnerHow would you set up HashiCorp Vault so Kubernetes workloads authenticate without any static token?Advanced