API Key Best Practices
API Key Best Practices
For Developers
1. Store Keys Securely
-
β Store in environment variables (
.envfile) -
β Use secret management tools (AWS Secrets Manager, Vault)
-
β Never commit keys to version control
-
β Never hardcode keys in source code
-
β Never share keys via email or chat
2. Use Minimal Permissions
-
β Create separate keys for different applications
-
β Grant only required permission scopes
-
β Donβt use full-access keys for single-purpose applications
3. Rotate Keys Regularly
-
β Rotate keys every 90 days (recommended)
-
β Rotate immediately if key compromised
-
β Test new key before revoking old key
4. Monitor Usage
-
β Review API key usage regularly
-
β Set up alerts for unusual activity
-
β Investigate unexpected errors
5. Handle Errors Gracefully
-
β Implement exponential backoff for rate limit errors
-
β Log authentication failures
-
β Retry failed requests with backoff
For PenguinMails Administrators
1. Enforce Security Policies
-
β Require HTTPS for all API requests
-
β Implement rate limiting per tier
-
β Monitor for suspicious activity
2. Audit Regularly
-
β Review audit logs weekly
-
β Investigate anomalies
-
β Revoke unused keys
3. Educate Users
-
β Provide security best practices documentation
-
β Send reminders for key rotation
-
β Offer security training