Access Virtual Servers in a Virtual Private Cloud with OpenVPN

2 min read

Virtual Private Cloud (VPC) comes with an additional layer of security because your workload can be completely hidden from the public Internet.

There are times, however, when you will want to get into this private network. A common practice is to use a bastion host to jump into your VPC from your local machine, for example. Another option is to install a VPN software inside your VPC to extend the secure VPC network to your local network.

OpenVPN is a popular VPN software solution that can be easily installed on a server, providing a simple way to reach all the servers in your VPC from your local machine.

OpenVPN is a popular VPN software solution that can be easily installed on a server, providing a simple way to reach all the servers in your VPC from your local machine.

Source code and instructions on how to deploy a fully functional example of this architecture can be found in GitHub. In this post, I will provide a high-level description of the steps.

Step 1: Deploy the infrastructure with Terraform

We use Terraform to create all the resources depicted above. We provision a VPC, a subnet, and one virtual server instance (the instance is not reachable from the public Internet). Then, we add the bastion. It is another virtual server instance, but it is accessible from the public Internet through a floating IP address. Finally we install OpenVPN on the bastion and connect to our VPN using OpenVPN client.

The set of Terraform files is built around four submodules:

  • vpc: Creates a VPC, a subnet, and rules in the default security group.
  • instance: Creates one (or more) instances in the specified VPC, distributing instances in the subnets.
  • bastion: Creates one host in a specific subnet.
  • ansible: Generates Ansible configuration files.
The set of Terraform files is built around four submodules:

Step 2: Install software with Ansible

The second step — once the infrastructure is deployed — is to use Ansible to install OpenVPN. With Terraform, we generated the Ansible inventory together with the playbook to install OpenVPN on the bastion host. The rest is about running the right Ansible commands. After running the OpenVPN playbook, we find OpenVPN installed on the bastion and a generated client certificate to connect to the VPN.

After running the OpenVPN playbook, we find OpenVPN installed on the bastion and a generated client certificate to connect to the VPN.

Step 3: Connect with the OpenVPN client

Once OpenVPN Connect client is installed, point it to the OpenVPN configuration file generated under the ansible/client-config directory and connect to the VPN. The VPN will push the IBM Cloud private DNS configuration to your local machine, together with the right routes to access all VSIs within the VPC and the cloud service endpoints.

The VPN will push the IBM Cloud private DNS configuration to your local machine, together with the right routes to access all VSIs within the VPC and the cloud service endpoints.

From there, you can connect to virtual server instances and to cloud service endpoints that are usually accessible only from within the IBM Cloud network directly from your local machine.

From there, you can connect to virtual server instances and to cloud service endpoints that are usually accessible only from within the IBM Cloud network directly from your local machine.

Feedback, questions, and suggestions

Go ahead and try the sample on your own from the GitHub source. Although the project creates its own VPC, it can be used as a starting point to deploy OpenVPN in your existing VPCs.

If you have feedback, suggestions, or questions about this post, please reach out to me on Twitter (@L2FProd).

Be the first to hear about news, product updates, and innovation from IBM Cloud