| 1 |
services: |
| 2 |
openvpn: |
| 3 |
# noinspection ComposeUnknownKeys |
| 4 |
init: true |
| 5 |
image: local/openvpn |
| 6 |
build: |
| 7 |
dockerfile: tests/Dockerfile |
| 8 |
args: |
| 9 |
GIT_REPO: https://github.com/OpenVPN/openvpn.git |
| 10 |
GIT_BRANCH: master |
| 11 |
context: ../ |
| 12 |
cap_add: |
| 13 |
- NET_ADMIN |
| 14 |
devices: |
| 15 |
- /dev/net/tun |
| 16 |
ports: |
| 17 |
- "1194:1194/tcp" |
| 18 |
- "1194:1194/udp" |
| 19 |
- "8081:8081/tcp" |
| 20 |
volumes: |
| 21 |
- ./:/tests/:ro |
| 22 |
- ./data:/etc/openvpn |
| 23 |
#restart: always |
| 24 |
environment: |
| 25 |
UPN: "${UPN:[email protected]}" |
| 26 |
entrypoint: |
| 27 |
- /bin/sh |
| 28 |
- -ec |
| 29 |
- |- |
| 30 |
if [ ! -f /etc/openvpn/pki/ca.crt ]; then |
| 31 |
/usr/share/easy-rsa/easyrsa init-pki nopass |
| 32 |
/usr/share/easy-rsa/easyrsa build-ca nopass |
| 33 |
/usr/share/easy-rsa/easyrsa build-server-full server nopass |
| 34 |
/usr/share/easy-rsa/easyrsa build-client-full ${UPN} nopass |
| 35 |
fi |
| 36 |
|
| 37 |
if [ ! -f /etc/openvpn/password.txt ]; then |
| 38 |
printf password > /etc/openvpn/password.txt |
| 39 |
fi |
| 40 |
|
| 41 |
if [ ! -d /etc/openvpn/client-config ]; then |
| 42 |
mkdir /etc/openvpn/client-config |
| 43 |
fi |
| 44 |
|
| 45 |
cat > "/etc/openvpn/openvpn.conf" <<EOF |
| 46 |
dev tun0 |
| 47 |
server 100.64.0.0 255.255.255.0 |
| 48 |
verb 3 |
| 49 |
ca /etc/openvpn/pki/ca.crt |
| 50 |
key /etc/openvpn/pki/private/server.key |
| 51 |
cert /etc/openvpn/pki/issued/server.crt |
| 52 |
dh none |
| 53 |
keepalive 10 60 |
| 54 |
persist-tun |
| 55 |
explicit-exit-notify |
| 56 |
|
| 57 |
verify-client-cert none |
| 58 |
username-as-common-name |
| 59 |
client-connect "/bin/sh -c 'env > /etc/openvpn/env.txt'" |
| 60 |
script-security 2 |
| 61 |
|
| 62 |
status /etc/openvpn/openvpn-status.log |
| 63 |
ifconfig-pool-persist /etc/openvpn/ipp.txt |
| 64 |
|
| 65 |
tls-cert-profile preferred |
| 66 |
|
| 67 |
inactive 65 |
| 68 |
|
| 69 |
topology subnet |
| 70 |
proto tcp |
| 71 |
port 1194 |
| 72 |
|
| 73 |
user nobody |
| 74 |
group nogroup |
| 75 |
|
| 76 |
# Does not work in containers |
| 77 |
disable-dco |
| 78 |
duplicate-cn |
| 79 |
|
| 80 |
client-config-dir /etc/openvpn/client-config |
| 81 |
|
| 82 |
#management 0.0.0.0 8081 /etc/openvpn/password.txt |
| 83 |
#management-hold |
| 84 |
#management-client-auth |
| 85 |
|
| 86 |
plugin /plugin/openvpn-auth-oauth2.so tcp://0.0.0.0:8081 /etc/openvpn/password.txt |
| 87 |
|
| 88 |
reneg-sec 120 |
| 89 |
push "reneg-sec 0" |
| 90 |
|
| 91 |
auth-gen-token 300 external-auth |
| 92 |
auth-user-pass-optional |
| 93 |
|
| 94 |
EOF |
| 95 |
|
| 96 |
cat > "/etc/openvpn/${UPN}.ovpn" <<EOF |
| 97 |
client |
| 98 |
dev tun |
| 99 |
nobind |
| 100 |
remote 127.0.0.1 1194 tcp4 |
| 101 |
remote-cert-tls server |
| 102 |
resolv-retry infinite |
| 103 |
tls-cert-profile preferred |
| 104 |
persist-tun |
| 105 |
verb 9 |
| 106 |
reneg-sec 0 |
| 107 |
<key> |
| 108 |
$(cat /etc/openvpn/pki/private/${UPN}.key) |
| 109 |
</key> |
| 110 |
<cert> |
| 111 |
$(openssl x509 -in /etc/openvpn/pki/issued/${UPN}.crt) |
| 112 |
</cert> |
| 113 |
<ca> |
| 114 |
$(cat /etc/openvpn/pki/ca.crt) |
| 115 |
</ca> |
| 116 |
EOF |
| 117 |
|
| 118 |
git -C /build/ log -1 |
| 119 |
exec openvpn --config "/etc/openvpn/openvpn.conf" |