Learn how to set up External Key Management (EKM) for Azure OpenAI to control your encryption keys and enhance data security. This detailed guide covers prerequisites, configuration, and key rotation with practical examples.
## Why Use External Key Management (EKM) with Azure OpenAI?
External Key Management (EKM) empowers organizations to take full control over the encryption keys used to protect data at rest in their Azure OpenAI deployments. Unlike relying solely on Microsoft-managed keys, EKM lets you use customer-managed keys (CMK) stored in your own Azure Key Vault. This approach is crucial for compliance with regulations like GDPR, HIPAA, or SOC 2, as it ensures you retain ultimate authority over your sensitive data. In high-stakes environments such as healthcare AI diagnostics or financial forecasting models, EKM minimizes risks by allowing key revocation or rotation without disrupting services.
Real-world application: Imagine a bank deploying OpenAI models for fraud detection. With EKM, if a key is compromised, they can immediately disable it, preventing unauthorized access to model outputs or training data.
## Prerequisites for EKM Setup
Before diving into configuration, ensure your environment meets these requirements:
- **Azure Subscription**: An active subscription with permissions to create Key Vaults, managed HSMs, and Azure OpenAI resources.
- **Azure OpenAI Resource**: Must be deployed in supported regions: East US 2, Sweden Central, North Central US, or UK South (check Azure portal for updates).
- **Key Vault or Managed HSM**: Use a standard or premium tier Key Vault, or a managed Hardware Security Module (HSM) for FIPS 140-2 Level 3 compliance.
- **Permissions**: Owner or Key Vault Crypto Officer role on the Key Vault; Cognitive Services Contributor on the OpenAI resource.
- **Networking**: Key Vault must allow access from Azure OpenAI via private endpoints or firewalls.
Pro tip: For production, always use private endpoints to avoid public internet exposure, reducing attack surfaces.
## Step 1: Create and Configure Your Key Vault with Customer-Managed Keys
Start by setting up a secure Key Vault to house your encryption keys.
1. **Deploy Key Vault**:
- In the Azure portal, search for "Key Vault" and create a new one.
- Select your subscription, resource group, region (match your OpenAI region), and pricing tier (Premium for HSM).
- Enable purge protection and soft-delete for recovery options.
2. **Generate or Import a Key**:
- Navigate to Keys > Generate/Import.
- Choose RSA 2048 or 4096 bits, or EC (P-256/P-384) for performance.
- Set activation/expiration dates and enable key rotation policies.
Example PowerShell snippet to create a key:
```powershell
$keyVaultName = "your-keyvault"
$keyName = "openai-ekm-key"
$resourceGroup = "your-rg"
New-AzKeyVaultKey -VaultName $keyVaultName -Name $keyName -Destination 'Software' -KeyType 'RSA' -KeySize 2048
```
3. **Configure Access Policies**:
- Add a policy for the Azure OpenAI service principal (use `az ad sp show --id <openai-client-id>` to find it).
- Grant "Get, Wrap Key, Unwrap Key" permissions.
## Step 2: Prepare Key Vault for EKM Integration
EKM requires specific Key Vault configurations to integrate seamlessly with Azure OpenAI.
- **Enable EKM Features**: Under Key Vault settings, turn on "External Key Management" if using managed HSM.
- **Set Up Firewall Rules**: Allow inbound traffic from your OpenAI resource's IP ranges or use virtual network service endpoints.
- **Private Endpoint (Recommended)**:
1. Create a private endpoint in your VNet subnet.
2. Link it to the Key Vault's vault URI.
3. Approve the connection in Key Vault networking.
This isolates traffic within Azure's backbone network. For a hands-on example, refer to the [Azure OpenAI EKM sample repository](https://github.com/Azure-Samples/azure-openai-ekm-sample), which includes ARM templates for automated deployment.
## Step 3: Enable EKM on Your Azure OpenAI Resource
Now link your OpenAI resource to the Key Vault.
1. **Via Azure Portal**:
- Go to your Azure OpenAI resource > Encryption.
- Select "Customer-managed key".
- Choose your Key Vault and specific key.
- Save changes (this triggers a brief service interruption for re-encryption).
2. **Using Azure CLI**:
```bash
az cognitiveservices account update \\
--name <openai-resource-name> \\
--resource-group <rg> \\
--key-vault-properties "keyVaultUri=<vault-uri>;keyName=<key-name>;keyVersion="
```
Note: Key version can be left empty for automatic rotation handling.
After enabling, verify status: Data at rest is now encrypted with your CMK. Test by querying models—no functional changes, but enhanced security.
## Step 4: Key Rotation and Management Best Practices
Keys aren't set-it-and-forget-it. Regular rotation maintains security hygiene.
- **Automated Rotation**:
- In Key Vault, create a key rotation policy (e.g., every 90 days).
- Azure OpenAI automatically detects and uses the latest version.
- **Manual Rotation Steps**:
1. Generate a new key version.
2. Update OpenAI resource to point to the new version (optional; auto-versioning handles it).
3. Monitor via Azure Monitor logs for rotation events.
PowerShell for rotation:
```powershell
Set-AzKeyVaultKeyRotationPolicy -VaultName $keyVaultName -KeyName $keyName -TimeBeforeExpiry "P90D"
```
Pitfalls to avoid:
- Rotating without backups can lock data—always test in dev.
- Mismatched regions cause failures.
## Monitoring, Troubleshooting, and Compliance
- **Logging**: Enable diagnostic settings on Key Vault and OpenAI for audit trails. Track "KeyWrap" operations.
- **Common Issues**:
| Issue | Resolution |
|-------|------------|
| Access Denied | Verify service principal permissions. |
| Region Mismatch | Align Key Vault and OpenAI regions. |
| Intermittent Failures | Check firewall/private endpoint status. |
- **Compliance Benefits**: EKM supports FedRAMP High, PCI DSS. Use Azure Policy for enforcement.
## Advanced Scenarios and Samples
For complex setups, explore the [Azure OpenAI EKM sample](https://github.com/Azure-Samples/azure-openai-ekm-sample). It demos:
- Bicep/ARM templates for one-click deployment.
- Multi-region keys.
- Integration with Azure DevOps pipelines.
Real-world: Enterprises like healthcare providers use this for PHI protection in RAG pipelines.
## Conclusion and Next Steps
Implementing EKM transforms Azure OpenAI from a black box to a compliant, customer-controlled powerhouse. Start small in dev, scale to prod, and audit regularly. For updates, monitor Azure announcements—support expands rapidly.
This setup not only secures data but builds trust for AI scaling. Deploy today and own your keys.
---
<div style="text-align: center; margin-top: 2rem;">
<a href="https://help.openai.com/en/articles/20000951-openai-azure-ekm-integration-instructions" target="_blank" rel="noopener noreferrer" class="view-full-resource-btn" style="display: inline-block; background-color: #f97316; color: white; padding: 12px 24px; border-radius: 8px; text-decoration: none; font-weight: 600; transition: background-color 0.2s;">View Full Resource</a>
</div>