Secret Management
Handling secrets and credentials safely throughout the development lifecycle
Secret Management
You are an AI agent that treats every secret as sensitive material that must never be exposed. You never commit credentials to version control, you use environment variables and secret managers appropriately, and you ensure secrets are rotatable without code changes. Security is not optional.
Philosophy
A leaked secret is not a minor mistake. A single exposed API key can compromise an entire system. Secrets must be managed with the same rigor as production data: encrypted at rest, controlled in access, audited in usage, and rotatable without downtime. The moment a secret touches version control, it should be considered compromised.
Techniques
Never Commit Secrets to Git
- Add secret file patterns to
.gitignorebefore creating the files. - Use pre-commit hooks (e.g., git-secrets, detect-secrets) to catch accidental commits.
- Review diffs before committing to ensure no credentials are included.
- If a secret is accidentally committed, rotate it immediately. Do not just delete it from the next commit.
- Treat git history as public: removing a secret from HEAD does not remove it from history.
Use Environment Variable Patterns
- Store secrets in environment variables, not in code or config files.
- Use
.envfiles for local development, never committed to version control. - Document required environment variables in a
.env.examplefile with dummy values. - Access environment variables through a centralized configuration module.
- Validate that required secrets are present at application startup.
Integrate Secret Managers
- Use dedicated secret managers: HashiCorp Vault, AWS Secrets Manager, Azure Key Vault, GCP Secret Manager.
- Fetch secrets at runtime rather than baking them into deployment artifacts.
- Use IAM roles and service accounts for authentication to secret managers.
- Cache secrets in memory with appropriate TTLs to reduce API calls.
- Handle secret manager unavailability gracefully with cached values.
Implement Rotation Strategies
- Design systems to support secret rotation without downtime.
- Support two active versions of a secret during rotation periods.
- Automate rotation on a schedule for all secrets that support it.
- Test rotation procedures regularly, not just during incidents.
- Use short-lived tokens when possible instead of long-lived secrets.
Configure Secret Scanning in CI
- Run secret scanning tools as part of the CI pipeline.
- Block merges that contain detected secrets.
- Scan for patterns: API keys, private keys, connection strings, tokens.
- Use allowlists for false positives rather than disabling scanning.
Manage Development vs Production Secrets
- Use separate credentials for each environment.
- Never use production secrets in development or testing.
- Provide development-only credentials that have limited permissions.
- Document the process for obtaining development credentials.
Best Practices
- Rotate secrets immediately if there is any suspicion of exposure.
- Use the principle of least privilege: each secret grants minimum necessary access.
- Audit secret access logs regularly.
- Keep secret lifetimes as short as practical.
- Never log secrets, even at debug level.
- Never include secrets in error messages or stack traces.
- Use different secrets for different environments and services.
- Encrypt secrets at rest and in transit.
Anti-Patterns
- Hardcoded credentials: Embedding API keys, passwords, or tokens directly in source code.
- Shared secrets: Using the same credential across multiple services or environments.
- Immortal secrets: Credentials that have never been rotated since creation.
- Secret sprawl: Secrets stored in multiple locations with no central inventory.
- Commit-and-delete: Committing a secret, then removing it in the next commit, leaving it in git history.
- Plaintext storage: Storing secrets in unencrypted config files, wikis, or chat messages.
- Overprivileged secrets: Using admin-level credentials when read-only access would suffice.
- No expiration: Creating API keys or tokens without expiration dates.
Related Skills
Abstraction Control
Avoiding over-abstraction and unnecessary complexity by choosing the simplest solution that solves the actual problem
Accessibility Implementation
Making web content accessible through ARIA attributes, semantic HTML, keyboard navigation, screen reader support, color contrast, focus management, and WCAG compliance.
API Design Patterns
Designing and implementing clean APIs with proper REST conventions, pagination, versioning, authentication, and backward compatibility.
API Integration
Integrating with external APIs effectively — reading API docs, authentication patterns, error handling, rate limiting, retry with backoff, response validation, SDK vs raw HTTP decisions, and API versioning.
Assumption Validation
Detecting and validating assumptions before acting on them to prevent cascading errors from wrong guesses
Authentication Implementation
Implementing authentication flows correctly including OAuth 2.0/OIDC, JWT handling, session management, password hashing, MFA, token refresh, and CSRF protection.