Hi,
Yes it works but you have to bring your tun up manual after the container is running.
https://forum.proxmox.com/threads/turnkey-linux-openvpn-template-issues.31668/#post-157372
auto tun0
iface tun0 inet static
address 192.168.15.1
netmask 255.255.255.255
network 192.168.15.2
pre-up openvpn --mktun --dev tun0
Sorry I missed this.But that thread is not about unprivileged container right?
lxc.mount.entry = /dev/net dev/net none bind,create=dir
/etc/pve/lxc/102.conf
# ls -l /dev/net/
total 0
crw-rw-rw- 1 nobody nogroup 10, 200 Sep 13 02:14 tun
openvpn[176]: Note: Cannot set tx queue length on tun0: Operation not permitted (errno=1)
cp /lib/systemd/system/openvpn-client\@.service /etc/systemd/system/
LimitNPROC=10
systemctl daemon-reload
systemd[1]: openvpn.service: Failed to reset devices.list: Operation not permitted
systemd[1]: openvpn.service: Failed to set invocation ID on control group /system.slice/openvpn.service,
lxc.mount.entry = /dev/net dev/net none bind,create=dir
chmod 0666 /dev/net/tun
chmod: changing permissions of '/dev/net/tun': Operation not permitted`
lxc.cgroup.devices.allow = c 10:200 rwm
lxc.hook.autodev = sh -c "modprobe tun; cd ${LXC_ROOTFS_MOUNT}/dev; mkdir net; mknod net/tun c 10 200; chmod 0666 net/tun"
unprivileged: 0
lxc.apparmor.profile: unconfined
lxc.mount.entry = /dev/net dev/net none bind,create=dir
# setfacl -m u:100000:rw -m g:100000:rw /dev/net/tun
mkdir -p /devcontainer/net
mknod /devcontainer/net/tun c 10 200
chown 100000:100000 /devcontainer/net/tun
I"m having this same issue trying to get OpenVPN to work on Ubunbu and CentOS LXC containers.That should do (unless for some reason your / is mounted with the `nodev` option).
You also have to adapt the `lxc.mount.entry` lines to bind this new file instead.
lxc.mount.entry = /devcontainer/net/tun dev/net/tun none bind,create=dir
mkdir -p /devcontainer/net
mknod /devcontainer/net/tun c 10 200
chown 100000:100000 /devcontainer/net/tun
lxc.mount.entry = /devcontainer/net/tun dev/net/tun none bind,create=dir
lxc.mount.entry = /devcontainer/net/tun dev/net/tun none bind,create=dir
I"m having this same issue trying to get OpenVPN to work on Ubunbu and CentOS LXC containers.
I ran the following on the host
Code:mkdir -p /devcontainer/net mknod /devcontainer/net/tun c 10 200 chown 100000:100000 /devcontainer/net/tun
Then updated /etc/pve/lxc/102.conf with
Code:lxc.mount.entry = /devcontainer/net/tun dev/net/tun none bind,create=dir
When I try to restart the container it it fails. This is the same behavior for both the Ubunbu and CentOS containers. If I delete the
it the containers start fine.Code:lxc.mount.entry = /devcontainer/net/tun dev/net/tun none bind,create=dir
lxc.mount.entry: /dev/net dev/net none bind,create=dir
Thanks for the quick reply. When I use that line the container starts fine but it doesn't resolve the "Cannot open TUN/TAP dev /dev/net/tun: error." This is what I'm getting when I try to start OpenVPN in the docker container. This in a Ubuntu 18.04.4 LXC and CentOS 7 LXC identically.try like:lxc.mount.entry: /dev/net dev/net none bind,create=dir
Using OpenVPN provider: PIA
Starting OpenVPN using config US West.ovpn
Setting OPENVPN credentials...
adding route to local network 192.168.1.0/24 via 172.17.0.1 dev eth0
Wed Jul 15 13:33:27 2020 OpenVPN 2.4.7 x86_64-pc-linux-gnu [SSL (OpenSSL)] [LZO] [LZ4] [EPOLL] [PKCS11] [MH/PKTINFO] [AEAD] built on Sep 5 2019
Wed Jul 15 13:33:27 2020 library versions: OpenSSL 1.1.1c 28 May 2019, LZO 2.10
Wed Jul 15 13:33:27 2020 NOTE: the current --script-security setting may allow this configuration to call user-defined scripts
Wed Jul 15 13:33:27 2020 TCP/UDP: Preserving recently used remote address: [AF_INET]xxx.xxx.xx.xxx:1198
Wed Jul 15 13:33:27 2020 UDP link local: (not bound)
Wed Jul 15 13:33:27 2020 UDP link remote: [AF_INET]xxx.xxx.xxx.xxx:1198
Wed Jul 15 13:33:27 2020 WARNING: this configuration may cache passwords in memory -- use the auth-nocache option to prevent this
Wed Jul 15 13:33:28 2020 [11b9e54dc6eaeece62a2e146f9e1a74b] Peer Connection Initiated with [AF_INET]xxx,xxx,xx,xxx:1198
Wed Jul 15 13:33:29 2020 ERROR: Cannot open TUN/TAP dev /dev/net/tun: No such file or directory (errno=2)
Wed Jul 15 13:33:29 2020 Exiting due to fatal error
oh my bad, i guess since you ranmknod
on/devcontainer/net/tun
you need to pass that instead.
so it should belxc.mount.entry: /devcontainer/net dev/net none bind,create=dir
#lxc.mount.entry%3A /dev/net/tun dev/net/tun none bind,create=dir
#lxc.mount.entry%3A /dev/net dev/net none bind,create=dir
arch: amd64
cores: 1
hostname: openvpn
memory: 1024
net0: name=Plex,bridge=vmbr0,firewall=1,hwaddr=BA:32:05:27:7C:89,ip=dhcp,type=v$
ostype: ubuntu
rootfs: local-zfs:subvol-102-disk-0,size=16G
swap: 512
unprivileged: 1
lxc.mount.entry: /storage/data storage none bind,create=dir, optional 0 0
lxc.apparmor.raw: mount,
lxc.mount.entry: /devcontainer/net dev/net none bind,create=dir
lxc-start -n 102 -F -l DEBUG -o /tmp/lxc-102.log
lxc-start 102 20200715143755.406 ERROR conf - conf.c:mount_entry:1855 - No such file or directory - Failed to mount "/devcontainer/net" on "/usr/lib/x86_64-linux-gnu$
lxc-start 102 20200715143755.406 ERROR conf - conf.c:lxc_setup:3329 - Failed to setup mount entries
lxc-start 102 20200715143755.406 ERROR start - start.c:do_start:1231 - Failed to setup container "102"
lxc-start 102 20200715143755.406 ERROR sync - sync.c:__sync_wait:41 - An error occurred in another process (expected sequence number 5)
lxc-start 102 20200715143755.406 DEBUG network - network.c:lxc_delete_network:3693 - Deleted network devices
lxc-start 102 20200715143755.406 ERROR start - start.c:__lxc_start:1957 - Failed to spawn container "102"
root@pharpe:/devcontainer/net# ls -al
total 2
drwxr-xr-x 2 root root 3 Jul 14 22:02 .
drwxr-xr-x 3 root root 3 Jul 14 22:02 ..
crw-r--r-- 1 100000 100000 10, 200 Jul 14 22:02 tun