机密(API 密钥、密码、令牌、加密密钥)必须安全地管理——绝不要在代码中硬编码或提交到版本控制,而应安全地存储和访问。不良的机密管理是导致数据泄露的常见且严重的原因。
基本原则:绝不要硬编码或提交机密
text
❌ NEVER hardcode secrets in source code or commit them to Git:
→ committed secrets are in the repo HISTORY (exposed even if "removed" later)
→ public repos / leaks expose them to attackers (bots scan GitHub for keys constantly)
→ a TOP cause of breaches (leaked AWS keys, database passwords, API tokens)
⚠️ If a secret IS committed/leaked → ROTATE it immediately (it's compromised)
如何正确管理机密
text
✓ ENVIRONMENT VARIABLES → inject secrets at runtime (not in code); keep .env OUT of Git
(.gitignore) — basic approach
✓ SECRETS MANAGERS → HashiCorp Vault, AWS Secrets Manager, Azure Key Vault, etc.:
→ centralized, encrypted, access-controlled, audited, rotatable secret storage
→ the robust approach for production (fetch secrets at runtime)
✓ Cloud/platform secret stores; CI/CD secret stores (for pipeline secrets)
