GitHub Secrets Best Practices
- Never commit secrets to code
- Use environment-specific secrets
- Rotate secrets regularly
- Use least privilege
Required Secrets for Rails
yaml
1# Repository Secrets
2DATABASE_URL
3REDIS_URL
4SECRET_KEY_BASE
5RAILS_MASTER_KEY
6
7# Deployment Secrets
8HEROKU_API_KEY
9RAILWAY_TOKEN
10AWS_ACCESS_KEY_ID
11AWS_SECRET_ACCESS_KEYUsing RAILS_MASTER_KEY
yaml
1steps:
2 - name: Decrypt credentials
3 env:
4 RAILS_MASTER_KEY: ${{ secrets.RAILS_MASTER_KEY }}
5 run: bundle exec rails credentials:showGenerating Secrets
bash
1# Generate secret key
2rails secret
3
4# Generate master key
5EDITOR=vim rails credentials:editOrganization Secrets
Share secrets across repositories:
- Go to Organization Settings
- Click Secrets and Variables
- Create organization secret
- Select repository access
Dependabot Secrets
For automated dependency updates:
yaml
1# Dependabot can access these
2name: dependabot-secrets