Azure Stack hub virtuális gép üzembe helyezése Key Vault tárolt jelszó használatávalDeploy an Azure Stack Hub VM using a password stored in Key Vault
Ez a cikk a Windows Server rendszerű virtuális gépek (VM) központi telepítésének lépéseit ismerteti Azure Stack hub Key Vaultban tárolt jelszó használatával.This article steps through deploying a Windows Server virtual machine (VM) using a password stored in Azure Stack Hub Key Vault. A Key Vault-jelszó használata biztonságosabb, mint az egyszerű szöveges jelszó átadása.Using a key vault password is more secure than passing a plain text password.
ÁttekintésOverview
A Azure Stack hub Key vaultban az értékeket, például a jelszót titkos kulcsként is tárolhatja.You can store values such as a password as a secret in an Azure Stack Hub key vault. Miután létrehozta a titkos kulcsot, hivatkozhat rá Azure Resource Manager-sablonokban.After you create a secret, you can reference it in Azure Resource Manager templates. A Titkok a Resource Managerrel való használata a következő előnyöket biztosítja:Using secrets with Resource Manager provides the following benefits:
- Nem kell manuálisan megadnia a titkot minden egyes erőforrás telepítésekor.You don't have to manually enter secret each time you deploy a resource.
- Megadhatja, hogy mely felhasználók vagy egyszerű szolgáltatások férhetnek hozzá a titkos kulcshoz.You can specify which users or service principals can access a secret.
ElőfeltételekPrerequisites
- Elő kell fizetnie egy olyan ajánlatra, amely tartalmazza a Key Vault szolgáltatást.You must subscribe to an offer that includes the Key Vault service.
- Telepítse a PowerShellt Azure Stack hubhoz.Install PowerShell for Azure Stack Hub.
- Konfigurálja a PowerShell-környezetet.Configure your PowerShell environment.
A következő lépések ismertetik a virtuális gép létrehozásához szükséges folyamatot a Key Vault tárolt jelszó beolvasásával:The following steps describe the process required to create a VM by retrieving the password stored in a Key Vault:
- Hozzon létre egy Key Vault titkot.Create a Key Vault secret.
- Frissítse a
azuredeploy.parameters.json
fájlt.Update theazuredeploy.parameters.json
file. - A sablon üzembe helyezése.Deploy the template.
Megjegyzés
Ezeket a lépéseket a Azure Stack Development Kit (ASDK) vagy egy külső ügyfélről is használhatja, ha VPN-kapcsolaton keresztül csatlakozik.You can use these steps from the Azure Stack Development Kit (ASDK), or from an external client if you're connected through VPN.
Key Vault titkos kód létrehozásaCreate a Key Vault secret
A következő szkript egy kulcstartót hoz létre, és a Key vaultban tárolja a jelszót.The following script creates a key vault and stores a password in the key vault as a secret. A -EnabledForDeployment
Key Vault létrehozásakor használja a paramétert.Use the -EnabledForDeployment
parameter when you're creating the key vault. Ez a paraméter gondoskodik arról, hogy a kulcstároló Azure Resource Manager-sablonokból is hivatkozhat.This parameter makes sure that the key vault can be referenced from Azure Resource Manager templates.
$vaultName = "contosovault"
$resourceGroup = "contosovaultrg"
$location = "local"
$secretName = "MySecret"
New-AzResourceGroup `
-Name $resourceGroup `
-Location $location
New-AzKeyVault `
-VaultName $vaultName `
-ResourceGroupName $resourceGroup `
-Location $location
-EnabledForTemplateDeployment
$secretValue = ConvertTo-SecureString -String '<Password for your virtual machine>' -AsPlainText -Force
Set-AzureKeyVaultSecret `
-VaultName $vaultName `
-Name $secretName `
-SecretValue $secretValue
Az előző parancsfájl futtatásakor a kimenet tartalmazza a titkos URI-t (Uniform Resource Identifier).When you run the previous script, the output includes the secret URI (Uniform Resource Identifier). Jegyezze fel ezt az URI-t.Make a note of this URI. Hivatkoznia kell rá a Windows rendszerű virtuális gép üzembe helyezése jelszóval a Key Vault- sablonban.You have to reference it in the Deploy Windows VM with password in key vault template. Töltse le a 101-VM-Secure-Password mappát a fejlesztői számítógépére.Download the 101-vm-secure-password folder onto your development computer. Ez a mappa tartalmazza a azuredeploy.json
és a azuredeploy.parameters.json
fájlokat, amelyekre a következő lépésekben szüksége lesz.This folder contains the azuredeploy.json
and azuredeploy.parameters.json
files, which you'll need in the next steps.
Módosítsa a azuredeploy.parameters.json
fájlt a környezeti értékek alapján.Modify the azuredeploy.parameters.json
file according to your environment values. A különleges érdekű paraméterek a tár neve, a tár erőforráscsoport és a titkos URI (az előző szkript által generált).The parameters of special interest are the vault name, the vault resource group, and the secret URI (as generated by the previous script). Az alábbi fájl egy példa egy paraméter fájlra.The file below is an example of a parameter file.
A fájl azuredeploy.parameters.jsfrissítéseUpdate the azuredeploy.parameters.json file
Frissítse a azuredeploy.parameters.json
fájlt a kulcstároló URI-ja, a secretName, a virtuálisgép-értékek adminUsername alapján a környezetében.Update the azuredeploy.parameters.json
file with the KeyVault URI, secretName, adminUsername of the VM values as per your environment. A következő JSON-fájl egy példát mutat be a sablon paramétereinek fájljára:The following JSON file shows an example of the template parameters file:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"adminUsername": {
"value": "demouser"
},
"adminPassword": {
"reference": {
"keyVault": {
"id": "/subscriptions/xxxxxx/resourceGroups/RgKvPwd/providers/Microsoft.KeyVault/vaults/KvPwd"
},
"secretName": "MySecret"
}
},
"dnsLabelPrefix": {
"value": "mydns123456"
},
"windowsOSVersion": {
"value": "2016-Datacenter"
}
}
}
Sablonalapú telepítésTemplate deployment
Most telepítse a sablont a következő PowerShell-parancsfájl használatával:Now deploy the template by using the following PowerShell script:
New-AzResourceGroupDeployment `
-Name KVPwdDeployment `
-ResourceGroupName $resourceGroup `
-TemplateFile "<Fully qualified path to the azuredeploy.json file>" `
-TemplateParameterFile "<Fully qualified path to the azuredeploy.parameters.json file>"
A sablon sikeres központi telepítésekor a következő kimenetet eredményezi:When the template is deployed successfully, it results in the following output: