From 65d1f311e1679d0d61b4be9162fdab23359c2403 Mon Sep 17 00:00:00 2001 From: maride Date: Thu, 23 Aug 2018 12:10:35 +0200 Subject: Add port forwarding for VPN, print remote address/port into env vars of VPN container --- src/access.go | 15 +++++++++++++++ src/main.go | 1 + 2 files changed, 16 insertions(+) (limited to 'src') diff --git a/src/access.go b/src/access.go index 6072025..ddb032d 100644 --- a/src/access.go +++ b/src/access.go @@ -8,10 +8,18 @@ import ( "net/http" "fmt" "github.com/docker/docker/api/types/network" + "flag" ) var vpnContainerID string var vpnNetworkID string +var remoteAddress* string +var remotePort* int + +func registerAccessFlags() { + remoteAddress = flag.String("vpnRemoteAddress", "", "The remote domain name or IP the VPN will run on") + remotePort = flag.Int("vpnRemotePort", 1194, "The port the VPN should listen on") +} func startVPN() (err error) { // Set up our context and Docker CLI connection @@ -23,12 +31,19 @@ func startVPN() (err error) { // Create container resp, err := dockerCli.ContainerCreate(dockerCtx, &container.Config{ Image: "circus-vpn", + Env: []string{ + fmt.Sprintf("remoteAddress=%s", *remoteAddress), + fmt.Sprintf("remotePort=%d", *remotePort), + }, }, &container.HostConfig{ Privileged: true, }, &network.NetworkingConfig{ EndpointsConfig: map[string]*network.EndpointSettings{ "endpoint": { NetworkID: vpnNetworkID, + Links: []string{ + fmt.Sprintf("%d:1194/tcp", *remotePort), + }, }, }, }, "") diff --git a/src/main.go b/src/main.go index a06ee66..ae50632 100644 --- a/src/main.go +++ b/src/main.go @@ -11,6 +11,7 @@ func main() { registerSessionFlags() registerCredentialsFlags() registerSeedFlags() + registerAccessFlags() flag.Parse() // Read challenges from file -- cgit 1.4.1