You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/security/fundamentals/secrets-best-practices.md
+100-4Lines changed: 100 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
---
2
-
title: Best practices for protecting secrets - Microsoft Azure | Microsoft Docs
2
+
title: Best practices for protecting secrets - Microsoft Azure
3
3
description: This article links you to security best practices for protecting secrets.
4
4
services: security
5
5
author: TerryLanfear
@@ -13,15 +13,111 @@ ms.date: 11/09/2023
13
13
ms.author: terrylan
14
14
15
15
---
16
+
16
17
# Best practices for protecting secrets
17
-
This article provides guidance on protecting secrets. Follow this guidance to help ensure you do not log sensitive information, such as credentials, into GitHub repositories or continuous integration/continuous deployment (CI/CD) pipelines.
18
18
19
-
## Best practices
19
+
This article provides guidance on protecting your secrets and reducing the risk of unauthorized access. Follow this guidance to help ensure you do not store sensitive information such as credentials in code, GitHub repositories, logs, continuous integration/continuous deployment (CI/CD) pipelines, and so forth. The guidance in this article is compiled from recommendations of individual services, as well as from the [Microsoft Cloud Security Benchmark](/security/benchmark/overview) (MCSB).
20
+
21
+
## General best practices
22
+
23
+
In today's digital landscape, securing sensitive information such as application credentials and secrets is paramount. A breach can lead to severe consequences, including data loss, financial penalties, and damage to reputation. Implementing a comprehensive secret management strategy is essential to mitigating these risks.
24
+
25
+
### Conduct an audit to identify secrets
26
+
27
+
Before you can secure your secrets, you need to know where they are. Conducting a thorough audit of your systems and applications helps identify all the sensitive information that needs protection. This includes passwords, API keys, connection strings, and other credentials. Regular audits ensure that new secrets are accounted for and existing ones are properly managed.
28
+
29
+
It's important to note that even dynamically created secrets, such as OAuth tokens, which may be temporary, still need to be safeguarded with the same rigor as long-term secrets.
30
+
31
+
### Avoid hardcoding secrets
32
+
33
+
Embedding secrets directly into your code or configuration files is a significant security risk. If your codebase is compromised, so are your secrets. Instead, use environment variables or configuration management tools that keep secrets out of your source code. This practice minimizes the risk of accidental exposure and simplifies the process of updating secrets.
34
+
35
+
Additionally, integrating secret retrieval into your automated deployment pipeline and using secret injection patterns can prevent secrets from being accidentally exposed in logs or version control, further enhancing the security of your deployment process.
36
+
37
+
See:
38
+
39
+
-[Recommendations for protecting application secrets](/azure/well-architected/security/application-secrets)
40
+
41
+
### Use secure key stores
42
+
43
+
Leveraging secure key stores ensures that your secrets are stored in a secure, encrypted location. Services like Azure Key Vault provide robust security features, including access control, logging, and automatic rotation. For even greater security, particularly for highly sensitive or critical secrets, consider using Hardware Security Modules (HSMs), which offer enhanced protection compared to software-based secret stores. This approach centralizes the management of your secrets and reduces the risk of unauthorized access.
Regularly scanning your codebase for embedded secrets can prevent accidental exposure. Tools like Azure DevOps Credential Scanner and GitHub's native secret scanning feature can automatically detect and alert you to any secrets found in your repositories. Integrating these tools into your CI/CD pipeline ensures continuous monitoring. It is crucial to treat any secret found by these scanning tools as compromised, which means it should be immediately revoked and replaced to maintain the integrity of your security posture.
Managed identities in Azure provide a secure way for applications to authenticate to Azure services without storing credentials in the code. By enabling managed identities for Azure resources, you can securely access Azure Key Vault and other services, reducing the need to handle secrets manually. This approach not only minimizes the creation of secrets but also reduces the surface area for potential breaches, as the responsibility for managing credentials is delegated to the platform.
Follow the principle of least privilege by applying granular access control to your secrets. Use Azure role-based access control (RBAC) to ensure that only authorized entities have access to specific secrets. Regularly review and update access permissions to prevent unauthorized access. It's also advisable to implement distinct roles such as user, administrator, and auditor to manage access to secrets, ensuring that only trusted identities have the appropriate level of permission.
Secrets are susceptible to leakage or exposure over time. Regularly rotating your secrets reduces the risk of unauthorized access. Azure Key Vault supports automatic rotation for certain secrets, but for those that cannot be automatically rotated, establish a manual rotation process and ensure they are purged when no longer in use. Automating the secret rotation process and building redundancy into your secret management can ensure that rotation does not disrupt service availability. Implementing retry logic and concurrent access patterns in your code can help minimize issues during the rotation window.
80
+
81
+
See:
82
+
83
+
-[Rotate secrets in Azure Key Vault](/azure/key-vault/secrets/rotate)
84
+
85
+
### Monitor and log access
86
+
87
+
Enable logging and monitoring for your secret management system to track access and usage. Use services like Azure Monitor and Azure Event Grid to monitor all activities related to your secrets. This provides visibility into who accessed your secrets and helps detect any suspicious behavior or potential security incidents. Maintaining detailed audit trails is critical for inspecting and validating access to secrets, which can help prevent identity theft, avoid repudiation, and reduce unnecessary exposure.
Reduce the exposure of your secrets by implementing network isolation. Configure firewalls and network security groups to restrict access to your key vaults. Only allow trusted applications and services to access your secrets, minimizing the attack surface and preventing unauthorized access. Additionally, consider using multiple key vaults to create isolation boundaries for different components, ensuring that if one component is compromised, it cannot gain control of other secrets or the entire workload.
98
+
99
+
See:
100
+
101
+
-[Isolation in the Azure Public Cloud](isolation-choice.md)
102
+
103
+
### Encrypt secrets at rest and in transit
104
+
105
+
Ensure that your secrets are encrypted both at rest and in transit. Azure Key Vault automatically encrypts secrets at rest using industry-standard encryption algorithms. Additionally, use secure communication protocols like HTTPS to encrypt data in transit between your applications and the key vault. This approach ensures that your secrets remain protected from unauthorized access during storage and transmission.
106
+
107
+
See:
108
+
109
+
-[Encryption at rest and in transit](encryption.md)
110
+
111
+
### Safe Distribution of Secrets
112
+
113
+
When distributing secrets, ensure they are shared securely within and outside the organization. Use tools designed for secure sharing and include secret recovery procedures in your disaster recovery plans. If a key is compromised or leaked, it should be regenerated immediately. To further enhance security, use distinct keys for each consumer rather than sharing keys, even if they have similar access patterns. This practice simplifies key management and revocation, ensuring that compromised keys can be revoked without affecting other consumers.
114
+
115
+
## Service-specific best practices
20
116
21
117
These best practices are intended to be a resource for IT pros. This might include designers, architects, developers, and testers who build and deploy secure Azure solutions.
- Azure Key Vault: [Centralize storage of application secrets](/azure/key-vault/general/overview)
120
+
- Azure Key Vault: [Centralize storage of application secrets](../../key-vault/general/overview.md)
25
121
- Azure Communications Service: [Create and manage access tokens](../../communication-services/quickstarts/identity/access-tokens.md)
26
122
- Azure Service Bus: [Authenticate and authorize an application with Microsoft Entra ID to access Azure Service Bus entities](../../service-bus-messaging/authenticate-application.md)
27
123
- Azure App Service: [Learn to configure common settings for an App Service application](../../app-service/configure-common.md)
0 commit comments