ducmthai / openconnect-as-a-container

openconnect, the anyconnect client in a Docker container
27 stars 5 forks source link

AnyConnect, Pulse and PAN container with proxies

Changelog

openconnect

An s6-overlayed Alpine Linux container with:

Build

Build the image

Use build.sh with an s6-overlay version. This version parameter is optional.

sh build.sh 3.1.4.2

Or, build the image with docker with BuiltKit enabled:

DOCKER_BUILDKIT=1 docker build --build-arg S6_OVERLAY_VERSION="3.1.4.2" -t ducmthai/openconnect:latest .

Alternatively, use docker-compose build:

COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=1 docker-compose build --build-arg S6_OVERLAY_VERSION="3.1.4.2"

Starting the VPN Proxy

vpn.config

The main configuration file, contain the following values:

Environment variables

The environment variables needed for exposing the proxy to the local network:

These variables can be specified in the command line or in the .env file in the case of docker-compose.

Set password in a file

Passwords can be set using a FILE__ prefixed environment variable where its value is path to the file contains the password:

FILE__PASSWORD=/vpn/passwd

Create a docker network

Before starting the container, please create a docker network for it:

docker network create openconnect --subnet=10.30.0.1/16

Start with docker run

docker build -t ducmthai/openconnect .
docker run -d \
--cap-add=NET_ADMIN \
--device=/dev/net/tun \
--name=vpn_proxy \
--dns=1.1.1.1 --dns=1.0.0.1 \
--privileged=true \
--restart=always \
-e "PROXY_PORT=3128" \
-e "HTTP_PROXY_PORT=3129" \
-e "LOCAL_NETWORK=192.168.0.1/24" \
-e "FILE__PASSWORD=/vpn/passwd" \
-e "OPENSSL_CONF=/etc/ssl/openssl.cnf" \
-e "EXT_IP=<get_yours_at_ifconfig.co/ip> \
-v /etc/localtime:/etc/localtime:ro \
-v "$(pwd)"/vpn.config:/vpn/vpn.config:ro \
-v "$(pwd)"/vpnpasswd:/vpn/passwd:ro \
-v "$(pwd)"/vpntoken:/vpn/token \
-p 3128:3128 \
-p 3129:3129 \
ducmthai/openconnect:latest

Start with docker-compose

A docker-compose.yml file is also provided:

docker-compose up -d

Supplying token

Token is taken from the file /vpn/token within the container. If DYNAMIC_TOKEN is true then the container clears the file after reading. To supply the dynamic OTP, simply do this outside the container:

echo OTP_HERE > ./vpntoken

Connecting to the VPN Proxy

Set your proxy to socks5://127.0.0.1:${PROXY_PORT}. Use Socks5 username and password if set.

Tested environments