Azure includes several services to help protect secret information for our applications and scripts. Key Vault is designed for secure programmatic access of secret information. However to access this information, we need to authenticate against Azure AD. This is where managed identities can help. And while, Key Vault is built for public accessibility, through the use of a resource firewall and Azure Private Link, we can ensure this communication remains private.
In this hands-on lab, we’ll configure secure connectivity for a VM to Azure Key Vault using Azure Private Link. We’ll also enable managed identity for the VM to provide native Azure AD authentication to the Key Vault service.
**Scenario**
You’ve recently been hired as a security engineer and tasked with improving the security of some DevOps tasks that are performed at your company.
Your manager has asked you to improve the security of an important automation VM, which is responsible for running several scripts.
It has been found that some PowerShell scripts currently executing on the automation VM are using secret information hard-coded into the scripts in plain text.
You must secure this solution by configuring Azure Key Vault, Private Link, and managed identities all to ensure the automation scripts can run securely by storing secrets in Key Vault.
Learning Objectives
Successfully complete this lab by achieving the following learning objectives:
- Create a Managed Identity for the VM
- Locate the existing virtual machine
vm1
. - Enable a system-assigned managed identity.
- Locate the existing virtual machine
- Configure Key Vault
- Create a new Key Vault Service with the following settings:
- Only allow access via a private endpoint.
- Configure an access policy to allow
vm1
identity to have full access to the Key Vault.
- Create a new Key Vault Service with the following settings:
- Create and Read Secrets in Key Vault from VM1
- Connect to
vm1
using RDP. - Log in to Azure using the managed identity.
- Create a secret in Key Vault.
- Read your secret from Key Vault.
Note: The following PowerShell commands can be used as guidance for the above tasks. The necessary PowerShell modules to complete these steps has been installed on
vm1
for you.Connect-AzAccount -Identity
$secret = Read-Host -AsSecureString
Set-AzKeyVaultSecret -VaultName <keyvaultname> -name <secretname> -SecretValue $secret
Get-AzKeyVaultSecret -VaultName <keyvaultname> -name <secretname> -AsPlainText
Note: The concepts in this lab apply to Azure CLI, PowerShell, or any other language you choose to use. The very limited example script discussed in this lab is included below for testing and demonstration purposes only.
$userName = "remoteUser123" $vaultName = "aabbccdd00" $vaultSecretName = "MySecret" # Retrieve password from Key Vault Write-Host "Logging in with Managed Identity" Connect-AzAccount -Identity | Out-Null $userPassword = Get-AzKeyVaultSecret -VaultName $vaultName -name $vaultSecretName -AsPlainText Write-Host "Retrieved password: ${userPassword}" # Run commands using the credentials Write-Host "Running command: Invoke-Command REMOTECOMPUTER command ... -User ${userName} -Pass ${userPassword}" Read-Host -Prompt "Press any key to continue"
- Connect to