|
| 1 | +--- |
| 2 | +title: Cross-tenant CMKs |
| 3 | +titleSuffix: Azure AI Search |
| 4 | +description: Set up CMK encryption in Azure AI Search that uses a key from an Azure Key Vault in another tenant. |
| 5 | +manager: vinodva |
| 6 | +author: mattgotteiner |
| 7 | +ms.author: magottei |
| 8 | +ms.service: azure-ai-search |
| 9 | +ms.topic: how-to |
| 10 | +ms.date: 10/13/2025 |
| 11 | +ms.update-cycle: 180-days |
| 12 | +--- |
| 13 | + |
| 14 | +# Configure customer-managed keys across different tenants |
| 15 | + |
| 16 | +When Azure Key Vault and Azure AI Search are in different Azure tenants, use a Microsoft Entra multitenant app to enable [customer-managed key (CMK) encryption](search-security-manage-encryption-keys.md) using a key from another tenant. |
| 17 | + |
| 18 | +## Prerequisites |
| 19 | + |
| 20 | ++ A tenant containing the search service that has content you want to encrypt. Azure AI Search must be [configured for role-based access](search-security-enable-roles.md). Support for CMK requires Basic pricing tier or higher. |
| 21 | + |
| 22 | ++ A separate tenant having the Azure Key Vault and the encryption keys you want to use. Azure Key Vault must be [configured for role-based access](/azure/key-vault/general/rbac-guide). |
| 23 | + |
| 24 | ++ Azure CLI for sending requests. |
| 25 | + |
| 26 | +## Create a multitenant Microsoft Entra application in tenant A |
| 27 | + |
| 28 | +Use the Azure CLI to send requests. We refer to the tenant containing Azure AI Search as *tenant A*. |
| 29 | + |
| 30 | +1. Get the tenant ID: |
| 31 | + |
| 32 | + `az account show --query tenantId --output tsv` |
| 33 | + |
| 34 | +1. Make sure you're signed in to tenant A: |
| 35 | + |
| 36 | + `az login --tenant <tenant-A-id> ` |
| 37 | + |
| 38 | +1. Create the application registration: |
| 39 | + |
| 40 | + `az ad app create --display-name cross-tenant-auth --sign-in-audience AzureADMultipleOrgs ` |
| 41 | + |
| 42 | +1. Save the app ID output from this step. |
| 43 | + |
| 44 | +## Add a client secret to the multitenant application |
| 45 | + |
| 46 | +1. To add the client secret to the multitenant application in tenant A, run the following command: |
| 47 | + |
| 48 | + `az ad app credential reset --id <multitenant-app-id>` |
| 49 | + |
| 50 | +1. Save the password output from this step. The password output is a required input for [setting up CMK](search-security-manage-encryption-keys.md) in Azure AI Search. |
| 51 | + |
| 52 | +1. To specify when the client secret expires, you can specify an end-date parameter to this command. |
| 53 | + |
| 54 | + `az ad app credential reset --id <multitenant-app-id> --end-date <end-date>` |
| 55 | + |
| 56 | + The end-date parameter accepts a date in ISO 8601 format. For example: `az ad app credential reset --id <multitenant-app-id> --end-date 2026-12-31`. |
| 57 | + |
| 58 | +## Create a service principal in tenant B for the multitenant application |
| 59 | + |
| 60 | +We refer to the tenant containing Azure Key Vault as *tenant B*. In tenant B, create a service principal for the multitenant application in tenant A. |
| 61 | + |
| 62 | +1. Sign in to tenant B: |
| 63 | + |
| 64 | + `az login --tenant <tenant-B-id>` |
| 65 | + |
| 66 | +1. Create the service principal using the multitenant app ID output from the first step: |
| 67 | + |
| 68 | + `az ad sp create --id <multitenant-app-id>` |
| 69 | + |
| 70 | + This service principal is an instance of the multitenant application in tenant A. Roles assigned to this service principal in tenant B are also assigned to the multitenant application in tenant A. |
| 71 | + |
| 72 | +1. Verify the link between tenant A and B by reviewing the "appOwnerOrganizationId" in the following command: |
| 73 | + |
| 74 | + `az ad sp show --id <multitenant-app-id>` |
| 75 | + |
| 76 | + This command displays the service principal details in JSON. Look for the "appOwnerOrganizationId" field in the output to confirm it matches tenant A's ID. |
| 77 | + |
| 78 | +1. Save the object ID of the service principal (from the `"id"` field) from this step. The object ID is a required input for setting up CMK in Azure AI Search. |
| 79 | + |
| 80 | +1. Get the resource ID for Azure Key Vault: |
| 81 | + |
| 82 | + `az keyvault show --name <key-vault-name> --query id --output tsv` |
| 83 | + |
| 84 | +1. Assign the **Key Vault Crypto Service Encryption User** role on the key vault in tenant B to the new service principal. |
| 85 | + |
| 86 | + `az role assignment create --assignee <service-principal-object-id> --role "Key Vault Crypto Service Encryption User" --scope <key-vault-resource-id>` |
| 87 | + |
| 88 | + An example of this assignment might look like this: |
| 89 | + |
| 90 | + `az role assignment create --assignee 12345678-1234-1234-1234-123456789012 --role "Key Vault Crypto Service Encryption User" --scope /subscriptions/87654321-4321-4321-4321-210987654321/resourceGroups/myKeyVaultRG/providers/Microsoft.KeyVault/vaults/myCompanyKeyVault` |
| 91 | + |
| 92 | +## Test encryption |
| 93 | + |
| 94 | +Create a test index in the search service (tenant A) to validate the setup. Use the multitenant app ID and the credentials you added in the "access credentials" object to authenticate to the key vault in the other tenant. |
| 95 | + |
| 96 | +You can use this sample index schema for testing. You can use the Azure portal to add an index and provide this JSON, or use a [REST client](search-get-started-text.md) to send a Create Index request. |
| 97 | + |
| 98 | +```json |
| 99 | +{ |
| 100 | + "name": "cross-tenant-cmk-test", |
| 101 | + "fields": [ |
| 102 | + { |
| 103 | + "name": "id", |
| 104 | + "type": "Edm.String", |
| 105 | + "key": true |
| 106 | + } |
| 107 | + ], |
| 108 | + "encryptionKey": { |
| 109 | + "keyVaultUri": "https://myCompanyKeyVault.vault.azure.net/", |
| 110 | + "keyVaultKeyName": "search-encryption-key", |
| 111 | + "keyVaultKeyVersion": "abc123def456ghi789", |
| 112 | + "accessCredentials": { |
| 113 | + "applicationId": "12345678-1234-1234-1234-123456789012", |
| 114 | + "applicationSecret": "secretValueFromStep2" |
| 115 | + } |
| 116 | + } |
| 117 | +} |
| 118 | +``` |
| 119 | + |
| 120 | +Verify the index was created successfully: |
| 121 | + |
| 122 | +```http |
| 123 | +GET https://<search-service>.search.windows.net/indexes/cross-tenant-cmk-test?api-version=2025-09-01 |
| 124 | +``` |
| 125 | + |
| 126 | +For more information about how to rotate or manage keys, see [Configure customer-managed keys for data encryption](search-security-manage-encryption-keys.md). |
0 commit comments