SSH Tunneling Testing with PostgreSQL
Overview
SSH tunneling (also known as SSH port forwarding) is a technique used to securely forward network connections between two endpoints with the help of the SSH protocol. In this process, a secure encrypted SSH connection is established between a client and a server, and then network traffic is routed through this connection.
Similar to the MySQL Database Account, the PostgreSQL Database Account and PostgreSQL Dynamic Account support SSH tunneling to the database host. This article describes how the functionality can be tested using Docker.
Setting Up the Bastion Host
Using docker, you can set up a bastion host using the Bastion docker image: Docker.
Step 1: Pull the image.
docker pull binlab/bastion
Step 2: Create an RSA private key and corresponding public key. Place it in postgres-ssh.pem
.
ssh-keygen -t rsa -b 4096 -m PEM
Step 3: Create a directory named config
in your current working directory and copy the public key into the new file named authorized_keys
. You can use this file to store all public keys you want to use to secure an SSH connection to this bastion host.
mkdir config
cp postgres-ssh.pem.pub config/
mv config/postgres-ssh.pem.pub config/authorized_keys
Step 4: Start the bastion host using the following command:
docker run -d \
--name bastion \
--hostname bastion \
--restart unless-stopped \
-v $PWD/config:/var/lib/bastion \
-v bastion:/usr/etc/ssh:rw \