Bastion Host Setup In Azure Console
Tags: bastionhost, jumpserve, azure, cloud
Published: 2022-08-09 06:59:19

**Bastion Host**

A bastion host is a server whose purpose is to provide access to a private network from an external network, such as the Internet. Because of its exposure to potential attack, a bastion host must minimize the chances of penetration.

**What is the difference between a firewall and a bastion host?**

A bastion host is a dedicated server that lets authorized users access a private network from an external network such as the internet. Placed outside the firewall or within a DMZ, the bastion host becomes the only ingress path to those internal resources.

If we want to SSH into a VM on the private subnet from our home/office (or using a development machine), currently we can’t. Our instance has no public IP, it is in a Private Subnet (no direct route from the internet). This is where we can use a Bastion Server or Jump server.

Azure Bastion is deployed to a virtual network and supports virtual network peering. 
Specifically, Azure Bastion manages RDP/SSH connectivity to VMs created in the local or peered virtual networks.

Exposing RDP/SSH ports over the Internet isn't desired and is seen as a significant threat surface. This is often due to protocol vulnerabilities. To contain this threat surface, you can deploy bastion hosts (also known as jump-servers) at the public side of your perimeter network. 

Bastion host servers are designed and configured to withstand attacks. Bastion servers also provide RDP and SSH connectivity to the workloads sitting behind the bastion.

**Network Security Group (NSG)**

A network security group, or NSG, allows or denies inbound network traffic to your Azure resources. Think of a NSG as a cloud-level firewall for your network. 

For example, notice that the a VM allows inbound traffic on ports 22 (SSH) and 80 (HTTP). This VM’s network security group allows inbound traffic over these ports from all sources as default. But we can configure a network security group to accept traffic only from known sources, such as IP addresses that you trust or your local PC IP address.  

NSGs can be associated with subnets or individual virtual machine instances within that subnet. When an NSG is associated with a subnet, the ACL rules apply to all Virtual Machine instances of that subnet. 

**NSG Architecture:** 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oj5hh98lawrn54grsoy2.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fuoe0yu9he5jrbqlg9yo.png)
 
**Bastion Host Setup Architecture:**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zfsepboxh7kyjduvx7d7.png)
 

 
**Deployment of Resources:**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kp0qhvn78bkj4769g9w6.jpg)

Create a Resource group (NSG-RG):

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qh4v46qe3m5zd3uet4zc.png)
 
Create a Virtual network (NSG-vnet) [CIDR- 10.0.0.0/16]

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1o3l5og7grnc770ghv51.png)
 
Add subnet-1 (NSG-subnet-1) with CIDR value “10.0.1.0/24"

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iww40wvxik8yfyvwiuez.png)
 
Add subnet-2 (NSG-subnet-2) with CIDR value “10.0.2.0/24”

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p97k435liodltv60ko3x.png)
 
Create VM-1 (Bastion host in Subnet-1). Allow public IP to it.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9rljeu1l1ny443qht201.png)
 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0wtk1cvt1f5sdmierksz.png)
 
In this case NSG is applied to server by default. We can also attach NSG at subnet level. There are two rules i.e, Inbound rules and outbound rules in NSG.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o0tyjof7ioohc31cl2q1.png)
 
Create another VM (Web-server) inside Subnet-1. We can assign public Ip to the server.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1r8a3ktwulese0182e2x.png)
 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u1pdsg6hxbleethk5ppy.png)
 
Create DB-server inside Subnet-2. Assign private ip to it.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p8m15zun4ft2d5kqyj78.png)
 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8ge94wd6s7vvv6i4jz32.png)
 
Inside inbound port there is a RDP port of source any and destination any , this means anyone can RDP into my server.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uw0vsabafv5vlpfmbo0e.png)
 
Now let’s create an inbound rule so that it can only allow my local desktop IP , to do that we have to put our ipv4 ip inside source IP addresses. Delete the previous inbound port security rule.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/30c2dk82boemyxiaaes8.png)
 
Add a new inbound port rule with source as your local PC ip address. Select service as RDP and protocol as TCP.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1tr6ejldp7qvmhdvpglb.png)
 
After editing this inbound port rule, NSG will only allow my local server IP to access the Bastion-host server via RDP. We can’t access the bastion-host from any other PC. 

If we want to allow multiple PC to be able to access the bastion host, we can edit the inbound port rule and in place of source we can put the respective IP address of the PCs.

Suppose we don’t want a particular IP to access my Virtual machine, then create an inbound port and put that IP inside the source IP addresses and inside the destination IP addresses put this VM IP and select deny option in action.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kcfwh3tv1yxqcujuqsmn.png)
 
We cannot directly RDP into our DB-server because it has only private IP, so in order to RDP we need a server that has a public ip and should present in the same network.

So, we use the Bastion-host or Jump-server to access the DB-server as they exist in the same network. Let’s Connect DB-server from inside Bastion-host.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o80e7etzkpon5lbptqmw.png)
 
Connection established to DB-server via RDP from Bastion-host.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h5sk57tdq09n8b88uq2d.png)
 
Similarly, connection to DB-server can be established by WEB-server as they exist in the same network.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7nfufr59eksm4rodwmsi.png)
 
Connection established with DB-server from Web-server via RDP.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/10ugu3u3wjp2uyhrr4h4.png)
 
But our Connection to DB-server should only be restricted to Jump-server only. To solve this, we need to change inbound rule configurations of NSG of DB-server.

First delete the existing rule for RDP.
Add inbound rule as following :
Source: IP address of web-server
Destination: IP address of DB-server
Service: RDP
Protocol: Any
Priority: 210(say)
Name: 3389_port_block
Action: Deny

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9sybocnfphg88y11nwtc.png)
 
 ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gbm5hrv2n9wlgqetgu4g.png)
 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z9wtvjcgdc4rpppzkybi.png)
 
Now let’s try connecting DB-server again from inside WEB-server via RDP. We can see that the connection can’t be established.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2uvra2zsbgs8jlfsfyyq.png)
 

If we try connecting internet from DB-server from via Jump server we can see that DB-server has internet access. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kwmcuk6eg7p880810p5q.png)
 

To restrict internet access to DB-server we need to edit the Outbound rules of DB-server.
Add Outbound rule as following:
Source: Any
Destination: Service Tag
Destination Service Tag: Internet
Destination port range: 8080
Action: Deny
Priority: 200(say)
Add rule.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uhftsovjzl7gt02nijqj.png)
 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ki7op3l0jkfgw0wsgizv.png)
 

Now our deployment and setup for connecting a database server via bastion host is successfully established.

Drop your views regarding this. 
Thank you!!