- Knowledge Base
- Microsoft Azure
- AI Services
- OpenAI Encryption using Customer-Managed Keys
Ensure that your Microsoft Azure OpenAI service instances are using Customer-Managed Keys (CMKs) instead of Microsoft-managed encryption keys (i.e. default keys used by Microsoft Azure for encryption at rest) in order to have a more granular control over your Azure OpenAI data encryption and decryption process.
This rule resolution is part of the Conformity Security & Compliance tool for Azure.
Microsoft Azure OpenAI automatically encrypts your data at rest. The encryption protects your data and assists in fulfilling your organization's security and compliance requirements. By default, the OpenAI encryption process uses Microsoft-managed keys. However, you can bring your own keys (i.e. Customer-Managed Keys) to fully control who can use the encryption keys and access the encrypted data. Using Customer-Managed Keys (CMKs) also allows you to automatically update the key version used for storage encryption whenever a new version is available.
Audit
To determine if your Microsoft Azure OpenAI service instances are encrypted using Customer Managed Keys (CMKs), perform the following actions:
Using Azure Console
01 Sign in to the Azure Management Console.
02 Navigate to Azure OpenAI blade at https://portal.azure.com/#view/Microsoft_Azure_ProjectOxford/CognitiveServicesHub/~/OpenAI.
03 Select the Azure subscription that you want to examine from the Subscription equals all filter box, and choose Apply.
04 Click on the name (link) of the Azure OpenAI service instance that you want to examine. An OpenAI service instance has Kind set to OpenAI.
05 In the navigation panel, under Resource Management, select Encryption to access the encryption configuration settings available for the selected OpenAI resource.
06 On the Encryption panel, check for the Encryption type configuration setting to determine the type of the encryption key used for the selected resource. If Encryption type is set to Microsoft Managed Keys, encryption at rest using Customer-Managed Keys (CMKs) is not enabled for the selected Microsoft Azure OpenAI service instance.
07 Repeat steps no. 4 – 6 for each Azure OpenAI instance available within the selected subscription.
08 Repeat steps no. 3 – 7 for each subscription created in your Microsoft Azure cloud account.
Using Azure CLI
01 Run cognitiveservices account list command (Windows/macOS/Linux) with custom output filters to list the name and the associated resource group for each Azure OpenAI service instance available in the current subscription:
az cognitiveservices account list --output table --query '[?(kind==`OpenAI`)].{name:name, resourceGroup:resourceGroup}'
02 The command output should return the requested OpenAI service instance identifiers:
Name ResourceGroup --------------------------- ------------------------------ tm-openai-project5-instance cloud-shell-storage-westeurope tm-openai-workspace-server cloud-shell-storage-westeurope
03 Run cognitiveservices account show command (Windows/macOS/Linux) with the name of the Azure OpenAI service instance that you want to examine as the identifier parameter and custom output filters to describe the name of the encryption key used for the selected OpenAI instance:
az cognitiveservices account show --name tm-openai-project5-instance --resource-group cloud-shell-storage-westeurope --query '{"encryptionKey":properties.encryption.keyVaultProperties.keyName}'
04 The command output should return the name of the requested encryption key:
{ "encryptionKey": null }
If the cognitiveservices account show command output returns null for the "encryptionKey" configuration attribute, as shown in the output example above, there is no Customer-Managed Key configured for your OpenAI instance, therefore, encryption at rest using Customer-Managed Keys (CMKs) is not enabled for the selected Microsoft Azure OpenAI service instance.
05 Repeat step no. 3 and 4 for each Azure OpenAI instance available in the selected Azure subscription.
06 Repeat steps no. 1 – 5 for each subscription created in your Microsoft Azure cloud account.
Remediation / Resolution
To enable encryption at rest for your Microsoft Azure OpenAI service instances using Customer-Managed Keys (CMKs), perform the following operations:
Using Azure Console
01 Sign in to the Azure Management Console.
02 Navigate to Azure Key vaults blade at https://portal.azure.com/#blade/HubsExtension/BrowseResource/resourceType/Microsoft.KeyVault%2Fvaults.
03 Choose Create and perform the following actions to create the Azure key vault that will store your new Customer-Managed Key (CMK):
- For Basics, choose the correct subscription and resource group, provide a unique name for the new key vault, then select the Azure cloud region where the vault will be deployed, and the appropriate pricing tier. Configure the vault retention period and enable purge protection. Both soft delete and purge protection must be enabled on the key vault. Choose Next to continue the setup process.
- For Access configuration, select Vault access policy for Permission model, choose Create under Access policies, and follow the setup wizard to create the policy that allows Azure OpenAI to create, get, recover, wrap, and unwrap encryption keys from the new vault. Once the access policy is configured, choose Create to create and attach it to the key vault. (Optional) Configure Azure cloud resource access under Resource access. Choose Next to continue the setup.
- For Networking, configure the network access control for the new key vault. You can connect to your new key vault either publicly, via public IP addresses or service endpoints, or privately, using a private endpoint. Choose Next to continue.
- For Tags, use the Name and Value fields to create tags that will help organize the identity of the key vault. Choose Review + create to validate the key vault setup.
- For Review + create, review the resource configuration details, then choose Create to create your new Azure key vault.
04 Click on the name of the newly created Microsoft Azure key vault.
05 In the resource navigation panel, under Objets, select Keys, then choose Generate/Import to create the Customer-Managed Key required for Azure OpenAI service instance encryption.
06 On the Create a key setup page, provide a unique name for the encryption key in the Name box, set Key type to RSA, RSA key size to 2048, choose an activation and/or expiration date, set the Enabled flag to Yes, then choose Create to generate your new Customer-Managed Key (CMK).
07 Once your new Customer-Managed Key is available, navigate to Azure OpenAI blade at https://portal.azure.com/#view/Microsoft_Azure_ProjectOxford/CognitiveServicesHub/~/OpenAI.
08 Click on the name (link) of the Azure OpenAI service instance that you want to configure.
09 In the navigation panel, under Resource Management, select Encryption to access the encryption configuration settings available for the selected OpenAI resource.
10 On the Encryption panel, perform the following actions:
- For Encryption type select Customer Managed Keys.
- For Encryption key choose Select from Key Vault.
- For Key vault and key choose Select a KeyVault and Key for encryption.
- Select the appropriate Azure subscription from the Subscription dropdown list.
- For Key store type choose Key vault.
- For Key vault select the Azure key vault deployed earlier in the Remediation section.
- For Key choose the Customer-Managed Key (CMK) created earlier in the Remediation section.
- For Version choose Current version.
- Choose Select to save the key vault and key selection.
11 Choose Save to apply the configuration settings.
12 Repeat steps no. 8 - 11 for each Azure OpenAI instance that you want to configure, available within the selected Azure subscription.
13 Repeat steps no. 2 – 12 for each subscription available in your Microsoft Azure cloud account.
Using Azure CLI
01 Run keyvault create command (Windows/macOS/Linux) to create the Microsoft Azure key vault where the required Customer-Managed Key (CMK) will be placed. Both soft delete and purge protection must be enabled on the new key vault:
az keyvault create --name tm-project5-vault --resource-group cloud-shell-storage-westeurope --location westeurope --enabled-for-deployment true --enabled-for-template-deployment true --enable-purge-protection true --retention-days 30 --enable-rbac-authorization false
02 The command output should return the object ID of the new Microsoft Azure key vault:
{ "id": "/subscriptions/abcd1234-abcd-1234-abcd-1234abcd1234/resourceGroups/cloud-shell-storage-westeurope/providers/Microsoft.KeyVault/vaults/tm-project5-vault", "location": "westeurope", "name": "tm-project5-vault", "properties": { "accessPolicies": [ { "applicationId": null, "objectId": "abcdabcd-abcd-abcd-abcd-abcdabcdabcd", "permissions": { "certificates": [ "all" ], "keys": [ "all" ], "secrets": [ "all" ], "storage": [ "all" ] }, "tenantId": "abcd1234-abcd-1234-abcd-1234abcd1234" } ], "createMode": null, "enablePurgeProtection": true, "enableRbacAuthorization": false, "enableSoftDelete": true, "enabledForDeployment": true, "enabledForDiskEncryption": null, "enabledForTemplateDeployment": true, "hsmPoolResourceId": null, "networkAcls": null, "privateEndpointConnections": null, "provisioningState": "Succeeded", "publicNetworkAccess": "Enabled", "sku": { "family": "A", "name": "standard" }, "softDeleteRetentionInDays": 30, "tenantId": "abcd1234-abcd-1234-abcd-1234abcd1234", "vaultUri": "https://tm-project5-vault.vault.azure.net/" }, "resourceGroup": "cloud-shell-storage-westeurope", "systemData": { "createdAt": "2024-06-12T15:48:59.183000+00:00", "createdBy": "", "createdByType": "User", "lastModifiedAt": "2024-06-12T15:48:59.183000+00:00", "lastModifiedBy": "", "lastModifiedByType": "User" }, "tags": {}, "type": "Microsoft.KeyVault/vaults" }
03 Run keyvault set-policy command (Windows/macOS/Linux) with the object ID (i.e. "properties.accessPolicies.objectId") and the name of the newly created key vault as the identifier parameters to assign the right permissions to the selected vault:
az keyvault set-policy --name tm-project5-vault --object-id abcdabcd-abcd-abcd-abcd-abcdabcdabcd --key-permissions create get recover unwrapKey wrapKey --query 'properties.accessPolicies'
04 The command output should return the modified key vault configuration information:
[ { "applicationId": null, "objectId": "abcdabcd-abcd-abcd-abcd-abcdabcdabcd", "permissions": { "certificates": [ "all" ], "keys": [ "recover", "unwrapKey", "get", "create", "wrapKey" ], "secrets": [ "all" ], "storage": [ "all" ] }, "tenantId": "abcd1234-abcd-1234-abcd-1234abcd1234" } ]
05 Run keyvault key create command (Windows/macOS/Linux) to create the Customer-Managed Key (CMK) necessary to encrypt data for your Azure OpenAI service instance:
az keyvault key create --name tm-openai-key --vault-name tm-project5-vault --kty RSA --size 2048 --ops decrypt encrypt sign unwrapKey verify wrapKey --protection software --disabled false --query 'key.kid'
06 The command output should return the URL of the new Customer-Managed Key:
"https://tm-project5-vault.vault.azure.net/keys/tm-openai-key/abcd1234abcd1234abcd1234abcd1234"
07 Run cognitiveservices account update command (Windows/macOS/Linux) to enable encryption at rest with Customer-Managed Keys (CMKs) for the selected Azure OpenAI service instance. Replace the --encryption parameter values with your own information:
az cognitiveservices account update --name tm-openai-project5-instance --resource-group cloud-shell-storage-westeurope --encryption '{ "keySource": "Microsoft.KeyVault", "keyVaultProperties": { "identityClientId": null, "keyName": "tm-openai-key", "keyVaultUri": "https://tm-project5-vault.vault.azure.net", "keyVersion": "abcd1234abcd1234abcd1234abcd1234" } }'
08 The command output should return the configuration information for the configured OpenAI service instance:
{ "id": "/subscriptions/abcd1234-abcd-1234-abcd-1234abcd1234/resourceGroups/cloud-shell-storage-westeurope/providers/Microsoft.CognitiveServices/accounts/tm-openai-project5-instance", "identity": { "principalId": "abcd1234-abcd-1234-abcd-1234abcd1234", "tenantId": "abcd1234-abcd-1234-abcd-1234abcd1234", "type": "SystemAssigned", "userAssignedIdentities": null }, "kind": "OpenAI", "location": "westus", "name": "tm-openai-project5-instance", "properties": { "encryption": { "keySource": "Microsoft.KeyVault", "keyVaultProperties": { "identityClientId": null, "keyName": "tm-openai-key", "keyVaultUri": "https://tm-project5-vault.vault.azure.net", "keyVersion": "abcd1234abcd1234abcd1234abcd1234" } }, ... "isMigrated": false, "locations": null, "migrationToken": null, "networkAcls": { "defaultAction": "Allow", "ipRules": [], "virtualNetworkRules": [] }, "privateEndpointConnections": [], "provisioningState": "Succeeded", "publicNetworkAccess": "Enabled", "quotaLimit": null, "restore": null, "restrictOutboundNetworkAccess": null, "scheduledPurgeDate": null, "skuChangeInfo": null, "userOwnedStorage": null }, "resourceGroup": "cloud-shell-storage-westeurope", "type": "Microsoft.CognitiveServices/accounts" }
09 Repeat steps no. 7 and 8 for each Azure OpenAI instance that you want to configure, available in the selected Azure subscription.
10 Repeat steps no. 1 – 9 for each subscription available in your Microsoft Azure cloud account.
References
- Azure Official Documentation
- Data, privacy, and security for Azure OpenAI Service
- Azure OpenAI Service encryption of data at rest
- Azure Command Line Interface (CLI) Documentation
- az cognitiveservices account list
- az cognitiveservices account show
- az cognitiveservices account update
- az keyvault create
- az keyvault set-policy
- az keyvault key create
Related AIServices rules
- OpenAI Service Instances with Admin Privileges (Security, reliability, cost-optimisation, operational-excellence, performance-efficiency)
- Use Managed Identities for OpenAI Service Instances (Security, operational-excellence)
- OpenAI Encryption using Customer-Managed Keys (Security)
- Disable Public Network Access to OpenAI Service Instances (Security)