Skip to content

Commit 6ac58af

Browse files
Merge pull request #213405 from tamram/tamram22-1003
PSH samples for xtenant CMK - create account
2 parents ff4c77d + 823df1d commit 6ac58af

3 files changed

+47
-12
lines changed

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

Lines changed: 1 addition & 1 deletion
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: 09/14/2022
10+
ms.date: 10/03/2022
1111
ms.author: tamram
1212
ms.reviewer: ozgun
1313
ms.subservice: common

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

Lines changed: 27 additions & 3 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: 09/14/2022
10+
ms.date: 10/03/2022
1111
ms.author: tamram
1212
ms.reviewer: ozgun
1313
ms.subservice: common
@@ -111,11 +111,35 @@ To configure cross-tenant customer-managed keys for a new storage account in the
111111

112112
### [PowerShell](#tab/azure-powershell)
113113

114-
N/A
114+
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.
115+
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.
117+
118+
```azurepowershell
119+
$accountName = "<account-name>"
120+
$keyVaultUri = "<key-vault-uri>"
121+
$keyName = "<keyName>"
122+
$location = "<location>"
123+
$multiTenantAppId = "<application-id>"
124+
125+
$userIdentity = Get-AzUserAssignedIdentity -Name <user-assigned-identity> -ResourceGroupName $rgName
126+
127+
New-AzStorageAccount -ResourceGroupName $rgName `
128+
-Name $accountName `
129+
-Kind StorageV2 `
130+
-SkuName Standard_LRS `
131+
-Location $location `
132+
-UserAssignedIdentityId $userIdentity.Id `
133+
-IdentityType SystemAssignedUserAssigned `
134+
-KeyName $keyName `
135+
-KeyVaultUri $keyVaultUri `
136+
-KeyVaultUserAssignedIdentityId $userIdentity.Id `
137+
-KeyVaultFederatedClientId $multiTenantAppId
138+
```
115139

116140
### [Azure CLI](#tab/azure-cli)
117141

118-
N/A
142+
To configure cross-tenant customer-managed keys for a new storage account in Azure CLI, 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.
119143

120144
---
121145

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

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,18 @@ Create a user-assigned managed identity to be used as a federated identity crede
9393
$subscriptionId="aaaaaaaa-0000-aaaa-0000-aaaa0000aaaa"
9494
$tenantId="bbbbbbbb-0000-bbbb-0000-bbbb0000bbbb"
9595
$appName="XTCMKDemoApp"
96-
$uamiName="XTCMKDemoAppUA"
96+
$managedIdentity="XTCMKDemoAppUA"
9797
$rgName="XTCMKDemoAppRG"
9898
$location="westcentralus"
9999
100100
Set-AzContext -Subscription $subscriptionId
101101
102102
New-AzResourceGroup -Location $location -ResourceGroupName $rgName
103103
104-
$uamiObject = New-AzUserAssignedIdentity -Name $uamiName -ResourceGroupName $rgName -Location $location -SubscriptionId $subscriptionId
104+
$uamiObject = New-AzUserAssignedIdentity -Name $managedIdentity `
105+
-ResourceGroupName $rgName `
106+
-Location $location `
107+
-SubscriptionId $subscriptionId
105108
```
106109

107110
#### The service provider configures the user-assigned managed identity as a federated credential on the application
@@ -151,7 +154,7 @@ export subscriptionId="aaaaaaaa-0000-aaaa-0000-aaaa0000aaaa"
151154
export tenantId="bbbbbbbb-0000-bbbb-0000-bbbb0000bbbb"
152155
export appName="XTCMKDemoApp"
153156
154-
export uamiName="XTCMKDemoAppUA"
157+
export managedIdentity="XTCMKDemoAppUA"
155158
export rgName="XTCMKDemoAppRG"
156159
export location="westcentralus"
157160
@@ -162,7 +165,7 @@ export appId=$(az ad app show --id $appObjectId --query appId --output tsv)
162165
az group create --location $location --resource-group $rgName --subscription $subscriptionId
163166
echo "Created a new resource group with name = $rgName, location = $location in subscriptionid = $subscriptionId"
164167
165-
export uamiObjectId=$(az identity create --name $uamiName --resource-group $rgName --location $location --subscription $subscriptionId --query principalId --out tsv)
168+
export uamiObjectId=$(az identity create --name $managedIdentity --resource-group $rgName --location $location --subscription $subscriptionId --query principalId --out tsv)
166169
```
167170

168171
#### The service provider configures the user-assigned managed identity as a federated credential on the application
@@ -286,15 +289,19 @@ New-AzResourceGroup -Location $location -ResourceGroupName $rgName
286289
287290
# Create the service principal with the registered app's application ID (client ID)
288291
$serviceprincipalObject = New-AzADServicePrincipal -ApplicationId
289-
# $serviceprincipalObject = Get-AzADServicePrincipal -ApplicationId $addObject.Id
290292
```
291293

292294
#### The customer creates a key vault
293295

294296
To create the key vault, the customer's account must be assigned the **Key Vault Contributor** role or another role that permits creation of a key vault.
295297

296298
```azurepowershell
297-
New-AzKeyVault -Location $location -Name $vaultName -ResourceGroupName $rgName -SubscriptionId $subscriptionId -EnablePurgeProtection -EnableRbacAuthorization
299+
New-AzKeyVault -Location $location `
300+
-Name $vaultName `
301+
-ResourceGroupName $rgName `
302+
-SubscriptionId $subscriptionId `
303+
-EnablePurgeProtection `
304+
-EnableRbacAuthorization
298305
```
299306

300307
#### The customer assigns Key Vault Crypto Officer role to a user account
@@ -303,7 +310,9 @@ This step ensures that you can create the key vault and encryption keys.
303310

304311
```azurepowershell
305312
$currentUserObjectId="object-id-of-the-user"
306-
New-AzRoleAssignment -RoleDefinitionName "Key Vault Crypto Officer" -Scope /subscriptions/$subscriptionId/resourceGroups/$rgName/providers/Microsoft.KeyVault/vaults/$vaultName -ObjectId $currentUserObjectId
313+
New-AzRoleAssignment -RoleDefinitionName "Key Vault Crypto Officer" `
314+
-Scope /subscriptions/$subscriptionId/resourceGroups/$rgName/providers/Microsoft.KeyVault/vaults/$vaultName `
315+
-ObjectId $currentUserObjectId
307316
```
308317

309318
#### The customer creates an encryption key
@@ -319,7 +328,9 @@ Add-AzKeyVaultKey -Name mastercmkkey -VaultName $vaultName -Destination software
319328
Assign the Azure RBAC role **Key Vault Crypto Service Encryption User** to the service provider's registered application so that it can access the key vault.
320329

321330
```azurepowershell
322-
New-AzRoleAssignment -RoleDefinitionName "Key Vault Crypto Service Encryption User" -Scope /subscriptions/$subscriptionId/resourceGroups/$rgName/providers/Microsoft.KeyVault/vaults/$vaultName -ObjectId $serviceprincipalObject.Id
331+
New-AzRoleAssignment -RoleDefinitionName "Key Vault Crypto Service Encryption User" `
332+
-Scope /subscriptions/$subscriptionId/resourceGroups/$rgName/providers/Microsoft.KeyVault/vaults/$vaultName `
333+
-ObjectId $serviceprincipalObject.Id
323334
```
324335

325336
Now you can configure customer-managed keys with the key vault URI and key.

0 commit comments

Comments
 (0)