Secret Management
Handling secrets and credentials safely throughout the development lifecycle
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. ## Key Points - Add secret file patterns to `.gitignore` before 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. - Store secrets in environment variables, not in code or config files. - Use `.env` files for local development, never committed to version control. - Document required environment variables in a `.env.example` file with dummy values. - Access environment variables through a centralized configuration module. - Validate that required secrets are present at application startup. - 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.
skilldb get autonomous-agent-skills/secret-managementFull skill: 77 linesSecret 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.
Install this skill directly: skilldb add autonomous-agent-skills
Related Skills
Security Awareness
Security considerations during code generation — avoiding injection vulnerabilities, secrets management, input validation, safe defaults, recognizing insecure patterns, and OWASP top 10 awareness.
Self Correction
How to detect, diagnose, and recover from mistakes during autonomous execution without cascading failures
Semantic Code Search
Finding code by meaning and concept rather than exact text matches
Serverless Patterns
Building serverless applications with Lambda/Cloud Functions, including cold start optimization, event-driven design, state management, and deployment automation.
Session and Cookie Management
Managing sessions and cookies correctly including cookie attributes, session stores, security hardening, consent handling, and token-based alternatives.
Shell Command Safety
Executing shell commands safely and effectively, including proper quoting, exit code handling, avoiding destructive operations, and cross-platform compatibility.