Code Monkey home page Code Monkey logo

vpn-in-docker-compose's Introduction

VPN-in-Docker with a network lock

It is organized as a collection of containers, each doing its job:

  • Network — a shared networking/firewalling namespace for all containers.
  • OpenVPN — tunnels the traffic through VPN (openvpn-client).
  • Firewall — blocks the untunnelled traffic with a firewall (iptables).
  • RuleMaker — generates the firewall rules to be applied atomically.
  • Status — monitors the status of the setup and prints it to stdout.
  • WebView — publishes the monitor's status via HTTP (static nginx).

Any amount of other containers can be added to run arbitrary application:

  • Transmission — run securely as a sample application.

All components are optional and can be disabled. Though, without some of them, the solution makes no sense and will not function (the traffic will be blocked, or the apps will never start).

The setup does not affect other containers or applications running in the same Docker.

Only IPv4 addresses and traffic are currently supported. IPv6 is disabled and blocked.

AirVPN is used as a VPN provider, but any other OpenVPN-compatible one can be used (if you have a config file for OpenVPN and know their IP ranges for monitoring/alerting).

Usage

To start:

docker-compose build
docker-compose up

Then, open:

Or download and install transmission-remote-gui and configure a connection with localhost as the hostname.

Download Ubuntu via BitTorrent (either server or desktop, any version).

Stop with Ctrl+C (docker-compose will stop the containers).

To clean it up:

docker-compose down --volumes --remove-orphans

Monitoring

When the network is fully secured, you will see this status:

  • The VPN's detected country is in green (acceptable).
  • The default next-hop IP address is in green (acceptable).
  • eth* interfaces show "Operation not permitted".
  • tun* interfaces show some pinging and timing.


When VPN is down, but the traffic is still secured:

  • The VPN's detected country is absent (acceptable).
  • The default next-hop IP address is absent (acceptable).
  • eth* interfaces show "Operation not permitted".
  • tun* interfaces are absent.

To simulate:

docker-compose stop openvpn

To restore:

docker-compose start openvpn 

When the network is exposed, the status reporting looks like this:

  • The VPN's detected country is in red and flashing (compromised).
  • The default next-hop IP address is in red (compromised).
  • eth* interfaces show some pinging and timing (they must not).
  • tun* interfaces are either absent or show something.

To simulate:

docker-compose stop openvpn firewall
docker-compose exec network iptables -F
docker-compose exec network iptables -P INPUT ACCEPT
docker-compose exec network iptables -P OUTPUT ACCEPT

To restore:

docker-compose start openvpn firewall

Please note that to expose yourself, you need to do both: configure the firewall to pass the traffic AND shut down the VPN connection. As long as the VPN connection is alive, the traffic goes through it even if the firewall is in the permissive mode.

Implementation details

Shared network container

All of the containers use the shared network space of a special pseudo-container: it sleeps forever, and is only used as a shared network namespace with iptables.

Why not Docker networks? In that case, each container has its own iptables namespace, and so the firewall rules do not apply to all of them equally. With the shared container's network, they all run in the same networking context.

vpn-in-docker-compose's People

Contributors

leocolman avatar nolar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

vpn-in-docker-compose's Issues

Unable to access local network

Hey, thanks so much for sharing this it helped me out soooo much. You should add one of those "Buy me a beer links" ;-P

I realize you probably didn't want to sign yourself up for IT support for any random person on github, 🤣 but would you mind sharing any pointers on something I'm doing wrong here? 🍻

My local network is not available within the network. I updated the LOCAL_IPS to my subnet which is 192.168.1.0/24 but that didn't fix it.

I was playing around and decided to add add a route to the local net just to see. When i did that I was able to ping the local IPs that the container is running on. But still can't reach anywhere else.

Here's the diff on my fork that Im running:
24427b1...declanshanaghy:b1469c390e86e9b9cf2338b1ed5d404eb63677dc

Wireguard

Would the same firewall configuration apply if replacing openvpn by the wireguard client container?

What if my app doesn't use wait-for-safety.sh?

Hey- great image, exactly what I've been looking for for a while. What if I add an app from another docker image (radarr for example) and don't use the wait-for-safety.sh command or entry point? Presumably the app will still be unable to send non-vpn traffic (as long as it has network_mode: service:network set?

AirVPN users

Thanks for this, exactly what i was after!

Just a note for AirVPN users, i had to disable IPv6 in my AirVPN OpenVPN client .conf file by commenting out the line "setenv UV_IPV6 yes". Otherwise OpenVPN would fail to connect.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.