Site To Site Transparent Layer 3 Tunnel

Overview

In this sample, we are going to use a single service forwarder to transfer a port from the local connector to a remote connector, and, over top of that, run a web socket UDP tunnel, and, over top of that, run a Wireguard VPN. This will provide layer 3 adjacency. We will use wstunnel to facilitate. We will use the Agilicus connector to facilitate the inbound/outbound connectivity, and, authenticate via a Service Account for always-on operation.

For the sample, we assume the main site and the remote site(s) each have a device running Linux (the sample is for Debian or Ubuntu). We also assume the sites have non-overlapping IP (avoiding the need for NAT in either of the directions).

High Level Steps

  1. Create a connector on each of ‘Main site’ and ‘Remote site’
  2. Create a network on Remote Site, using destination 127.0.0.1, port 4443
  3. Create a service forwarder, via ‘Main Site’, listening on 127.0.0.1 port 4443, destination the network created above
  4. Run ‘wstunnel’ on Remote site, listening for connections on 127.0.01 4443
  5. Run ‘wstunnel’ on Main site, sending connections to 127.0.0.1, port 4443
  6. Run wireguard on each of the sites, using wstunnel as the source/sink

Agilicus Connector & Network Setup

In this example, we assume your domain is connect.example.org. This you would use https://admin.connect.example.org for administration. We assume you are going to have two sites connected, ‘main’, and ‘remote-1’ (you can later add more remotes).

Main: Connector & Service Account & Application Setup & SSH

On the ‘main’ site, install an Agilicus Connector.

Now we will create a ‘application’ to use this Connector. First, we will create a Service Account, a special system user that will have always-on permission to use it.

Now, we will create an “application’ to use this Connector.

Now we will assign permissions to the Service Account we created above:

Download and save the ‘Authentication Document’ for this Service Account, we will use it below. Also, copy and save the service account email, we will use that below.

Now, let us setup SSH so we can remotely administer this device:

NOTE: feel free to modify the options. The ‘DISCUSS’ on users auto-signing in, this may be a convenient way to use a browser-based sign in without giving users the password of the device.

At this stage we are complete setting up ‘main’.

Remote: Connector & SSH

Install the connector as above in main, switching the connector name to remote-1.

Setup SSH as above in ‘main’, switching the connector to remote-1 and the SSH name.

Checks

If we examine the connector screen, we can see that each of our new connectors exists, and has SSH bound to it, as well as ‘main’ has the wireguard service from the application we created:

We can also check by opening https://profile.connect.example.org and hitting refresh, we should see an SSH icon for each, and, if selected, should be able to sign-in. NOTE: we recommend creating an SSH key and using the native integration for a more seamless and secure experience.

Linux Setup

We now have some Linux-specific setup to do, outside the scope of Agilicus AnyX. This is to install a site-to-site connectivity agent called ‘wireguard’ and a WebSocket tunnel to facilitate it.

Install Wireguard: Main

On the ‘main’ site Linux device, run the following commands as root (e.g. run sudo su - first):

Install Wireguard: Remote

On the ‘remote’ site Linux device, run the following commands as root (e.g. run sudo su - first):

Add Remote Trust to Main

On the ‘main’ site Linux device, run the following commands as root (e.g. run sudo su - first). This will cause it to trust the remote.

Examine Wireguard Configuration

Now, let us examine the configuration. On the ‘main’ site, run cat /etc/wireguard/wg0.conf’ and observe the output, as below:

Reading, we can see that the ‘server’ has a private key, and the remotes it trusts have a public key. Also, the ‘main’ is going to have an IP of 10.8.0.1, we will assign 10.8.0.2 to the remote.

On the ‘remote’ site, let us also examine the config. We can see the assign of the 10.8.0.2 IP

WebSocket Tunnel Setup

On both of the sites, run the following to install the WebSocket tunnel facility:

Main WebSocket Setup

Now, on the ‘main’ site, we will setup WebSocket to listen:

We can now check that it is running:

Remote WebSocket Setup

Now on the ‘remote’ site, we will setup the WebSocket tunnel. First, we will create an API Key which gives us permission to the Service Account we created above. There is no exposed facility in the Web administration to create API keys, so we will use the CLI. You can do this on your Windows machine, or, on the Linux machine. The machine needs Python installed, see https://www.python.org/downloads/windows/ .

First we will install the Agilicus CLI & SDK using ‘pip install -U agilicus’ (this works equally on Windows or Linux).

Then, we will list the users of type service_account to find the one we created above. A browser will open the first time to obtain your credentials for this operation.

Now, we will create an API key using the Service Account credentials we downloaded above:

It will output something like below. the api_key: XXX is the important part.

The Network can be accessed using the service account ’email’ we obtained above, and the API key we just created.

Let us test the API key with curl. First, lets see that if we open it with a browser, we are forced to try and sign in (we will not be able to sign-in, but this will tell us the application is up). Now, let us try with curl. Fill in your values on the first two lines, and, replace connect.example.org with your domain.

We should see a response like:

OK, now that we have tested the connection, let us install the remote-1 site tunnel. Fill in your values on the first two lines, and, replace connect.example.org with your domain.

OK at this stage we are done and the connection should be up, and will stay up, restarting as needed if the network goes down.

Checks

Let us bring up the Wireguard interfaces, and diagnose. On each machine, run wg-quick up wg0

Now, we should see the interfaces up. On each run wg and check:

From the remote, we should be able to ping 10.8.0.1, and from main we should be able to ping 10.8.0.2:

We can check logs:

We can check the interfaces:

Routing

Now that we have the point to point interfaces up, we may wish to reach local peers on one side or the other. First, let us check routing is enabled:

Now, devices on the remote side will need a route installed, using the lan-side IP of the Linux device. Similarly, the main side devices will need a route installed, using the lan-side IP of the Linux device.