.secrets [ DELUXE ✯ ]
First, a semantic distinction. Many developers confuse the .env file with the .secrets file. While they look similar (both are plain text KEY=value pairs), their purpose is fundamentally different.
The .secrets file is a contract. It says: "The contents of this file must never leave the local machine or the secure vault. They must not appear in logs. They must not be stored in Git history."
Before you even type the word "secret" into a file, you need pre-commit hooks. .secrets
In your pipeline (e.g., GitHub Actions), you do not store the .secrets file in the repo. Instead, you store each secret as an encrypted Repository Secret. During the build, the pipeline reads the encrypted variables and dynamically creates a .secrets file inside the ephemeral container.
# .github/workflows/deploy.yml
- name: Create .secrets file
run: |
echo "DATABASE_PASSWORD=$ secrets.DB_PASS " >> .secrets
echo "API_KEY=$ secrets.API_KEY " >> .secrets
Add a rule to your .gitignore (or the ignore file of whatever VCS you use): First, a semantic distinction
# .gitignore
.secrets
.secrets/
.secrets.*
If you’re using a folder:
/.secrets/
Safety check: After adding the rule, run
git statusto verify that the file is listed under “untracked files” and not under “changes to be committed”. Add a rule to your
DATABASE_URL=postgresql://admin:SuperStrongP@ssw0rd!@prod-db:5432/main DATABASE_REPLICA_PASSWORD=ReplicaKey_9x2#kLp
Assume you’ve found a .secrets file during an audit or while debugging. Never view it on a shared screen or save plaintext to an insecure location. Use these steps: