subcollection | copyright | lastupdated | lasttested | content-type | services | account-plan | completion-time | use-case | ||
---|---|---|---|---|---|---|---|---|---|---|
solution-tutorials |
|
2024-01-02 |
2023-09-07 |
tutorial |
vpc |
paid |
1h |
Cybersecurity, VirtualPrivateCloud |
{{site.data.keyword.attribute-definition-list}}
{: #vpc-secure-management-bastion-server} {: toc-content-type="tutorial"} {: toc-services="vpc"} {: toc-completion-time="1h"}
This tutorial may incur costs. Use the Cost Estimator to generate a cost estimate based on your projected usage. {: tip}
This tutorial walks you through the deployment of a bastion host to securely access remote instances within a Virtual Private Cloud (VPC). A bastion host is an instance that is provisioned with a public IP address and can be accessed via SSH. Once set up, the bastion host acts as a jump server, allowing secure connection to instances provisioned without a public IP address. {: shortdesc}
To reduce exposure of servers within the VPC, you will create and use a bastion host. Administrative tasks on the individual servers are going to be performed using SSH, proxied through the bastion. Access to the servers and regular internet access from the servers, e.g., for software installation, will only be allowed with a special maintenance security group attached to those servers.
{: #vpc-secure-management-bastion-server-objectives}
- Learn how to set up a bastion host and security groups with rules
- Securely manage servers via the bastion host
{: caption="Figure 1. Architecture diagram of the tutorial" caption-side="bottom"} {: style="text-align: center;"}
- After setting up the required infrastructure (subnets, security groups with rules, virtual server instances) on the cloud, the admin (DevOps) connects (SSH) to the bastion host using the private SSH key.
- The admin assigns a maintenance security group with proper outbound rules.
- The admin connects (SSH) securely to the instance's private IP address via the bastion host to install or update any required software eg., a web server
- The internet user makes an HTTP/HTTPS request to the web server.
{: #vpc-secure-management-bastion-server-prereqs}
- Check for user permissions. Be sure that your user account has sufficient permissions to create and manage VPC resources. See the list of required permissions for VPC.
- You need an SSH key to connect to the virtual servers. If you don't have an SSH key, see the instructions for creating a key for VPC.
- The tutorial assumes that you are adding the bastion host in an existing virtual private cloud. If you don't have a VPC in your account, create one before proceeding with the next steps.
{: #vpc-secure-management-bastion-server-create-bastion-host} {: step}
In this section, you will create and configure a bastion host along with a security group in a separate subnet.
{: #vpc-secure-management-bastion-server-create-bastion-subnet}
-
Click Subnets under Network on the left pane, then click Create.
- Enter vpc-secure-bastion-subnet as name, then select the Virtual Private Cloud you created.
- Select the same resource group as for your VPC.
- Under Location, select a geography, region and zone.
- Leave the Address prefix as it is and select the Total IP addresses as 256.
-
Switch the Public gateway to Attached.
Attach a public gateway to the subnet to allow all attached resources to communicate with the public internet. {: tip}
-
Click Create subnet to provision it.
{: #vpc-secure-management-bastion-server-create-configure-security-group }
Let's create a security group and configure inbound rules to your bastion VSI (virtual server instance).
-
Select Security groups under Network, then click Create.
-
Enter vpc-secure-bastion-sg as name and select the VPC you created earlier.
-
Select the same resource group as for your VPC.
-
Now, create the following inbound rules by clicking Add in the inbound section. They allow SSH access and Ping (ICMP). The values are shown in the table below.
Protocol Port / Value Source type TCP Port range: 22-22 Any ICMP Type: 8,Code: Leave empty Any {: caption="Bastion: Inbound rules" caption-side="bottom"} To enhance security further, the inbound traffic could be restricted to the company network or a typical home network. You could run
curl ipecho.net/plain ; echo
to obtain your network's external IP address and use that instead. {: tip } -
Click Create security group to create it.
{: #vpc-secure-management-bastion-server-create-bastion-instance}
With the subnet and security group already in place, next, create the bastion virtual server instance.
- Under Subnets on the left pane, select vpc-secure-bastion-subnet.
- Click on Attached resources and under Attached instances, click Create to provision a new virtual server called vpc-secure-bastion-vsi under the same resource group as your subnet.
- Select Architecture as Intel. Pick a Location and make sure to later use the same location again.
- Under Image click on Change image. Use the search field to select Ubuntu Linux as your Operating system. You can pick any version of the image.
- Click Change profile, select Compute as category and pick cx2-2x4 (2 vCPUs and 4 GB RAM) as your profile.
- Create a new SSH key, click New key
- Enter vpc-ssh-key as key name.
- Select the same resource group as for your VSI.
- Leave the Region as is.
- Copy the contents of your existing local SSH key and paste it under Public key.
- Click Add SSH key.
- Scroll to select the VPC under Networking
- Under Network interfaces, click on the Edit icon
- Make sure that vpc-secure-bastion-subnet is selected as the subnet.
- Uncheck the default security group and mark vpc-secure-bastion-sg.
- Click Save.
- Click Create virtual server.
- Once the instance is up and Running, click on vpc-secure-bastion-vsi and reserve a floating IP by clicking on the Edit icon under Network interfaces, then under Floating IP address selecting Reserve a new floating IP. Click Save to finish.
{: #vpc-secure-management-bastion-server-6}
Once your bastion's floating IP address is active, try connecting to it using ssh:
ssh -i ~/.ssh/<PRIVATE_KEY> root@<BASTION_FLOATING_IP_ADDRESS>
{: pre}
{: #vpc-secure-management-bastion-server-maintenance-security-group} {: step}
With access to the bastion working, continue and create the security group for maintenance tasks like installing and updating the software.
-
Select Security groups under Network, then click Create.
-
Enter vpc-secure-maintenance-sg as name and select the VPC you created earlier.
-
Select the same resource group as for your VPC.
-
Next, add the inbound rule shown in the table below. It allows SSH access from the bastion host.
Protocol Port / Value Source type Source TCP Ports 22-22 Security group vpc-secure-bastion-sg {: caption="Maintenance: Inbound rules" caption-side="bottom"} -
Next, add the outbound rule shown in the table below. It allows SSH access from the bastion host.
Protocol Port / Value Destination type TCP Ports 80-80 Any TCP Ports 443-443 Any TCP Ports 53-53 Any UDP Ports 53-53 Any {: caption="Maintenance: Outbound rules" caption-side="bottom"} DNS server requests are addressed on port 53. DNS uses TCP for Zone transfer and UDP for name queries either regular (primary) or reverse. HTTP requests are on port 80 and 443. {: tip }
-
Click Create security group to create it.
-
Navigate to Security Groups, then select vpc-secure-bastion-sg.
-
Finally, edit the security group and add the following outbound rule.
Protocol Destination type Destination Port / Value TCP Security group vpc-secure-maintenance-sg Ports 22-22 {: caption="Bastion: Outbound rules" caption-side="bottom"}
{: #vpc-secure-management-bastion-server-bastion-host-access-instances} {: step}
In this section, you will create a subnet with virtual server instance and a security group.
If you already have virtual server instances in your VPC that you want to connect to, you can skip the next three sections and start at Add virtual server instance(s) to the maintenance security group.
{: #vpc-secure-management-bastion-server-create-private-subnet}
To create a new subnet,
- Click Subnets under Network on the left pane, then click Create.
- Enter vpc-secure-private-subnet as name, then select the VPC you created.
- Select the same resource group as for your VPC.
- Select a Location.
- Leave the Address prefix as it is and select the Total IP addresses as 256.
- Switch the Public gateway to Attached.
- Click Create subnet to provision it.
{: #vpc-secure-management-bastion-server-10}
To create a new security group:
- Click Security groups under Network, then click Create.
- Enter vpc-secure-private-sg as name and select the VPC you created earlier.
- Click Create security group.
{: #vpc-secure-management-bastion-server-11}
To create a virtual server instance in the newly created subnet:
- Click on the subnet vpc-secure-private-subnet created earlier under Subnets.
- Click Attached resources, under Attached instances, click Create.
- To configure the instance:
- Enter a unique name, vpc-secure-private-vsi and resource group as earlier.
- Select the same Location already used by the bastion virtual server.
- Select Public type of virtual server.
- Under Image click on Change image. Use the search field to select Ubuntu Linux as your Operating system. You can pick any version of the image.
- Click Change profile, select Compute as category and pick cx2-2x4 (2 vCPUs and 4 GB RAM) as your profile.
- For SSH keys pick the SSH key you created earlier for the bastion.
- Scroll to Networking and select the VPC your created.
- Under Network interfaces, click on the Edit icon
- Select vpc-secure-private-subnet as the subnet.
- Uncheck the default security and group and activate vpc-secure-private-sg.
- Click Save.
- Click Create virtual server.
{: #vpc-secure-management-bastion-server-add-vsi-to-maintenance}
For administrative work on the servers, you have to associate the specific virtual servers with the maintenance security group. In the following, you will enable maintenance, log into the private server, update the software package information, then disassociate the security group again.
Let's enable the maintenance security group for the server.
- Navigate to Security groups and select vpc-secure-maintenance-sg security group.
- Click on the Attached resources tab, then Edit interfaces.
- Expand the virtual server instances and check the selection in the Interfaces column for vpc-secure-private-vsi.
- Click Save for the changes to be applied.
{: #vpc-secure-management-bastion-server-13}
To SSH into an instance using its private IP, you will use the bastion host as your jump host.
-
Obtain the private IP address of a virtual server instance under Virtual server instances.
-
Use the ssh command with
-J
to log into the server with the bastion floating IP address you used earlier and the server Private IP address shown under Network interfaces.ssh -J root@<BASTION_FLOATING_IP_ADDRESS> root@<PRIVATE_IP_ADDRESS>
{: pre}
-J
flag is supported in OpenSSH version 7.3+. In older versions-J
is not available. In this case the safest and most straightforward way is to use ssh's stdio forwarding (-W
) mode to "bounce" the connection through a bastion host. e.g.,ssh -o ProxyCommand="ssh -W %h:%p root@<BASTION_FLOATING_IP_ADDRESS" root@<PRIVATE_IP_ADDRESS>
{: tip }
{: #vpc-secure-management-bastion-server-14}
Once connected, you can install software on the virtual server or perform maintenance tasks.
-
First, update the software package information:
apt-get update
{: pre}
-
Install the desired software, e.g., Nginx or MySQL or IBM Db2.
When done, disconnect from the server with exit
command.
To allow HTTP/HTTPS requests from the internet user, assign a floating IP to the VSI and open required ports (80 - HTTP and 443 - HTTPS) via the inbound rules in the security group of private VSI. {: tip}
{: #vpc-secure-management-bastion-server-15}
Once you're done installing software or performing maintenance, you should remove the virtual servers from the maintenance security group to keep them isolated.
- Navigate to Security groups and select vpc-secure-maintenance-sg security group.
- Click Attached interfaces, then Edit interfaces.
- Expand the virtual server instances and uncheck the selection in the Interfaces column for vpc-secure-private-vsi.
- Click Save for the changes to be applied.
{: #vpc-secure-management-bastion-server-removeresources} {: step}
- Switch to Virtual server instances, Stop and Delete your instances by clicking the respective action menu.
- Once the VSIs are gone, switch to Subnets and delete your subnets.
- After the subnets have been deleted, switch to the VPCs tab and delete your VPC.
When using the console, you may need to refresh your browser to see updated status information after deleting a resource. {: tip}
{: #vpc-secure-management-bastion-server-related}