Managing Certificates Secrets and Keys
Complete the full lesson to earn 25 points — 50 with Pro
Work through each section, then tap “Mark as Complete” on the last one.
✦ Skip the page breaks, the wait, and see fewer ads — read each lesson on a single page with Pro
Managing Certificates, Secrets, and Keys in Microsoft Cloud Environments
Introduction: The Foundation of Cloud Security
In the modern cloud landscape, the perimeter of your network is no longer a physical firewall or a gated office building. Instead, the perimeter has shifted to the identity of your services and the security of the digital credentials that grant them access. Whether you are running applications on Azure, managing hybrid workloads, or orchestrating containers, your infrastructure relies on a silent, invisible backbone: certificates, secrets, and cryptographic keys.
Managing these assets is not just an administrative task; it is the cornerstone of cloud governance. If a developer accidentally commits a database connection string to a source code repository or an administrator leaves a root certificate unrotated, the entire security posture of your organization is compromised. Microsoft Defender for Cloud and Microsoft Sentinel provide the tools to monitor, detect, and remediate these risks, but the responsibility for governing these secrets begins with your configuration and policy design.
This lesson explores how to manage these sensitive assets effectively, how to implement lifecycle policies, and how to use Microsoft’s security stack to ensure that your secrets, keys, and certificates remain protected, rotated, and audited. By the end of this guide, you will understand how to transition from reactive firefighting to proactive governance.
Understanding the Triad: Secrets, Keys, and Certificates
Before diving into governance policies, it is essential to define exactly what we are protecting. In the context of Azure Key Vault and general cloud security, these three terms are often used interchangeably, but they serve distinct functions.
1. Secrets
Secrets are essentially small pieces of data that provide access to other resources. Common examples include database connection strings, API keys for third-party services, storage account access keys, and passwords. Secrets are "static"—they do not expire unless you manually change them, and they are usually treated as simple strings of text.
2. Keys
Cryptographic keys are used for encryption and decryption processes. This includes data-at-rest encryption (such as Azure Disk Encryption) or signing data to ensure its integrity. Unlike secrets, keys are mathematical constructs that follow specific algorithms like RSA or Elliptic Curve. They are the "locks" that protect your data, and their governance is tied to regulatory compliance standards like FIPS 140-2.
3. Certificates
Certificates are digital identity documents. They combine a public key with identity information and are signed by a Certificate Authority (CA). They are used primarily for establishing encrypted communication channels (TLS/SSL) and verifying the identity of services. Unlike secrets, certificates have a hard expiration date, making their lifecycle management a recurring operational requirement.
Callout: The Difference Between Keys and Secrets While both keys and secrets are stored in Key Vault, they serve different purposes. A secret is a "key to the kingdom" that grants access, whereas a key is a "mathematical tool" used to scramble data so it cannot be read by unauthorized parties. Governance policies for keys often focus on rotation frequency and hardware security module (HSM) backing, while policies for secrets focus on access control and preventing hard-coded exposure.
Governance Through Azure Key Vault
Azure Key Vault is the central repository for managing these assets. Governance begins here. If you are not using Key Vault to centralize your secrets, you are likely managing them in configuration files, environment variables, or worse, hard-coded directly into your application source code.
Implementing Least Privilege Access
The first rule of cloud governance is the principle of least privilege. You should never grant an application or a user access to the entire Key Vault if they only need one specific secret. Azure Key Vault provides two primary authorization models:
- Azure Role-Based Access Control (RBAC): This is the modern standard. You assign roles like "Key Vault Secrets User" to specific managed identities. This allows you to audit access at a granular level through Azure Monitor.
- Access Policies: The legacy model. While still widely used, it is less granular than RBAC. Access policies are applied at the vault level rather than the object level.
Tip: Always prefer Azure RBAC over Vault Access Policies. RBAC integrates better with Microsoft Sentinel and provides more detailed activity logs, which are essential for security investigations.
Centralized Secret Storage
To govern secrets effectively, they must be centralized. If your organization has 50 different applications, each with its own local configuration file, you have no way to enforce a rotation policy. By moving these to Key Vault, you can:
- Enable diagnostic logging to see exactly who accessed a secret and when.
- Use Managed Identities to eliminate the need to store "credentials to access credentials."
- Implement centralized auditing to satisfy compliance requirements.
Establishing Lifecycle Policies
Lifecycle management is the process of creating, using, rotating, and retiring secrets and certificates. Without an automated lifecycle, you will inevitably face "expiration outages," where a service stops working because a certificate expired overnight.
Automated Rotation
Azure Key Vault supports automated rotation for certain types of secrets (like storage account keys) and certificates. For custom secrets, you can use Azure Functions to trigger a rotation workflow. A robust rotation policy should include:
- The Grace Period: When a secret is rotated, the old version should remain available for a short window to ensure that any distributed applications have time to refresh their cache.
- Notification: Configure Azure Monitor alerts to notify your team via email or ITSM integration (like ServiceNow) 30 days, 15 days, and 7 days before an expiration event.
- Version Control: Key Vault tracks versions of every secret. If a new version causes an application failure, you should be able to roll back to the previous version instantly.
Certificate Management Best Practices
Certificates are particularly dangerous because they have a fixed expiration date. If a certificate expires, your HTTPS traffic stops, and your users see security warnings. To govern this:
- Use Managed Certificates: Whenever possible, use Azure-managed certificates for App Service or Application Gateway. Microsoft handles the renewal automatically.
- Standardize CA usage: Centralize your certificate requests through a single internal or public CA to avoid "shadow IT" certificates that no one knows how to manage.
- Automated Monitoring: Use Microsoft Defender for Cloud to track the expiration dates of all certificates across your subscriptions.
Leveraging Microsoft Defender for Cloud
Microsoft Defender for Cloud is your primary tool for identifying gaps in your governance policy. It provides a "Secure Score" that tells you exactly where your secrets management is failing.
Identifying Unprotected Secrets
Defender for Cloud scans your environment for common misconfigurations. It will alert you if:
- A Key Vault has "purge protection" disabled (a critical data loss risk).
- Access to the Key Vault is allowed from public internet IP addresses rather than private endpoints.
- A secret has been inactive for an extended period, suggesting it might be orphaned.
Practical Example: Detecting Risky Configurations
Imagine you have an engineer who creates a Key Vault for testing but forgets to restrict access to the public internet. Defender for Cloud will flag this as a "High" severity recommendation: "Key Vaults should have public network access disabled."
To remediate this:
- Navigate to the Recommendation blade in Defender for Cloud.
- Select the "Key Vaults should have public network access disabled" policy.
- Click Remediate to launch a guided deployment of a Private Endpoint, which ensures the Key Vault is only reachable from within your virtual network.
Warning: Be careful when enabling "Purge Protection" in Key Vault. Once enabled, it cannot be turned off. This is a security feature to prevent accidental deletion, but it also means you cannot reclaim the name of a deleted vault for the duration of the retention period.
Integrating with Microsoft Sentinel for Security Operations
While Defender for Cloud provides the state of your governance, Microsoft Sentinel provides the intelligence to detect active threats against your secrets.
Monitoring Access Patterns
Sentinel allows you to ingest logs from Azure Key Vault. By creating a Kusto Query Language (KQL) workbook, you can visualize who is accessing your secrets. You should look for anomalies such as:
- A service account accessing a secret at 3:00 AM when it usually only accesses it during business hours.
- A single identity accessing an unusually high number of secrets in a short time frame (potential exfiltration).
Sample KQL Query for Suspicious Access
You can use the following query in Sentinel to detect suspicious Key Vault activity:
AzureActivity
| where OperationNameValue == "MICROSOFT.KEYVAULT/VAULTS/SECRETS/READ"
| summarize Count = count() by Caller, bin(TimeGenerated, 1h)
| where Count > 50
This query identifies any user or service principal that has performed more than 50 secret read operations in a single hour. This is a classic indicator of a credential harvesting attack, where an attacker attempts to dump all secrets from a vault.
Step-by-Step: Implementing a Governance Workflow
Let’s walk through a real-world scenario: Securing a database connection string for a production application.
Step 1: Create the Key Vault
Ensure the vault is created with "Soft Delete" and "Purge Protection" enabled. These are mandatory for any production workload to recover from accidental deletion.
Step 2: Configure Access
Assign a Managed Identity to your application. Go to the Key Vault, select Access Configuration, and switch to Azure RBAC. Assign the "Key Vault Secrets User" role to your application's Managed Identity.
Step 3: Store the Secret
Upload the database connection string as a secret. Give it a descriptive name like Prod-Database-ConnectionString. Set an expiration date if your internal policy mandates quarterly rotation.
Step 4: Configure Alerts
In Azure Monitor, set up an alert rule on the SecretGet operation. If an unauthorized user attempts to access the secret, the alert should trigger a workflow in Azure Logic Apps to disable the user's account automatically.
Step 5: Regular Audit
Set up a recurring task in Defender for Cloud to export your "Secure Score" report. Review this report monthly to identify any new Key Vaults that were created without the proper governance settings.
Common Pitfalls and How to Avoid Them
Even with the best tools, organizations often fall into traps that undermine their security.
1. Hard-Coding Secrets
The most common mistake is keeping secrets in code. Even if that code is in a private repository, it is a liability.
- The Fix: Use environment variables that pull values from Key Vault at runtime. Never commit a
.envfile or aweb.configfile to source control.
2. Over-permissioning Managed Identities
"Just give it Contributor access so we don't have to troubleshoot permissions." This is the death of security.
- The Fix: Use the "Least Privilege" principle. If a service only needs to read a secret, give it "Secrets User" access. Never use "Contributor" access for production applications.
3. Ignoring Service Principal Expirations
Service Principals are used to authenticate applications. If the secret/certificate associated with the Service Principal expires, the application dies.
- The Fix: Use Managed Identities whenever possible. Managed Identities handle their own rotation automatically, eliminating the need for you to manage the underlying credentials.
Callout: The "Managed Identity" Advantage A Managed Identity is an identity automatically managed by Azure Active Directory. Because the identity is tied to the Azure resource itself, you don't have to manage any credentials. There is no "secret" to leak, because the authentication is handled by the Azure platform internally. This is the single most effective way to improve your secret governance.
Comparison Table: Governance Tools
| Feature | Azure Key Vault | Defender for Cloud | Microsoft Sentinel |
|---|---|---|---|
| Primary Goal | Secure storage | Compliance & Posture | Threat detection |
| Action | Stores the secret | Recommends policy | Alerts on anomalies |
| Visibility | Per-vault metrics | Subscription-wide | Cross-platform logs |
| Automation | Rotation triggers | Remediation scripts | Incident response |
Best Practices for Enterprise Governance
To maintain a high standard of security, you should codify your governance requirements into your Infrastructure as Code (IaC) templates.
1. Use Policy-as-Code
Use Azure Policy to enforce settings at the subscription level. For example, you can create a policy that denies the creation of any Key Vault that does not have "Enable Purge Protection" set to true. This prevents developers from accidentally creating insecure vaults in the first place.
2. Implement "Break Glass" Accounts
You must have a way to access your secrets if your primary identity management system (like Entra ID) fails. Create a "break glass" account—a cloud-only, highly secured account with MFA and physical security keys—that is kept in a safe and used only during emergency scenarios.
3. Rotate Keys Regularly
For cryptographic keys used in data encryption, rotation should be automated. If a key is compromised, rotation limits the amount of data that can be decrypted by an attacker. Aim for a rotation cycle of 90 days for production keys.
4. Separate Environments
Never share a Key Vault between Development, Testing, and Production. If a developer needs access to the Dev vault to debug, they should not have access to the Production vault. This isolation ensures that a compromise in a lower environment does not lead to a production breach.
FAQ: Common Questions on Secret Governance
Q: How do I handle secrets in a hybrid environment? A: Use Azure Arc to extend your governance policies to on-premises servers. You can use the Key Vault extension for Arc-enabled servers to securely provide secrets to applications running outside of Azure.
Q: What if I need to share a secret across regions? A: Use Key Vault replication. You can replicate your vault to a secondary region for high availability, ensuring that your secrets are always available even if a primary region experiences an outage.
Q: How often should I audit my secrets? A: Automated auditing should be continuous via Defender for Cloud. Manual reviews should occur at least quarterly to ensure that the access lists (who has access to what) are still accurate and that no former employees still have permissions.
Q: Is it safe to store secrets in a GitHub Action? A: Only if you use OIDC (OpenID Connect) for authentication. Never store long-lived service principal secrets in GitHub Secrets if you can avoid it. OIDC allows your action to request a short-lived token from Azure, which is far more secure.
Key Takeaways
Managing certificates, secrets, and keys is a continuous process that requires a combination of technical configuration, automated monitoring, and strict organizational policy. By following these principles, you can significantly reduce your attack surface and ensure operational stability.
- Centralize Everything: Move all credentials, API keys, and certificates into Azure Key Vault. Eliminate local configuration files and hard-coded secrets immediately.
- Automate Lifecycle Management: Use rotation policies for secrets and managed certificates for TLS/SSL. Do not rely on manual reminders for expiration dates.
- Enforce Least Privilege: Use Azure RBAC to grant access at the object level. Avoid global "Contributor" roles at all costs.
- Codify Your Security: Use Azure Policy to prevent the creation of insecure resources. If a vault doesn't meet your security standards, it shouldn't exist.
- Monitor with Sentinel: Treat your Key Vault logs as a critical security data source. Detect and respond to anomalous access patterns before they become a data breach.
- Prefer Managed Identities: Whenever possible, use Managed Identities to remove the need for credentials entirely. This is the gold standard for cloud-native security.
- Plan for Recovery: Always enable "Purge Protection" and "Soft Delete" to prevent accidental data loss, and maintain a "break glass" account for emergency access.
By implementing these strategies, you move from a reactive security posture to a robust, automated governance model. Security in the cloud is not a destination; it is a discipline of constant improvement, regular auditing, and leveraging the native tools provided by the Microsoft ecosystem to protect your most sensitive assets.
Reach the last section to complete this lesson and earn points — you're on section 1 of 11.
- Understanding Azure Built-in Role Assignments
- Understanding Azure Built-in Role Assignments5q
- Managing Custom Azure Roles
- Managing Custom Azure Roles5q
- Creating Custom Microsoft Entra Roles
- Creating Custom Microsoft Entra Roles5q
- Planning Privileged Identity Management
- Planning Privileged Identity Management5q
- Configuring PIM Settings and Assignments
- Configuring PIM Settings and Assignments5q
- Implementing Multi-Factor Authentication
- Implementing Multi-Factor Authentication5q
- Implementing Conditional Access Policies
- Implementing Conditional Access Policies5q
- Advanced Conditional Access Scenarios
- Advanced Conditional Access Scenarios5q
- Managing Enterprise Application Access
- Managing Enterprise Application Access5q
- Managing OAuth Permission Grants
- Managing OAuth Permission Grants5q
- Configuring App Registration Permission Scopes
- Configuring App Registration Permission Scopes5q
- Managing Service Principals
- Managing Service Principals5q
- Managing Managed Identities
- Managing Managed Identities5q
- Planning and Implementing NSGs
- Planning and Implementing NSGs5q
- Implementing Application Security Groups
- Implementing Application Security Groups5q
- Managing VNets with Virtual Network Manager
- Managing VNets with Virtual Network Manager5q
- Implementing User-Defined Routes
- Implementing User-Defined Routes5q
- Configuring VNet Peering and VPN Gateway
- Configuring VNet Peering and VPN Gateway5q
- Implementing Virtual WAN and Secured Hub
- Implementing Virtual WAN and Secured Hub5q
- Securing VPN and ExpressRoute Connectivity
- Securing VPN and ExpressRoute Connectivity5q
- Monitoring with Network Watcher
- Monitoring with Network Watcher5q
- Implementing Service Endpoints
- Implementing Service Endpoints5q
- Implementing Private Endpoints
- Implementing Private Endpoints5q
- Implementing Private Link Services
- Implementing Private Link Services5q
- Network Integration for App Service and Functions
- Network Integration for App Service and Functions5q
- Network Security for ASE and SQL Managed Instance
- Network Security for ASE and SQL Managed Instance5q
- Implementing TLS for Applications
- Implementing TLS for Applications5q
- Planning and Implementing Azure Firewall
- Planning and Implementing Azure Firewall5q
- Managing Firewall Policies with Azure Firewall Manager
- Managing Firewall Policies with Azure Firewall Manager5q
- Implementing Azure Application Gateway
- Implementing Azure Application Gateway5q
- Implementing Azure Front Door and CDN
- Implementing Azure Front Door and CDN5q
- Implementing Web Application Firewall
- Implementing Web Application Firewall5q
- Implementing Azure DDoS Protection
- Implementing Azure DDoS Protection5q
- Remote Access with Azure Bastion
- Remote Access with Azure Bastion5q
- Implementing Just-in-Time VM Access
- Implementing Just-in-Time VM Access5q
- Configuring AKS Network Isolation
- Configuring AKS Network Isolation5q
- Securing and Monitoring AKS
- Securing and Monitoring AKS5q
- AKS Authentication Configuration
- AKS Authentication Configuration5q
- Security Monitoring for Container Instances and Apps
- Security Monitoring for Container Instances and Apps5q
- Managing Access to Azure Container Registry
- Managing Access to Azure Container Registry5q
- Configuring Disk Encryption Options
- Configuring Disk Encryption Options5q
- Security for Azure API Management
- Security for Azure API Management5q
- Configuring Storage Account Access Control
- Configuring Storage Account Access Control5q
- Managing Storage Account Access Keys
- Managing Storage Account Access Keys5q
- Configuring Access to Azure Files
- Configuring Access to Azure Files5q
- Configuring Access to Azure Blob Storage
- Configuring Access to Azure Blob Storage5q
- Data Protection with Soft Delete and Versioning
- Data Protection with Soft Delete and Versioning5q
- Configuring BYOK and Infrastructure Encryption
- Configuring BYOK and Infrastructure Encryption5q
- Enabling Microsoft Entra Database Authentication
- Enabling Microsoft Entra Database Authentication5q
- Enabling Database Auditing
- Enabling Database Auditing5q
- Implementing Dynamic Data Masking
- Implementing Dynamic Data Masking5q
- Implementing Transparent Data Encryption
- Implementing Transparent Data Encryption5q
- Using Azure SQL Always Encrypted
- Using Azure SQL Always Encrypted5q
- Creating and Assigning Azure Policies
- Creating and Assigning Azure Policies5q
- Interpreting Azure Policy Initiatives
- Interpreting Azure Policy Initiatives5q
- Configuring Key Vault Network Settings
- Configuring Key Vault Network Settings5q
- Configuring Key Vault Access Policies and RBAC
- Configuring Key Vault Access Policies and RBAC5q
- Managing Certificates Secrets and Keys
- Managing Certificates Secrets and Keys5q
- Configuring Key Rotation and Backup
- Configuring Key Rotation and Backup5q
- Implementing Backup Security Controls
- Implementing Backup Security Controls5q
- Using Secure Score and Inventory
- Using Secure Score and Inventory5q
- Managing Compliance Standards
- Managing Compliance Standards5q
- Adding Custom Standards to Defender
- Adding Custom Standards to Defender5q
- Connecting Multi-Cloud Environments
- Connecting Multi-Cloud Environments5q
- Using External Attack Surface Management
- Using External Attack Surface Management5q
- Enabling Cloud Workload Protection Plans
- Enabling Cloud Workload Protection Plans5q
- Configuring Defender for Servers
- Configuring Defender for Servers5q
- Configuring Defender for Databases and Storage
- Configuring Defender for Databases and Storage5q
- Implementing Agentless VM Scanning
- Implementing Agentless VM Scanning5q
- Managing Vulnerability Management for VMs
- Managing Vulnerability Management for VMs5q
- Configuring DevOps Security
- Configuring DevOps Security5q
- Managing Security Alerts
- Managing Security Alerts5q
- Configuring Workflow Automation
- Configuring Workflow Automation5q
- Configuring Data Collection Rules
- Configuring Data Collection Rules5q
- Configuring Sentinel Data Connectors
- Configuring Sentinel Data Connectors5q
- Enabling Analytics Rules in Sentinel
- Enabling Analytics Rules in Sentinel5q
- Configuring Automation in Sentinel
- Configuring Automation in Sentinel5q
Enjoying the courses?
Everything stays free. Pro shows fewer ads, doubles the points you earn on every lesson and quiz so you progress twice as fast, unlocks half of every practice exam — plus full case studies — with the Learn & Exam study modes, and lets you read each lesson on one page.
- ✓ Fewer advertisements
- ✓ 2× points per lesson & quiz
- ✓ 50% of every exam unlocked
- ✓ Learn & Exam modes
- ✓ Distraction-free lessons