Nasazení virtuálního počítače s zabezpečeným uloženým certifikátem v centru Azure StackDeploy a VM with a securely stored certificate on Azure Stack Hub
Tento článek popisuje, jak nasadit virtuální počítač s Azure Stack hub s nainstalovaným certifikátem Key Vault.This article describes how to deploy an Azure Stack Hub virtual machine (VM) with a Key Vault certificate installed.
PřehledOverview
Certifikáty se používají v mnoha scénářích, jako je ověřování ve službě Active Directory nebo šifrování webového provozu.Certificates are used in many scenarios, such as authenticating to Active Directory, or encrypting web traffic. Certifikáty můžete bezpečně ukládat jako tajné klíče v trezoru klíčů centra Azure Stack.You can securely store certificates as secrets in an Azure Stack Hub key vault. Mezi výhody použití centra Azure Stack Key Vault patří:The benefits of using Azure Stack Hub Key Vault are:
- Certifikáty nejsou zveřejněné ve skriptu, historii příkazového řádku nebo šabloně.Certificates are not exposed in a script, command-line history, or template.
- Proces správy certifikátů je zjednodušený.The certificate management process is streamlined.
- Máte kontrolu nad klíči, které přistupují k certifikátům.You have control of the keys that access certificates.
Popis procesuProcess description
Následující kroky popisují proces vyžadovaný k odeslání certifikátu do virtuálního počítače:The following steps describe the process required to push a certificate to the VM:
- Vytvoření tajného klíče trezoru klíčůCreate a key vault secret.
- Aktualizuje azuredeploy.parameters.jsv souboru.Update the azuredeploy.parameters.json file.
- Nasazení šablonyDeploy the template.
Poznámka
Pomocí těchto kroků můžete z Azure Stack Development Kit (ASDK) nebo z externího klienta, pokud jste připojení prostřednictvím sítě VPN.You can use these steps from the Azure Stack Development Kit (ASDK), or from an external client if you're connected through VPN.
PředpokladyPrerequisites
- Musíte se přihlásit k odběru nabídky, která zahrnuje službu Key Vault.You must subscribe to an offer that includes the Key Vault service.
- Nainstalujte PowerShell pro centrum Azure Stack.Install PowerShell for Azure Stack Hub.
- Nakonfigurujte prostředí PowerShell uživatele centra Azure Stack.Configure the Azure Stack Hub user's PowerShell environment.
Vytvoření tajného klíče trezoru klíčůCreate a key vault secret
Následující skript vytvoří certifikát ve formátu. pfx, vytvoří Trezor klíčů a uloží certifikát do trezoru klíčů jako tajný kód.The following script creates a certificate in the .pfx format, creates a key vault, and stores the certificate in the key vault as a secret. contentType
Tajný klíč musí být nastaven na hodnotu pfx
.The contentType
of the secret must be set to pfx
.
Důležité
-EnabledForDeployment
Při vytváření trezoru klíčů musíte použít parametr.You must use the -EnabledForDeployment
parameter when creating the key vault. Tento parametr zajišťuje, aby se Trezor klíčů mohl odkazovat z Azure Resource Manager šablon.This parameter ensures that the key vault can be referenced from Azure Resource Manager templates.
# Create a certificate in the .pfx format
New-SelfSignedCertificate `
-certstorelocation cert:\LocalMachine\My `
-dnsname contoso.microsoft.com
$pwd = ConvertTo-SecureString `
-String "<Password used to export the certificate>" `
-Force `
-AsPlainText
Export-PfxCertificate `
-cert "cert:\localMachine\my\<certificate thumbprint that was created in the previous step>" `
-FilePath "<Fully qualified path to where the exported certificate can be stored>" `
-Password $pwd
# Create a key vault and upload the certificate into the key vault as a secret
$vaultName = "contosovault"
$resourceGroup = "contosovaultrg"
$location = "local"
$secretName = "servicecert"
$fileName = "<Fully qualified path to where the exported certificate can be stored>"
$certPassword = "<Password used to export the certificate>"
$fileContentBytes = get-content $fileName `
-Encoding Byte
$fileContentEncoded = [System.Convert]::ToBase64String($fileContentBytes)
$jsonObject = @"
{
"data": "$filecontentencoded",
"dataType" :"pfx",
"password": "$certPassword"
}
"@
$jsonObjectBytes = [System.Text.Encoding]::UTF8.GetBytes($jsonObject)
$jsonEncoded = [System.Convert]::ToBase64String($jsonObjectBytes)
New-AzResourceGroup `
-Name $resourceGroup `
-Location $location
New-AzKeyVault `
-VaultName $vaultName `
-ResourceGroupName $resourceGroup `
-Location $location `
-sku standard `
-EnabledForDeployment
$secret = ConvertTo-SecureString `
-String $jsonEncoded `
-AsPlainText -Force
Set-AzureKeyVaultSecret `
-VaultName $vaultName `
-Name $secretName `
-SecretValue $secret
Při spuštění tohoto skriptu obsahuje výstup identifikátor URI tajného kódu.When you run this script, the output includes the secret URI. Poznamenejte si tento identifikátor URI, protože ho musíte odkázat do šablony push Certificate pro Windows Správce prostředků.Make a note of this URI, as you must reference it in the Push certificate to Windows Resource Manager template. Stáhněte si do vývojového počítače složku VM-push-Certificate-Windows Template.Download the vm-push-certificate-windows template folder to your development computer. Tato složka obsahuje azuredeploy.js a azuredeploy.parameters.js se soubory, které potřebujete v následujících krocích.This folder contains the azuredeploy.json and azuredeploy.parameters.json files, which you need in the following steps.
Upravte azuredeploy.parameters.js souboru podle hodnot vašich prostředí.Modify the azuredeploy.parameters.json file according to your environment values. Důležité parametry jsou název trezoru, skupina prostředků trezoru a identifikátor URI tajného kódu (jak je vygenerován předchozí skript).The important parameters are the vault name, the vault resource group, and the secret URI (as generated by the previous script). Následující část ukazuje příklad souboru parametrů.The following section shows an example of a parameter file.
Aktualizovat azuredeploy.parameters.jsv souboruUpdate the azuredeploy.parameters.json file
Aktualizujte azuredeploy.parameters.jsv souboru pomocí vaultName
identifikátoru URI, tajného klíče, VmName
a dalších parametrů, které jsou na vašem prostředí.Update the azuredeploy.parameters.json file with the vaultName
, secret URI, VmName
, and other parameters as per your environment. Následující soubor JSON ukazuje příklad souboru parametrů šablony: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": {
"newStorageAccountName": {
"value": "kvstorage01"
},
"vmName": {
"value": "VM1"
},
"vmSize": {
"value": "Standard_D1_v2"
},
"adminUserName": {
"value": "demouser"
},
"adminPassword": {
"value": "demouser@123"
},
"vaultName": {
"value": "contosovault"
},
"vaultResourceGroup": {
"value": "contosovaultrg"
},
"secretUrlWithVersion": {
"value": "https://testkv001.vault.local.azurestack.external/secrets/testcert002/82afeeb84f4442329ce06593502e7840"
}
}
}
Nasazení šablonyDeploy the template
Nasaďte šablonu pomocí následujícího skriptu prostředí PowerShell:Deploy the template by using the following PowerShell script:
# Deploy a Resource Manager template to create a VM and push the secret to it
New-AzResourceGroupDeployment `
-Name KVDeployment `
-ResourceGroupName $resourceGroup `
-TemplateFile "<Fully qualified path to the azuredeploy.json file>" `
-TemplateParameterFile "<Fully qualified path to the azuredeploy.parameters.json file>"
Po úspěšném nasazení šablony se zobrazí následující výstup:When the template is deployed successfully, it displays the following output:
Centrum Azure Stack během nasazování vloží certifikát do virtuálního počítače.Azure Stack Hub pushes the certificate to the VM during deployment. Umístění certifikátu závisí na operačním systému virtuálního počítače:The certificate location depends on the operating system of the VM:
- V systému Windows se certifikát přidá do umístění certifikátu LocalMachine s úložištěm certifikátů, které zadal uživatel.In Windows, the certificate is added to the LocalMachine certificate location, with the certificate store that the user provided.
- V systému Linux je certifikát umístěn v adresáři /var/lib/waagent s názvem souboru UppercaseThumbprint. CRT pro soubor certifikátu x509 a UppercaseThumbprint. prv pro privátní klíč.In Linux, the certificate is placed under the /var/lib/waagent directory, with the file name UppercaseThumbprint.crt for the X509 certificate file and UppercaseThumbprint.prv for the private key.
Vyřazení certifikátůRetire certificates
Vyřazení certifikátů je součástí procesu správy certifikátů.Retiring certificates is part of the certificate management process. Starší verzi certifikátu nelze odstranit, ale můžete ji zakázat pomocí Set-AzureKeyVaultSecretAttribute
rutiny.You can't delete the older version of a certificate, but you can disable it by using the Set-AzureKeyVaultSecretAttribute
cmdlet.
Následující příklad ukazuje, jak zakázat certifikát.The following example shows how to disable a certificate. Použijte vlastní hodnoty pro VaultName
Name
parametry, a Version
.Use your own values for the VaultName
, Name
, and Version
parameters.
Set-AzureKeyVaultSecretAttribute -VaultName contosovault -Name servicecert -Version e3391a126b65414f93f6f9806743a1f7 -Enable 0