I'm mainly trying to compartmentalise VPN subnets into four tiers to make firewalling and routing policies much more easily maintained.
To that end, I'm putting Group 1 (lowest trust) into 192.168.255.0/24, with static IP# assignments defined ideally in the CCD directory.
The main "highest trust" group are in 172.16.1.0/24, served dynamically via the internal DHCP as normal.
The basics: Servers are 4.1.x-grsec, with fairly high security profile.
Note: when I run a simple DHCP/non-statically-assigned pool, everything works flawlessly.
I am running a two instance OpenVPN server to handle otherwise identical configurations/setups via both tcp and udp.
On the server side, I see errors like:
May 2 13:45:20 bigmomma ovpn-server_tcp[14296]: user1/4.3.2.1:56465 MULTI ERROR: primary virtual IP for user1/4.3.2.1:56465 (192.168.255.3) violates tunnel network/netmask constraint (172.16.1.0/255.255.255.0)
May 2 13:45:20 bigmomma ovpn-server_tcp[14296]: user1/4.3.2.1:56465 MULTI: Learn: 192.168.255.3 -> user1/4.3.2.1:56465
May 2 13:45:20 bigmomma ovpn-server_tcp[14296]: user1/4.3.2.1:56465 MULTI: primary virtual IP for user1/4.3.2.1:56465: 192.168.255.3
May 2 13:45:21 bigmomma ovpn-server_tcp[14296]: user1/4.3.2.1:56465 SENT CONTROL [user1]: 'PUSH_REPLY,redirect-gateway def1 bypass-dhcp,dhcp-option DNS 10.1.0.1,dhcp-option DNS 10.2.0.1,route-gateway 172.16.1.1,topology subnet,ping 10,ping-restart 65,socket-flags TCP_NODELAY,ifconfig 192.168.255.3 255.255.255.0,peer-id 0,cipher AES-128-GCM' (status=1)
On the client side, I get this:
https://pastebin.com/ZYsv2y1K
Server is:
OpenVPN 2.5_git x86_64-unknown-linux-gnu [SSL (OpenSSL)] [LZO] [LZ4] [EPOLL] [PKCS11] [MH/PKTINFO] [AEAD] built on Apr 13 2017
library versions: OpenSSL 1.1.0e 16 Feb 2017, LZO 2.06
Originally developed by James Yonan
Copyright (C) 2002-2017 OpenVPN Technologies, Inc. <sales@openvpn.net>
Compile time defines: enable_async_push=no enable_comp_stub=no enable_crypto=yes enable_crypto_ofb_cfb=yes enable_debug=yes enable_def_auth=yes enable_dlopen=unknown enable_dlopen_self=unknown enable_dlopen_self_static=unknown enable_fast_install=yes enable_fragment=yes enable_iproute2=no enable_libtool_lock=yes enable_lz4=yes enable_lzo=yes enable_management=yes enable_multi=yes enable_multihome=yes enable_pam_dlopen=no enable_password_save=yes enable_pedantic=no enable_pf=yes enable_pkcs11=yes enable_plugin_auth_pam=yes enable_plugin_down_root=yes enable_plugins=yes enable_port_share=yes enable_selinux=no enable_server=yes enable_shared=yes enable_shared_with_static_runtimes=no enable_small=no enable_static=yes enable_strict=no enable_strict_options=no enable_systemd=no enable_werror=no enable_win32_dll=yes enable_x509_alt_username=yes with_crypto_library=openssl with_gnu_ld=yes with_ifconfig_path=/sbin/ifconfig with_mem_check=no with_sysroot=no
Clients are 2.4.1 (release) on both Windows (7 x64 Ultimate) and Linux (4.x). They're test VMs running behind VIrtualBox's own NAT on a host that is behind NAT as well, but otherwise unfirewalled. The main network router is a small Linux host (4.1.x-grsec based) with several NICs using the normal stateful rules (iptables). When I assign a static IP# from the 172.16.1.0/24 pool, it works flawlessly.
The documentation and HOWTO on the OpenVPN site are very misleading if not outright wrong, at least for 2.4+. The provided examples of three tiers of subnets using ccd doesn't work at all.
Configuration files + helper scripts follow:
local 1.2.3.4
cd /etc/openvpn2
port 80
proto tcp
dev tunvpn0
ca ca.crt
cert server.crt
key server.key # This file should be kept secret
dh dh2560.pem
topology subnet
server 172.16.1.0 255.255.255.0
ifconfig-pool-persist ipp.txt
client-config-dir ccd
route 192.168.255.0 255.255.255.0 172.16.1.1
learn-address /etc/openvpn2/learn-address.sh
push "redirect-gateway def1 bypass-dhcp"
push "dhcp-option DNS 10.1.0.1"
push "dhcp-option DNS 10.2.0.1"
keepalive 10 65
tls-auth ta.key 0
cipher AES-128-GCM
auth sha256
comp-lzo
max-clients 32
user vpn
group vpn
up '/etc/openvpn2/up.tun'
persist-key
persist-tun
remote-cert-eku "TLS Web Client Authentication"
status openvpn.server_tcp.status
verb 3
mute 15
ncp-ciphers "AES-128-GCM:AES-256-GCM:AES-128-CBC"
tls-version-min 1.2
tcp-nodelay
tcp-queue-limit 128
UDP Configuration:local 1.2.3.4
cd /etc/openvpn2
up '/etc/openvpn2/up.tun'
port 80
proto udp
dev tunvpn1
ca ca.crt
cert server.crt
key server.key
dh dh2560.pem
topology subnet
server 172.16.1.0 255.255.255.0
ifconfig-pool-persist ipp.txt
client-config-dir ccd
route 192.168.255.0 255.255.255.0 172.16.1.1
learn-address /etc/openvpn2/learn-address.sh
push "redirect-gateway def1 bypass-dhcp"
push "dhcp-option DNS 10.1.0.1"
push "dhcp-option DNS 10.2.0.1"
keepalive 10 65
tls-auth ta.key 0 # This file is secret
cipher AES-128-GCM
auth sha256
comp-lzo
max-clients 32
user vpn
group vpn
persist-key
persist-tun
remote-cert-eku "TLS Web Client Authentication"
status openvpn.server_udp.status
verb 3
mute 15
ncp-ciphers "AES-128-GCM:AES-256-GCM:AES-128-CBC"
tls-version-min 1.2
learn-address.sh:
if [ $# -lt 2 ]; then
exit 0;
fi
action=$1;
addr=$2;
case ${action} in
add|update)
echo "[-] ${addr} logged in to ${dev}" >> vpn.log
/usr/bin/sudo /bin/ip ro del ${addr}/32
/usr/bin/sudo /bin/ip ro add ${addr}/32 dev ${dev};
;;
delete)
# Found out we'd better do nothing when delete is called.
echo "[-] Deleting addr ${addr} -> ${dev}" >> vpn.log
/usr/bin/sudo /bin/ip ro del ${addr}/32 &> /dev/null
;;
*)
;;
esac
exit 0;
up.tun:
#!/bin/bash
/bin/echo 1 > /proc/sys/net/ipv4/conf/${1}/forwarding
exit 0
dev tun
proto tcp
remote my.vpn.com 80
resolv-retry infinite
nobind
persist-key
persist-tun
mute-replay-warnings
remote-cert-tls server
cipher AES-128-GCM
auth sha256
comp-lzo adaptive
socket-flags TCP_NODELAY
verb 2
# Silence repeating messages
mute 30
key-direction 1
verify-x509-name 'CN=my.vpn.com' subject
remote-cert-eku "TLS Web Server Authentication"
### Windows specific options ###
block-outside-dns
dhcp-option NTP 10.2.0.1
dhcp-option DISABLE-NBT
dhcp-option DOMAIN vpn0.my.vpn.com
register-dns
### End of Windows specific options ###
<ca>
-----BEGIN CERTIFICATE-----
(snip)
-----END CERTIFICATE-----
</ca>
<cert>
Certificate:
Data:
Version: 3 (0x2)
Serial Number: 6 (0x6)
Signature Algorithm: ecdsa-with-SHA256
(snip)
-----BEGIN CERTIFICATE-----
(snip)
-----END CERTIFICATE-----
</cert>
<key>
-----BEGIN ENCRYPTED PRIVATE KEY-----
(snip)
-----END ENCRYPTED PRIVATE KEY-----
</key>
<tls-auth>
#
# 2048 bit OpenVPN static key
#
-----BEGIN OpenVPN Static key V1-----
(snip)
-----END OpenVPN Static key V1-----
</tls-auth>ifconfig-push 172.16.1.253 255.255.255.0