Secure app configuration data by using Azure App Configuration or Azure Key Vault
Centralized Configuration Management
Azure App Configuration provides a central service for storing and managing application settings and feature flags. This is especially useful for microservices and serverless apps, as it separates configuration from code, preventing errors and making updates easier. For sensitive information like connection strings and API keys, you should use Azure Key Vault, which is a dedicated, secure vault. The two services work together using Key Vault references, which are pointers in App Configuration that tell your application where to find a secret in Key Vault, keeping the actual secrets locked away.
Secure Authentication with Managed Identities
The most secure way for applications to access these services is by using managed identities. These are automatically managed identities within Microsoft Entra ID. A system-assigned identity is tied to a single Azure resource, while a user-assigned identity can be shared. Using managed identities means your application code never contains passwords or connection strings, as Azure handles authentication automatically. You then grant these identities specific roles, like App Configuration Data Reader or Key Vault Secrets User, following the principle of least privilege.
Feature Management and Dynamic Updates
App Configuration includes tools for feature management, allowing you to turn features on or off or roll them out to specific users without redeploying your application. To make this efficient, your app can be configured to watch a sentinel key; it only checks App Configuration for updates when this specific key changes, reducing unnecessary calls. This enables dynamic configuration changes and ensures your app can respond to new settings without requiring a restart.
Secret Lifecycle and Access Control
Secret rotation is the process of regularly updating secrets to limit damage if they are ever exposed. Key Vault supports automatic rotation for many secret types. Access to the vault is controlled through role-based access control (RBAC), which allows you to grant granular permissions (like "read a secret") at different scopes. For added protection, you can use private endpoints to restrict vault access to trusted applications within a specific virtual network, and you should enable monitoring and logging to audit all access to secrets.
Develop code that uses keys, secrets, and certificates stored in Azure Key Vault
Secure Authentication and Authorization
Applications must authenticate securely to Azure Key Vault before accessing keys, secrets, or certificates. The recommended method is using managed identities, which allow Azure resources to authenticate automatically through Microsoft Entra ID without any credentials in your code. Authorization is then handled through RBAC, where you assign specific roles like Key Vault Secrets User to grant only the necessary permissions, such as the ability to retrieve a secret.
Retrieving and Using Secrets
To retrieve a secret in your code, you use the Azure SDKs. You create a SecretClient instance, authenticating it with a credential like DefaultAzureCredential (which works with managed identities). Then you call a method like GetSecretAsync to fetch the secret value. This flow keeps sensitive data out of your source code. For certificates, you retrieve them using a Secret Identifier URL, and services like Azure App Service can automatically sync to the latest version when it's updated in the vault.
For tasks like encryption or digital signing, you use keys stored in Key Vault. The Azure Key Vault client library provides a CryptographyClient for these operations. A common pattern is envelope encryption: your app generates a temporary key to encrypt the data, then uses a key from the vault to encrypt that temporary key. The master key never leaves the vault, which is secured by Hardware Security Modules. Authentication for these operations also uses managed identities or DefaultAzureCredential.
Certificate Management for Secure Communication
Azure Key Vault centrally stores digital certificates needed for SSL/TLS protocols, which encrypt data in transit. This prevents hardcoding certificates in your application. Services like Azure Application Gateway can integrate directly with Key Vault to retrieve certificates for SSL termination, where the encrypted connection ends at the gateway. Key Vault also manages the certificate lifecycle, including renewal, and applications can reference the latest version automatically.
Implement Managed Identities for Azure resources
Understanding Managed Identity Types
Managed Identities provide an automatic way for Azure resources to authenticate to services that support Microsoft Entra authentication, like Azure Key Vault or Azure Storage. There are two types: system-assigned and user-assigned. A system-assigned identity is created directly on a specific Azure resource (like a VM or App Service) and is tied to that resource's lifecycle. A user-assigned identity is created as a standalone Azure resource and can be assigned to one or more other Azure resources, allowing it to be shared.
Enabling and Using Managed Identities
You enable a managed identity directly in the Azure portal or via infrastructure-as-code tools like ARM templates or Bicep. Once enabled, the identity gets a Service Principal in Microsoft Entra ID. Your application code then uses the Azure Identity library (like DefaultAzureCredential in .NET or Python) to get an access token. This library automatically tries several credential sources, including the managed identity, making your code work seamlessly across different environments (local development, Azure, etc.) without changes.
Assigning Permissions to Managed Identities
After creating the identity, you must grant it permissions to access other Azure resources. This is done through role-based access control (RBAC). For example, to allow an App Service to read a secret from Key Vault, you would assign the managed identity the Key Vault Secrets User role on that specific vault. Following the principle of least privilege, you only grant the exact permissions needed for the application to function, such as "read" but not "delete."
Benefits and Security Considerations
Using managed identities removes the need to manage and secure credentials like passwords or client secrets in your application code or configuration files. This drastically reduces the risk of credentials being leaked. Managed identities are automatically rotated and managed by Azure, which improves operational security. They are the recommended authentication method for any Azure service that needs to access another Azure service securely.