This repository contains sensitive credentials in alert_system.py. Follow these steps BEFORE pushing to GitHub:
Option A: Use the Template (Recommended)
# Backup your credentials locally (not in git)
cp alert_system.py alert_system_BACKUP.py
# Use the template instead
cp alert_system_template.py alert_system.py
# Edit alert_system.py with placeholder valuesOption B: Use Environment Variables
# In alert_system.py, replace hardcoded values with:
import os
CLOUDINARY_NAME = os.environ.get('CLOUDINARY_NAME')
CLOUDINARY_KEY = os.environ.get('CLOUDINARY_KEY')
CLOUDINARY_SECRET = os.environ.get('CLOUDINARY_SECRET')
TWILIO_SID = os.environ.get('TWILIO_SID')
TWILIO_TOKEN = os.environ.get('TWILIO_TOKEN')
YOUR_WHATSAPP_NUMBER = os.environ.get('YOUR_WHATSAPP_NUMBER')Ensure these lines exist in .gitignore:
# Sensitive credentials
alert_system.py
config.py
credentials.json
*.key
*.pem
.env
git status
git diffDO NOT commit if you see real credentials!
# Create .env file (this will NOT be committed)
cat > .env << EOF
CLOUDINARY_NAME=your_cloud_name
CLOUDINARY_KEY=your_api_key
CLOUDINARY_SECRET=your_api_secret
TWILIO_SID=your_account_sid
TWILIO_TOKEN=your_auth_token
TWILIO_FROM_NUMBER=whatsapp:+14155238886
YOUR_WHATSAPP_NUMBER=whatsapp:+1234567890
EOFLoad environment variables:
# At the top of your script
from dotenv import load_dotenv
load_dotenv()Install python-dotenv:
pip install python-dotenvcd /Users/deepak/Downloads/Driver_Monitoring_System
# Initialize git
git init
# Add all files (safe files only due to .gitignore)
git add .
# Check what's being added
git status
# Commit
git commit -m "Initial commit: Driver Monitoring System"- Go to GitHub
- Click New Repository
- Name:
Driver_Monitoring_System - Choose: Public or Private
- DO NOT initialize with README (we already have one)
- Click Create Repository
# Add remote repository
git remote add origin https://github.com/yourusername/Driver_Monitoring_System.git
# Push to GitHub
git branch -M main
git push -u origin mainIf you accidentally pushed credentials:
-
Immediately Revoke All Keys:
- Cloudinary: Dashboard β Settings β Security β Reset API Secret
- Twilio: Console β Settings β API Keys β Deactivate
-
Remove from Git History:
# Install BFG Repo-Cleaner brew install bfg # macOS # or download from: https://rtyley.github.io/bfg-repo-cleaner/ # Remove alert_system.py from history bfg --delete-files alert_system.py # Clean up git reflog expire --expire=now --all git gc --prune=now --aggressive # Force push (WARNING: This rewrites history!) git push origin --force --all
-
Generate New Credentials:
- Get new API keys from Cloudinary
- Get new Auth Token from Twilio
- Update your local
alert_system.py(not in git)
- Use environment variables for all secrets
- Keep
.gitignoreup to date - Review files before committing
- Use
.envfor local development - Store credentials in secure password manager
- Use different credentials for dev/prod
- Commit API keys, tokens, or passwords
- Share credentials in issues or pull requests
- Hardcode secrets in code
- Commit
.envfiles - Use production credentials in development
- Share your
.envfile
# Install git-secrets
brew install git-secrets # macOS
# or: https://github.com/awslabs/git-secrets
# Initialize
git secrets --install
git secrets --register-aws
# Scan repository
git secrets --scanCreate .git/hooks/pre-commit:
#!/bin/sh
# Check for potential secrets
if git diff --cached --name-only | grep -q "alert_system.py"; then
echo "β ERROR: Attempting to commit alert_system.py"
echo "This file contains sensitive credentials!"
exit 1
fi
if git diff --cached | grep -qE "(TWILIO_TOKEN|CLOUDINARY_SECRET|API_KEY).*=.*['\"][^'\"]{10,}"; then
echo "β ERROR: Potential secret detected in commit!"
exit 1
fiMake it executable:
chmod +x .git/hooks/pre-commitFor production environments:
-
Use Cloud Secret Management:
- AWS Secrets Manager
- Google Cloud Secret Manager
- Azure Key Vault
- HashiCorp Vault
-
Set Environment Variables on Server:
# On your server export CLOUDINARY_NAME="your_value" export TWILIO_SID="your_value" # etc.
-
Use Platform-Specific Configuration:
- Heroku: Config Vars
- AWS: Parameter Store
- Docker: Secrets
- Kubernetes: Secrets
Before pushing to GitHub:
- Removed all credentials from code
- Using environment variables or config files
-
.gitignoreincludes sensitive files - Tested that secrets aren't in git history
- Created
.env.examplewith dummy values - Updated README with setup instructions
- Reviewed all files with
git diff - Scanned for secrets with
git secrets
If you're unsure about security:
- Create a private repository first
- Ask for a security review
- Consult GitHub's security guide
Remember: Once credentials are on the internet, assume they're compromised!
Stay safe! π