Loading...

Connect to a Linux VM using Bastion and Key Vault without a private key file

Connect to a Linux VM using Bastion and Key Vault without a private key file

In enterprise environments, requirements often demand the use of private networks, resulting in VMs not being assigned Public IP addresses. In such cases, Azure Bastion offers an extremely useful feature for accessing these VMs without complexity. When logging into Linux VMs on Azure via Azure Bastion using an SSH Private Key, the key is often managed as a local file. Managing SSH Private Key files on individual devices poses risks such as potential key leakage. Therefore, centralized management, including proper role assignment, is preferable from a security standpoint. A common need in such scenarios is to manage SSH Private Keys using Key Vault. This article provides such a comprehensive step-by-step guide.

 

There are two huge benefits here.

  • SSH Private Key is no longer required to store as a local file Local file by storing it in Azure Key Vault.
  • Access to Linux VM can be be controlled using RBAC assignment for Azure Key Vault.

Regarding the first point, storing the SSH Private Key locally after creating it through the Azure Portal can be issues such as loss the file or difficulty in identifying which VM it is for. Additionally, it has the benefit of reducing the risk of file leakage if a developer leaves the company or the project.
Regarding the second point, using Key Vault for access management allows you to control VM access through Key Vault. You can manage access control to specific VMs.

Here is the architecture diagram for the current setup. When creating a Linux VM, the SSH Private Key generated through the Azure portal is registered in Key Vault. This SSH Private Key is then used to access the Linux VM via Azure Bastion.

 
 

Prerequisites

Before following this article, you have to create Azure resources as follows:

  • Virtual Network
  • Key Vault
  • Azure Bastion

Setup

First, we create a new SSH Key when creating the Linux VM through the Azure portal. While it is possible to create an SSH Private Key when creating a Linux VM through the Azure portal, you can also create it separately. Once you input the parameters and create the Linux VM, you can download the SSH Private Key and save it as a local file.

20231222233143-.png

If you choose to create the SSH Private Key separately, note that you need to select "Reset password" from the VM menu on Azure Portal and use "Add SSH public key" to set the SSH Key information for the Linux VM. The first link in the References section contains relevant information.

 

Next, you have to acquire proper RBAC role to manage Azure Key Vault. It's not enough just having subscription Owner role. In this article, we assign Key Vault Administrator role.

fig02.png

We can use Key Vault Secrets Officer role for developers who access your Linux VM. Please refer to the article as follows to assign proper RBA roles.

Provide access to Key Vault keys, certificates, and secrets with an Azure role-based access control 

 

Then, we register the SSH Private Key in the secrets of Azure Key Vault (you cannot select Keys or Certificates with Azure Bastion). There is a tip here that the SSH Private Key contains a multi-line file, but the Key Vault portal does not support the registration of multi-line strings. Therefore, we have to execute this via command line as follows:

 

az keyvault secret set --name "your-secret-name" --vault-name "your-key-name" --file "my-ssh-private-key.pem"

 

20231222234027--.png

If the command works well, you can find your SSH Private Key on the Azure Key Vault.

20231222234159---.png

Then, we can access the Linux VM via Azure Bastion. Select the Linux VM, choose "SSH Private Key from Azure Key Vault" from the Authentication Type options, and use the the SSH Private Key you have registered.

20231222234519----.png

Error #1: Register SSH Private Key without RBAC role assignment

You got error as follows if you do not have proper RBAC. I have assigned Key Vault Administrator role to the operator to solve this issue.

fig03.png

Error #2: Access Linux VM without RBAC role assignment

You got error as follows if you do not have proper RBAC. I have assigned Key Vault Secrets Officer role to the operator to solve this issue.

fig04.png

References

Published on:

Learn more
Azure Infrastructure Blog articles
Azure Infrastructure Blog articles

Azure Infrastructure Blog articles

Share post:

Related posts

Enable IP restriction for a public facing App service

In this blog article, we will cover how to control the app service deployment to support only public facing app service with IP restriction en...

1 year ago

Selecting the Optimal Container for Azure AI: Docker, ACI, or AKS?

Deploying Azure AI services in containers like Docker, Azure Container Instances (ACI), or Azure Kubernetes Service (...

1 year ago

Securing Hardware and Firmware Supply Chains

In the modern cloud data center, ensuring the authenticity, integrity, and security of hardware and firmware is paramount. Firmware is the low...

1 year ago

Liquid Cooling in Air Cooled Data Centers on Microsoft Azure

With the advent of artificial intelligence and machine learning (AI/ML), hyperscale datacenters are increasingly accommodating AI accelerators...

1 year ago

Mt Diablo - Disaggregated Power Fueling the Next Wave of AI Platforms

Authors: Jason Adrian – General Manager, Azure Platform Architecture Laurentiu Olariu – Power Architect, Azure Platform Architecture Banha Sok...

1 year ago

Deny inbound NSG Rule creation via Azure Policy

  In this blog article, we will cover how to deny the creation of inbound Network Security Group Rules if the inbound NSG Rule contains&n...

1 year ago

Azure Extended Zones: Optimizing Performance, Compliance, and Accessibility

  Azure Extended Zones are designed to bring the power of Azure closer to end users in specific metropolitan areas or jurisdictions, cate...

1 year ago

Inside Maia 100: Revolutionizing AI Workloads with Microsoft's Custom AI Accelerator

Authored by: Sherry Xu, Partner Lead SoC Architect, Azure Maia Chandru Ramakrishnan, Partner Software Engineering Manager   As the advanc...

1 year ago

Accelerate Cloud Potential for Your SAP Workloads on Azure with these Learning Paths

  Accelerate Cloud Potential for Your SAP Workloads on Azure with these Learning Paths   In today's rapidly evolving digital landsc...

1 year ago

Azure Role Assignments Audit Report

Overview:  Azure Administrators often come across challenges while tracking multiple Azure role assignments and removals. At present Azur...

2 years ago

Newsletter

Get the latest Dynamics 365 and Power Platform content in your inbox

A curated digest of community blogs, product news, videos, and podcasts — delivered without the noise.

Weekly updates Unsubscribe anytime Fresh community picks
We use your email only for the newsletter and you can unsubscribe at any time.
By subscribing, you agree to the privacy policy.