I have a mysql database which I can access only after establishing VPN connection (IpSec-shared-secret + username + password)
so I want to run an isolated docker container which will establish this connection and proxy/expose mysql port somehow so that other containers can just connect to it without knowing if there is an vpn connection
all the examples I can find - require privileged access to a host/network (which I want to avoid to fully isolate container logic)
all I want is expose mysql port from a container that can establish ipsec-vpn access to a remote host`s mysql port
You can do it without privileged access, but
NET_ADMIN
capabilities is required, so that the container can created and tunnel interface.To test the config I picked up a free VPN service from
https://www.vpnbook.com/freevpn
Downloading this [file] (https://www.vpnbook.com/free-openvpn-account/VPNBook.com-OpenVPN-US1.zip)
I created below
Dockerfile
for the sameIn the
vpnbook-us1-tcp80.ovpn
, I made a small changed toauth-user-pass
and made itauth-user-pass openvpn-credentials
, so we can pass credentials from a file. Next was to create astart.sh
The
mknod /dev/net/tun c 10 200
creates a tun device at run-time inside container so we don't need to map it from host.Since you wanted other containers to access mysql by connecting to this container, you will change below
to
What this would do is listen to local port X on container and forward that request to port Y on IP/domain your provide. Then we can either map this ports to Host or access them directly through container.
To run the whole thing I made a simple
docker-compose.yml
Now after doing
docker-compose up -d
and waiting for few seconds, I run below command on my hostAs you can see
localhost:8080
was mapped to container port80
andsocat
is forwarding that port80
toipinfo.io:80
. The forwarding is happening through the VPN