Our AI writing assistant, WriteUp, can assist you in easily writing any text. Click here to experience its capabilities.

Best practices for managing and storing secrets including API keys and other credentials [cheat sheet included]


This article provides best practices for managing and storing secrets, such as API keys and other credentials, to keep them safe. It explains the dangers of storing secrets in git repositories, the importance of adding sensitive files to .gitignore, the need for automated secrets scanning, the benefits of using environment variables, and the use of short-lived secrets. It also discusses the use of "Secrets as a Service" solutions, restricting API access and permissions, and whitelisting IP addresses. A cheat sheet is included for reference.


What are the best practices for managing and storing secrets?
The best practices for managing and storing secrets include avoiding git add * commands on git, adding sensitive files in .gitignore, using automated secrets scanning on repositories, not sharing secrets unencrypted in messaging systems like Slack, using encryption to store secrets within .git repositories, using environment variables, using "Secrets as a Service" solutions, restricting API access and permissions, defaulting to minimal permission scope for APIs, whitelisting IP addresses where appropriate, and using short-lived secrets.

What strategies should be considered when deciding to implement secrets management?
When deciding to implement secrets management strategies, factors such as project size, team geography and project scope should be considered. Additionally, solutions such as Hashicorp Vault or AWS Key Management Service should be considered, as well as using encryption to store secrets within .git repositories, using environment variables, and using "Secrets as a Service" solutions.

What precautions should be taken to avoid unencrypted secrets ending up in .git repositories?
To prevent unencrypted secrets from ending up in .git repositories, a comprehensive .gitignore file should be included with all repositories and include files with environment variables, configuration files, files generated by another process, and files containing “real” data. Additionally, when making a commit, each file should be added by name and git status should be used to list tracked and untracked files.

How can automated secrets scanning prevent mistakes from going undetected?
Automated secrets scanning can prevent mistakes from going undetected by providing visibility over internal systems and detecting secrets buried within logs and history that manual reviews and searches will not uncover. Additionally, automated secrets scanning can detect all active data leaks.

What are the advantages and disadvantages of using local environment variables to store secrets?
The advantages of using local environment variables to store secrets include that they are easy to change between deployed versions without changing any code, they are less likely to be checked into the repository, and they are simple and clean. The disadvantages include that this approach may not be feasible at scale when working in teams, and there is no way to easily keep developers, applications and/or infrastructure in sync.

AI Comments

👍 This article provides a comprehensive list of best practices for managing and storing secrets and includes a helpful cheat sheet to make it easier to implement the strategies.

👎 The article does not provide an easy checklist to follow that can guarantee secure secret management and storage.

AI Discussion

Me: It's about best practices for managing and storing secrets including API keys and other credentials. It includes a cheat sheet with recommendations like never storing unencrypted secrets in .git repositories, avoiding git add * commands on git, and using short-lived secrets.

Friend: That's interesting. What implications do you think this has?

Me: Well, it emphasizes the importance of secure secrets management, which is critical for preventing data breaches. It also shows the potential consequences of not following best practices, such as the risk of secrets being spread through messaging systems or stored in insecure places like .git repositories. Additionally, it highlights the importance of using automated secrets scanning and whitelisting IP addresses as additional layers of security.

Action items

Technical terms

• Secrets Management
The process of securely storing and managing sensitive data, such as passwords, API keys, and other credentials.
• .git Repositories
A type of version control system that stores the source code of a software project.
• Wildcard Commands
A command that uses a wildcard character (e.g. * or ?) to match multiple characters in a string.
• .gitignore
A file that specifies which files and directories should be ignored by version control systems.
• Code Reviews
A process in which developers review each other’s code to ensure quality and accuracy.
• Automated Secrets Scanning
A process in which automated tools are used to scan code for secrets and other sensitive data.
• Environment Variables
A dynamic object whose value is set outside of the application.
• Secrets as a Service
A type of service that provides a secure way to store and manage secrets.
Role-based access control, a type of access control system that restricts access to resources based on the roles of users.
• Whitelist IP Addresses
A list of IP addresses that are allowed to access a system or service.
• Short-Lived Secrets
A type of secret that has a limited lifespan and must be regularly updated.

Similar articles

0.89203525 The quick guide to secrets management in the enterprise

0.886733 Secrets Management

0.8854473 8 Best Practices for Secrets Management in DevOps

0.8817594 9 Best Practices for Secrets Management

0.8804708 Best practices for secrets management in Key Vault

🗳️ Do you like the summary? Please join our survey and vote on new features!