Skip to content

Commit dc00071

Browse files
authored
[Key Vault] Update HSM deployment scripts (Azure#22179)
1 parent 882f538 commit dc00071

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

sdk/keyvault/test-resources-post.ps1

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
8379
Log '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-
9890
Log "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

108100
Log "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...'
112104
Start-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'"

sdk/keyvault/test-resources.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,27 @@
3737
},
3838
"hsmLocation": {
3939
"type": "string",
40-
"defaultValue": "westus",
40+
"defaultValue": "westus2",
4141
"allowedValues": [
4242
"australiacentral",
4343
"canadacentral",
4444
"centralus",
4545
"eastasia",
46+
"eastus",
4647
"eastus2",
4748
"koreacentral",
49+
"northcentralus",
4850
"northeurope",
4951
"southafricanorth",
5052
"southcentralus",
5153
"southeastasia",
5254
"switzerlandnorth",
5355
"uksouth",
56+
"westcentralus",
5457
"westeurope",
55-
"westus"
58+
"westus",
59+
"westus2",
60+
"westus3"
5661
],
5762
"metadata": {
5863
"description": "The location of the Managed HSM. By default, this is 'westus'."

0 commit comments

Comments
 (0)