Skip to content

Commit 2425fc1

Browse files
Merge pull request #213685 from tamram/tamram22-1004a
xtenant CMK: clean up PSH samples + example for existing account
2 parents de8a80d + 0f8ac56 commit 2425fc1

3 files changed

+75
-40
lines changed

articles/storage/common/customer-managed-keys-configure-cross-tenant-existing-account.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ author: tamram
77

88
ms.service: storage
99
ms.topic: how-to
10-
ms.date: 10/03/2022
10+
ms.date: 10/04/2022
1111
ms.author: tamram
1212
ms.reviewer: ozgun
1313
ms.subservice: common
@@ -119,7 +119,28 @@ After you've specified the key from the key vault in the customer's tenant, the
119119

120120
### [PowerShell](#tab/azure-powershell)
121121

122-
N/A
122+
To configure cross-tenant customer-managed keys for a new storage account in PowerShell, first install the [Az.Storage PowerShell module](https://www.powershellgallery.com/packages/Az.Storage/4.4.2-preview), version 4.4.2-preview.
123+
124+
Next, call [Set-AzStorageAccount](/powershell/module/az.storage/set-azstorageaccount), providing the resource ID for the user-assigned managed identity that you configured previously in the ISV's subscription, and the application (client) ID for the multi-tenant application that you configured previously in the ISV's subscription. Provide the key vault URI and key name from the customer's key vault.
125+
126+
Remember to replace the placeholder values in brackets with your own values and to use the variables defined in the previous examples.
127+
128+
```azurepowershell
129+
$accountName = "<storage-account>"
130+
$kvUri = "<key-vault-uri>"
131+
$keyName = "<keyName>"
132+
$multiTenantAppId = "<multi-tenant-app-id>"
133+
134+
Set-AzStorageAccount -ResourceGroupName $rgName `
135+
-Name $accountName `
136+
-KeyvaultEncryption `
137+
-UserAssignedIdentityId $userIdentity.Id `
138+
-IdentityType SystemAssignedUserAssigned `
139+
-KeyName $keyName `
140+
-KeyVaultUri $kvUri `
141+
-KeyVaultUserAssignedIdentityId $userIdentity.Id `
142+
-KeyVaultFederatedClientId $multiTenantAppId
143+
```
123144

124145
### [Azure CLI](#tab/azure-cli)
125146

articles/storage/common/customer-managed-keys-configure-cross-tenant-new-account.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ author: tamram
77

88
ms.service: storage
99
ms.topic: how-to
10-
ms.date: 10/03/2022
10+
ms.date: 10/04/2022
1111
ms.author: tamram
1212
ms.reviewer: ozgun
1313
ms.subservice: common
@@ -113,11 +113,13 @@ To configure cross-tenant customer-managed keys for a new storage account in the
113113

114114
To configure cross-tenant customer-managed keys for a new storage account in PowerShell, first install the [Az.Storage PowerShell module](https://www.powershellgallery.com/packages/Az.Storage/4.4.2-preview), version 4.4.2-preview.
115115

116-
Next, call [New-AzStorageAccount](/powershell/module/az.storage/new-azstorageaccount), providing the resource ID for the user-assigned managed identity that you configured previously in the ISV's subscription, and the application (client) ID for the multi-tenant application that you configured previously in the ISV's subscription. Remember to replace the placeholder values in brackets with your own values and to use the variables defined in the previous examples.
116+
Next, call [New-AzStorageAccount](/powershell/module/az.storage/new-azstorageaccount), providing the resource ID for the user-assigned managed identity that you configured previously in the ISV's subscription, and the application (client) ID for the multi-tenant application that you configured previously in the ISV's subscription. Provide the key vault URI and key name from the customer's key vault.
117+
118+
Remember to replace the placeholder values in brackets with your own values and to use the variables defined in the previous examples.
117119

118120
```azurepowershell
119121
$accountName = "<account-name>"
120-
$keyVaultUri = "<key-vault-uri>"
122+
$kvUri = "<key-vault-uri>"
121123
$keyName = "<keyName>"
122124
$location = "<location>"
123125
$multiTenantAppId = "<application-id>"
@@ -132,7 +134,7 @@ New-AzStorageAccount -ResourceGroupName $rgName `
132134
-UserAssignedIdentityId $userIdentity.Id `
133135
-IdentityType SystemAssignedUserAssigned `
134136
-KeyName $keyName `
135-
-KeyVaultUri $keyVaultUri `
137+
-KeyVaultUri $kvUri `
136138
-KeyVaultUserAssignedIdentityId $userIdentity.Id `
137139
-KeyVaultFederatedClientId $multiTenantAppId
138140
```

includes/active-directory-msi-cross-tenant-cmk-create-identities-authorize-key-vault.md

Lines changed: 46 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -83,25 +83,31 @@ The following steps are performed by the service provider in the service provide
8383

8484
#### Create a new multi-tenant application registration
8585

86-
Pick a name for your multi-tenant application in *Tenant1*. For example: “XTCMKDemoApp”. Note that this name is used by customers to identify the application in *Tenant2*. Note the application ID (or client ID) of the app, the object ID of the app, and also the tenant ID for the app. You'll need these values in the following steps.
86+
Pick a name for your multi-tenant application in *Tenant1*, and create the multi-tenant application in the Azure portal.
87+
88+
The name that you provide for the multi-tenant application is used by the customer to identify the application in *Tenant2*. Copy the application ID (or client ID) of the app, the object ID of the app, and also the tenant ID for the app. You'll need these values in the following steps.
8789

8890
#### The service provider creates a user-assigned managed identity
8991

90-
Create a user-assigned managed identity to be used as a federated identity credential.
92+
Sign in to the ISV's tenant, and then create a user-assigned managed identity to be used as a federated identity credential.
9193

9294
```azurepowershell
93-
$subscriptionId="aaaaaaaa-0000-aaaa-0000-aaaa0000aaaa"
94-
$tenantId="bbbbbbbb-0000-bbbb-0000-bbbb0000bbbb"
95-
$appName="XTCMKDemoApp"
96-
$managedIdentity="XTCMKDemoAppUA"
97-
$rgName="XTCMKDemoAppRG"
98-
$location="westcentralus"
99-
95+
$tenantId="<isv-tenant-id>"
96+
$subscriptionId="<isv-subscription-id>"
97+
$appName="<multi-tenant-app>"
98+
$userIdentityName="<user-assigned-managed-identity>"
99+
$rgName="<isv-resource-group>"
100+
$location="<location>"
101+
102+
# Sign in to Azure in the ISV's tenant.
103+
Connect-AzAccount -Tenant $tenantId
104+
# Set the context to the ISV's subscription.
100105
Set-AzContext -Subscription $subscriptionId
101-
106+
# Create a new resource group in the ISV's subscription.
102107
New-AzResourceGroup -Location $location -ResourceGroupName $rgName
103108
104-
$uamiObject = New-AzUserAssignedIdentity -Name $managedIdentity `
109+
# Create the new user-assigned managed identity.
110+
$userIdentity = New-AzUserAssignedIdentity -Name $userIdentityName `
105111
-ResourceGroupName $rgName `
106112
-Location $location `
107113
-SubscriptionId $subscriptionId
@@ -114,7 +120,7 @@ Connect-MgGraph
114120
$appObject = New-MgApplication -DisplayName $appName -SignInAudience AzureADMultipleOrgs
115121
116122
$issuer="https://login.microsoftonline.com/$tenantId/v2.0"
117-
$subject=$uamiObject.PrincipalId
123+
$subject=$userIdentity.PrincipalId
118124
$audience="api://AzureADTokenExchange"
119125
```
120126

@@ -225,7 +231,7 @@ To create the key vault, the user's account must be assigned the **Key Vault Con
225231

226232
:::image type="content" source="media/active-directory-msi-cross-tenant-cmk-create-identities-authorize-key-vault/create-key-vault.png" alt-text="Screen shot showing how to create a key vault." lightbox="media/active-directory-msi-cross-tenant-cmk-create-identities-authorize-key-vault/create-key-vault.png" border="true":::
227233

228-
Take note of the **Vault name** and **Vault URI**. Applications that access your key vault must use this URI.
234+
Take note of the key vault name and URI Applications that access your key vault must use this URI.
229235

230236
For more information, see [Quickstart - Create an Azure Key Vault with the Azure portal](../articles/key-vault/general/quick-create-portal.md).
231237

@@ -246,9 +252,7 @@ To create the encryption key, the user's account must be assigned the **Key Vaul
246252

247253
1. On the Key Vault properties page, select **Keys**.
248254
1. Select **Generate/Import**.
249-
1. On the **Create a key** screen choose the following values. Leave the other values to their defaults.
250-
- Options: Generate
251-
- Name: mycmkkey
255+
1. On the **Create a key** screen, specify a name for the key. Leave the other values to their defaults.
252256
1. Select **Create**.
253257
1. Copy the key URI.
254258

@@ -278,17 +282,24 @@ Once you receive the application ID of the service provider's multi-tenant appli
278282
Execute the following commands in the tenant where you plan to create the key vault.
279283

280284
```azurepowershell
281-
$rgName="MyCMKKeys"
282-
$subscriptionId="cccccc-0000-ccc-000-cccc0000cccc"
283-
$vaultName="mykeyvaultname"
284-
$location="westcentralus"
285-
$currentUserObjectId="enter-your-objectId"
286-
287-
Set-AzContext -Subscription $subscriptionId
288-
New-AzResourceGroup -Location $location -ResourceGroupName $rgName
289-
290-
# Create the service principal with the registered app's application ID (client ID)
291-
$serviceprincipalObject = New-AzADServicePrincipal -ApplicationId
285+
$customerTenantId="<customer-tenant-id>"
286+
$customerRgName="<customer-resource-group>"
287+
$customerSubscriptionId="<customer-subscription-id>"
288+
$currentUserObjectId="<user-object-id>"
289+
$multiTenantAppId="<multi-tenant-app-id>"
290+
$kvName="<key-vault>"
291+
$keyName="<key-name>"
292+
$location="<location>"
293+
294+
# Sign in to Azure in the customer's tenant.
295+
Connect-AzAccount -Tenant $customerTenantId
296+
# Set the context to the customer's subscription.
297+
Set-AzContext -Subscription $customerSubscriptionId
298+
# Create a resource group in the customer's subscription.
299+
New-AzResourceGroup -Location $location -ResourceGroupName $customerRgName
300+
301+
# Create the service principal with the registered app's application ID (client ID).
302+
$servicePrincipal = New-AzADServicePrincipal -ApplicationId $multiTenantAppId
292303
```
293304

294305
#### The customer creates a key vault
@@ -297,7 +308,7 @@ To create the key vault, the customer's account must be assigned the **Key Vault
297308

298309
```azurepowershell
299310
New-AzKeyVault -Location $location `
300-
-Name $vaultName `
311+
-Name $kvName `
301312
-ResourceGroupName $rgName `
302313
-SubscriptionId $subscriptionId `
303314
-EnablePurgeProtection `
@@ -309,9 +320,8 @@ New-AzKeyVault -Location $location `
309320
This step ensures that you can create the key vault and encryption keys.
310321

311322
```azurepowershell
312-
$currentUserObjectId="object-id-of-the-user"
313323
New-AzRoleAssignment -RoleDefinitionName "Key Vault Crypto Officer" `
314-
-Scope /subscriptions/$subscriptionId/resourceGroups/$rgName/providers/Microsoft.KeyVault/vaults/$vaultName `
324+
-Scope $keyVault.ResourceId `
315325
-ObjectId $currentUserObjectId
316326
```
317327

@@ -320,7 +330,9 @@ New-AzRoleAssignment -RoleDefinitionName "Key Vault Crypto Officer" `
320330
To create the encryption key, the user's account must be assigned the **Key Vault Crypto Officer** role or another role that permits creation of a key.
321331

322332
```azurepowershell
323-
Add-AzKeyVaultKey -Name mastercmkkey -VaultName $vaultName -Destination software
333+
Add-AzKeyVaultKey -Name $keyName `
334+
-VaultName $kvName `
335+
-Destination software
324336
```
325337

326338
#### The customer grants the service provider application access to the key vault
@@ -329,8 +341,8 @@ Assign the Azure RBAC role **Key Vault Crypto Service Encryption User** to the s
329341

330342
```azurepowershell
331343
New-AzRoleAssignment -RoleDefinitionName "Key Vault Crypto Service Encryption User" `
332-
-Scope /subscriptions/$subscriptionId/resourceGroups/$rgName/providers/Microsoft.KeyVault/vaults/$vaultName `
333-
-ObjectId $serviceprincipalObject.Id
344+
-Scope $keyVault.ResourceId `
345+
-ObjectId $servicePrincipal.Id
334346
```
335347

336348
Now you can configure customer-managed keys with the key vault URI and key.
@@ -388,7 +400,7 @@ az role assignment create --role "Key Vault Crypto Officer" --scope /subscriptio
388400
To create the encryption key, the user's account must be assigned the **Key Vault Crypto Officer** role or another role that permits creation of a key.
389401

390402
```azurecli
391-
az keyvault key create --name mastercmkkey --vault-name $vaultName
403+
az keyvault key create --name > --vault-name $vaultName
392404
```
393405

394406
#### The customer grants the service provider application access to the key vault

0 commit comments

Comments
 (0)