@@ -76,10 +76,6 @@ if (!$DeploymentOutputs['AZURE_MANAGEDHSM_URL']) {
7676[Uri ] $hsmUrl = $DeploymentOutputs [' AZURE_MANAGEDHSM_URL' ]
7777$hsmName = $hsmUrl.Host.Substring (0 , $hsmUrl.Host.IndexOf (' .' ))
7878
79- $tenant = $DeploymentOutputs [' KEYVAULT_TENANT_ID' ]
80- $username = $DeploymentOutputs [' KEYVAULT_CLIENT_ID' ]
81- $password = $DeploymentOutputs [' KEYVAULT_CLIENT_SECRET' ]
82-
8379Log ' Creating 3 X509 certificates to activate security domain'
8480$wrappingFiles = foreach ($i in 0 .. 2 ) {
8581 $certificate = New-X509Certificate2 " CN=$ ( $hsmUrl.Host ) "
@@ -91,10 +87,6 @@ $wrappingFiles = foreach ($i in 0..2) {
9187 Resolve-Path " $baseName .cer"
9288}
9389
94- # TODO: Use Az module when available; for now, assumes Azure CLI is installed and in $Env:PATH.
95- Log " Logging '$username ' into the Azure CLI"
96- az login -- service- principal -- tenant " $tenant " -- username " $username " -- password= " $password "
97-
9890Log " Downloading security domain from '$hsmUrl '"
9991
10092$sdPath = " $PSScriptRoot \$hsmName -security-domain.key"
@@ -103,15 +95,18 @@ if (Test-Path $sdpath) {
10395 Remove-Item $sdPath - Force
10496}
10597
106- az keyvault security - domain download -- hsm - name $hsmName -- security - domain - file $sdPath -- sd - quorum 2 -- sd - wrapping - keys $wrappingFiles
98+ Export-AzKeyVaultSecurityDomain - Name $hsmName - Quorum 2 - Certificates $wrappingFiles - OutputPath $sdPath
10799
108100Log " Security domain downloaded to '$sdPath '; Managed HSM is now active at '$hsmUrl '"
109101
110- # Force a sleep to wait for Managed HSM activation to propagate through Cosmos replication. Issue tracked in AzDo .
111- Log " Sleeping for 120 seconds to allow activation to propagate..."
102+ # Force a sleep to wait for Managed HSM activation to propagate through Cosmos replication. Issue tracked in Azure DevOps .
103+ Log ' Sleeping for 120 seconds to allow activation to propagate...'
112104Start-Sleep - Seconds 120
113105
114- Log " Creating additional required role assignments for resource access."
115- New-AzKeyVaultRoleAssignment - HsmName $hsmName - RoleDefinitionName " Managed HSM Crypto Officer" - ObjectID $DeploymentOutputs [" CLIENT_OBJECTID" ]
116- New-AzKeyVaultRoleAssignment - HsmName $hsmName - RoleDefinitionName " Managed HSM Crypto User" - ObjectID $DeploymentOutputs [" CLIENT_OBJECTID" ]
117- Log " Done."
106+ $testApplicationOid = $DeploymentOutputs [' CLIENT_OBJECTID' ]
107+
108+ Log " Creating additional required role assignments for '$testApplicationOid '"
109+ $null = New-AzKeyVaultRoleAssignment - HsmName $hsmName - RoleDefinitionName ' Managed HSM Crypto Officer' - ObjectID $testApplicationOid
110+ $null = New-AzKeyVaultRoleAssignment - HsmName $hsmName - RoleDefinitionName ' Managed HSM Crypto User' - ObjectID $testApplicationOid
111+
112+ Log " Role assignments created for '$testApplicationOid '"
0 commit comments