-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from theohbrothers/feature/add-2.6.5-variants
Feature: Add `2.6.5` variants
- Loading branch information
Showing
9 changed files
with
321 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FROM alpine:3.18 | ||
|
||
RUN apk add --no-cache openvpn=2.6.5-r0 iptables | ||
|
||
COPY docker-entrypoint.sh /docker-entrypoint.sh | ||
RUN chmod +x /docker-entrypoint.sh | ||
|
||
ENTRYPOINT ["/docker-entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
version: '2.1' | ||
services: | ||
openvpn-server: | ||
image: theohbrothers/docker-openvpn:v2.6.5-alpine-3.18 | ||
environment: | ||
- OPENVPN_CONFIG_FILE=/etc/openvpn/server.conf | ||
# - CUSTOM_FIREWALL_SCRIPT=/etc/openvpn/firewall.sh | ||
volumes: | ||
- ./openvpn/server.conf:/etc/openvpn/server.conf | ||
# - ./openvpn/firewall.sh:/etc/openvpn/firewall.sh | ||
ports: | ||
- "1194:1194/udp" | ||
cap_add: | ||
- NET_ADMIN | ||
# sysctls for the container if it is not set on the host. See: https://docs.docker.com/compose/compose-file/compose-file-v2/#sysctls | ||
sysctls: | ||
- net.ipv4.conf.all.forwarding=1 | ||
# - net.ipv6.conf.all.disable_ipv6=0 | ||
# - net.ipv6.conf.default.forwarding=1 | ||
# - net.ipv6.conf.all.forwarding=1 | ||
restart: unless-stopped | ||
|
||
openvpn-client: | ||
image: theohbrothers/docker-openvpn:v2.6.5-alpine-3.18 | ||
environment: | ||
- OPENVPN_CONFIG_FILE=/etc/openvpn/client.conf | ||
- NAT_MASQUERADE=0 | ||
# - CUSTOM_FIREWALL_SCRIPT=/etc/openvpn/firewall.sh | ||
volumes: | ||
- ./openvpn/client.conf:/etc/openvpn/client.conf | ||
# - ./openvpn/firewall.sh:/etc/openvpn/firewall.sh | ||
cap_add: | ||
- NET_ADMIN | ||
# sysctls for the container if it is not set on the host. See: https://docs.docker.com/compose/compose-file/compose-file-v2/#sysctls | ||
sysctls: | ||
- net.ipv4.conf.all.forwarding=1 | ||
# - net.ipv6.conf.all.disable_ipv6=0 | ||
# - net.ipv6.conf.default.forwarding=1 | ||
# - net.ipv6.conf.all.forwarding=1 | ||
restart: unless-stopped |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#!/bin/sh | ||
|
||
set -eu -o pipefail | ||
|
||
output() { | ||
echo -e "[$( date -u '+%Y-%m-%dT%H:%M:%S%z' )] $1" | ||
} | ||
|
||
error() { | ||
echo -e "[$( date -u '+%Y-%m-%dT%H:%M:%S%z' )] $1" >&2 | ||
} | ||
|
||
# Env vars | ||
OPENVPN_CONFIG_FILE=${OPENVPN_CONFIG_FILE:-/etc/openvpn/server.conf} | ||
OPENVPN_SERVER_CONFIG_FILE=${OPENVPN_SERVER_CONFIG_FILE:-} # Deprecated. For backward compatibility | ||
OPENVPN_ROUTES=${OPENVPN_ROUTES:-} | ||
NAT=${NAT:-1} | ||
NAT_INTERFACE=${NAT_INTERFACE:-eth0} | ||
NAT_MASQUERADE=${NAT_MASQUERADE:-1} | ||
CUSTOM_FIREWALL_SCRIPT=${CUSTOM_FIREWALL_SCRIPT:-/etc/openvpn/firewall.sh} | ||
|
||
# Normalization | ||
if [ -n "$OPENVPN_SERVER_CONFIG_FILE" ]; then | ||
output "Warning: OPENVPN_SERVER_CONFIG_FILE is deprecated. Use OPENVPN_CONFIG_FILE instead." | ||
OPENVPN_CONFIG_FILE="$OPENVPN_SERVER_CONFIG_FILE" | ||
fi | ||
|
||
# Provision | ||
output "Provisioning tun device" | ||
mkdir -p /dev/net | ||
if [ ! -c /dev/net/tun ]; then | ||
mknod /dev/net/tun c 10 200 | ||
fi | ||
if [ -f "$CUSTOM_FIREWALL_SCRIPT" ]; then | ||
output "Executing custom firewall script: $CUSTOM_FIREWALL_SCRIPT" | ||
. "$CUSTOM_FIREWALL_SCRIPT" | ||
else | ||
output "Not executing custom firewall script $CUSTOM_FIREWALL_SCRIPT because it does not exist" | ||
fi | ||
if [ "$NAT" = 1 ]; then | ||
output "NAT is enabled" | ||
output "Provisioning NAT iptables rules" | ||
output "NAT_INTERFACE: $NAT_INTERFACE" | ||
if [ "$NAT_MASQUERADE" = 1 ]; then | ||
output "NAT_MASQUERADE is enabled" | ||
iptables -t nat -C POSTROUTING -o "$NAT_INTERFACE" -j MASQUERADE > dev/null 2>&1 || iptables -t nat -A POSTROUTING -o "$NAT_INTERFACE" -j MASQUERADE | ||
if [ -n "$OPENVPN_ROUTES" ]; then | ||
output "Provisioning NAT iptables rules for OPENVPN_ROUTES=$OPENVPN_ROUTES" | ||
for r in $OPENVPN_ROUTES; do | ||
iptables -t nat -C POSTROUTING -s "$r" -o "$NAT_INTERFACE" -j MASQUERADE > dev/null 2>&1 || iptables -t nat -A POSTROUTING -s "$r" -o "$NAT_INTERFACE" -j MASQUERADE | ||
done | ||
else | ||
output "Not provisioning route iptables rules because OPENVPN_ROUTES is empty" | ||
fi | ||
else | ||
output "Not provisioning NAT iptables rules because NAT_MASQUERADE is disabled." | ||
fi | ||
else | ||
output "NAT is disabled." | ||
output "Not adding NAT iptables rules" | ||
fi | ||
|
||
output "Listing iptables rules:" | ||
iptables -L -nv | ||
output "Listing iptables NAT rules:" | ||
iptables -L -nv -t nat | ||
|
||
# Generate the command line. openvpn man: https://openvpn.net/community-resources/reference-manual-for-openvpn-2-4/ | ||
output "Generating command line" | ||
set openvpn --cd /etc/openvpn | ||
set "$@" --config "$OPENVPN_CONFIG_FILE" | ||
|
||
# Exec | ||
ARGS="$@" | ||
output "openvpn command line: $ARGS" | ||
exec "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# See sample config file: https://github.com/OpenVPN/openvpn/blob/v2.4.8/sample/sample-config-files/client.conf | ||
# redirect-gateway def1 bypass-dhcp | ||
client | ||
dev tun | ||
proto udp | ||
remote 10.8.0.1 1194 | ||
resolv-retry infinite | ||
nobind | ||
# user nobody | ||
# group nobody | ||
persist-key | ||
persist-tun | ||
ca pki/ca.crt | ||
cert pki/issued/client.crt | ||
key pki/private/client.key | ||
remote-cert-tls server | ||
tls-auth pki/ta.key 1 | ||
# key-direction 1 | ||
cipher AES-256-CBC | ||
# auth SHA256 | ||
comp-lzo no | ||
verb 3 | ||
# mute 20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/sh | ||
|
||
# This iptables script to controlling traffic in the openvpn tunnel. | ||
# In this example, clients can only perform DNS, HTTP and HTTPS requests to the world. | ||
|
||
set -eu -o pipefail | ||
|
||
# Drop everything by default from tunnel to world | ||
iptables -P FORWARD DROP | ||
# Allow DNS from tunnel to world | ||
iptables -A FORWARD -i tun+ -o "$NAT_INTERFACE" -p udp -m udp --dport 53 -m conntrack --ctstate NEW -j ACCEPT | ||
# Allow HTTP and HTTPS from tunnel to world | ||
iptables -A FORWARD -i tun+ -o "$NAT_INTERFACE" -p tcp -m tcp -m conntrack --ctstate NEW -m multiport --dports 80,443 -j ACCEPT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# See sample config file: https://github.com/OpenVPN/openvpn/blob/v2.4.8/sample/sample-config-files/server.conf | ||
port 1194 | ||
proto udp | ||
dev tun | ||
ca pki/ca.crt | ||
cert pki/issued/server.crt | ||
key pki/private/server.key | ||
dh pki/dh.pem | ||
crl-verify pki/crl.pem | ||
server 10.8.0.0 255.255.255.0 | ||
ifconfig-pool-persist ipp.txt | ||
;client-config-dir ccd | ||
keepalive 10 120 | ||
tls-auth pki/ta.key 0 | ||
cipher AES-256-CBC | ||
max-clients 5 | ||
user nobody | ||
group nogroup | ||
persist-key | ||
persist-tun | ||
status server.status.log | ||
# log-append server.log | ||
verb 3 | ||
mute 20 | ||
explicit-exit-notify 1 |