Skip to contentSkip to conversation

can not delete tun interface automatically if option "user nobody" is used

Openvpn-devel Tony He 5 participants 11 messages Mar 29, 2022

lore
Share & tools
lore

Tony He

author
#0 lore raw

Hi,

1. Add option "user nobody" to test ovpn-dco.
2. Start openvpn, below is the log. Then we will see tun0 is still there after openvpn exit. We must use the command "ip link del tunX" to delete. This is not friendly to end user.

[email protected]...:/tmp/etc# openvpn test.conf
2022-03-29 18:12:43 Note: --cipher is not set. OpenVPN versions before
2.5 defaulted to BF-CBC as fallback when cipher negotiation failed in
this case. If you need this fallback please add '--data-ciphers-fallb.
2022-03-29 18:12:43 OpenVPN 2.6_git aarch64-openwrt-linux-gnu [SSL
(OpenSSL)] [LZO] [EPOLL] [MH/PKTINFO] [AEAD] [DCO]
2022-03-29 18:12:43 library versions: OpenSSL 1.1.1n  15 Mar 2022, LZO
2.10
2022-03-29 18:12:43 net_route_v4_best_gw query: dst 0.0.0.0
2022-03-29 18:12:43 net_route_v4_best_gw result: via 192.168.5.1 dev
eth5
2022-03-29 18:12:43 Diffie-Hellman initialized with 2048 bit key
2022-03-29 18:12:43 net_iface_new: add tun0 type ovpn-dco
2022-03-29 18:12:43 TUN/TAP device tun0 opened
2022-03-29 18:12:43 net_iface_mtu_set: mtu 1500 for tun0
2022-03-29 18:12:43 net_iface_up: set tun0 up
2022-03-29 18:12:43 net_addr_v4_add: 10.8.0.1/24 dev tun0
2022-03-29 18:12:43 Socket Buffers: R=[212992->212992]
S=[212992->212992]
2022-03-29 18:12:43 UDPv4 link local (bound): [AF_INET][undef]:1195
2022-03-29 18:12:43 UDPv4 link remote: [AF_UNSPEC]
2022-03-29 18:12:43 GID set to nogroup
2022-03-29 18:12:43 UID set to nobody
2022-03-29 18:12:43 MULTI: multi_init called, r=256 v=256
2022-03-29 18:12:43 IFCONFIG POOL IPv4: base=10.8.0.2 size=253
2022-03-29 18:12:43 Initialization Sequence Completed
^C2022-03-29 18:12:45 event_wait : Interrupted system call
(fd=-1,code=4)
2022-03-29 18:12:45 Closing TUN/TAP interface
2022-03-29 18:12:45 net_addr_v4_del: 10.8.0.1 dev tun0
2022-03-29 18:12:45 sitnl_send: rtnl: generic error (-1): Operation
not permitted
2022-03-29 18:12:45 Linux can't del IP from iface tun0
2022-03-29 18:12:45 net_iface_del: delete tun0
2022-03-29 18:12:45 sitnl_send: rtnl: generic error (-1): Operation
not permitted
2022-03-29 18:12:45 SIGINT[hard,] received, process exiting

Tony

#1 lore raw
Quoted 6 lines · Tony He

Hi,

1. Add option "user nobody" to test ovpn-dco.
2. Start openvpn, below is the log. Then we will see tun0 is still there after openvpn exit. We must use the command "ip link del tunX" to delete. This is not friendly to end user.

I think the dco only working if openvpn is running as root is a general issue right now.
Like, clients can't connect either, because it fails to communicate with the interface after dropping privileges.

author
#2 lore raw
Quoted 11 lines · Timo Rothenpieler <[email protected]...> 于2022年3月29日周二 18:45写道:
Quoted 6 lines · Tony He

Hi,

1. Add option "user nobody" to test ovpn-dco.
2. Start openvpn, below is the log. Then we will see tun0 is still there after openvpn exit. We must use the command "ip link del tunX" to delete. This is not friendly to end user.

I think the dco only working if openvpn is running as root is a general issue right now.

Yes, I know that. Just in case user who is not openvpn expert adds this option by accident.

Quoted 8 lines

Like, clients can't connect either, because it fails to communicate with the interface after dropping privileges.

_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

Tony

#3 lore raw
In reply to Timo Rothenpieler

Hi,

Quoted 4 lines · Timo Rothenpieler

I think the dco only working if openvpn is running as root is a general issue right now.
Like, clients can't connect either, because it fails to communicate with the interface after dropping privileges.

Indeed, on a server, you need privileges for the iroute handling.

@Antonio, we should really investigate that capability stuff :-)

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...
#4 lore raw

Hi,

Quoted 1 line · Gert Doering

@Antonio, we should really investigate that capability stuff :-)

I think this was already discussed somewhere else in the past. To talk to the netlink API the NET_ADMIN capability is required - no need to be root.

Therefore, just grant this capability to the binary with:

setcap cap_net_admin+eip /usr/sbin/openvpn

and then launch it with any user you want (no need to launch as root and then drop to user nobody, unless there are other reasons for doing so).

Just tested here a few minutes ago.

Cheers,

Signature · 1 line
Antonio Quartulli
#5 lore raw

Hi,

Quoted 7 lines · Antonio Quartulli
Quoted 1 line · Gert Doering

@Antonio, we should really investigate that capability stuff :-)

I think this was already discussed somewhere else in the past. To talk to the netlink API the NET_ADMIN capability is required - no need to be root.

Quoted 6 lines

Therefore, just grant this capability to the binary with:

setcap cap_net_admin+eip /usr/sbin/openvpn

and then launch it with any user you want (no need to launch as root and then drop to user nobody, unless there are other reasons for doing so).

This is indeed nice.

What I was looking for was more the "if we start as root, assign NET_ADMIN to ourself, and then drop user privs" option.

So, no need to fiddle with system install - which is a bit risky because that way, anyone on the system can run openvpn with NET_ADMIN privs, not only those users that have sudo rights.

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...
#6 lore raw
In reply to Tony He

Hi,

Quoted 4 lines · Tony He

1. Add option "user nobody" to test ovpn-dco.
2. Start openvpn, below is the log. Then we will see tun0 is still there after openvpn exit. We must use the command "ip link del tunX" to delete. This is not friendly to end user.

Yes. This is currently unsolved - if you tell openvpn to give up its privileges, it will give up its privileges, and then it lacks privileges to tear down the interface again.

This should be doable with linux net capabilities, but right now, we have not investigated this option further. So, for now, do not use "user" together with DCO.

(For completeness: this is not a DCO issue, it just happens that normal tun interfaces go away if the file descriptor is closed, so "magic auto cleanup" happens - so if you have other stuff to clean up, like extra routes to non-tun destinates, cleanup will also fail)

@Antonio: can we make DCO interfaces auto-disappear if the OpenVPN process closes the last FD?

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...
#7 lore raw

Hi,

Quoted 2 lines · Gert Doering

@Antonio: can we make DCO interfaces auto-disappear if the OpenVPN process closes the last FD?

Originally we did not want to do that because we wanted ovpn-dco to survive a userspace crash or reload/restart (more likely) without losing state or client connections. Not something that can work now, but we wanted to be able to get there.

This said, as highlighted by Timo, the NET_ADMIN capa is required anyway for other operations (openvpn talks to DCO via netlink API).

Cheers,

Signature · 1 line
Antonio Quartulli
#8 lore raw
In reply to Gert Doering
Quoted 10 lines · Gert Doering
Quoted 4 lines · Tony He

1. Add option "user nobody" to test ovpn-dco.
2. Start openvpn, below is the log. Then we will see tun0 is still there after openvpn exit. We must use the command "ip link del tunX" to delete. This is not friendly to end user.

Yes. This is currently unsolved - if you tell openvpn to give up its privileges, it will give up its privileges, and then it lacks privileges to tear down the interface again.

Couldn't the down-root plugin be used? It's biggest drawback for this is that it's Linux-only, I suppose.

#9 lore raw

Hi,

Quoted 2 lines · Pete Nelson

Couldn't the down-root plugin be used? It's biggest drawback for this is that it's Linux-only, I suppose.

Yes, you could use down-root (and that's more portable than "DCO", which is "Linux and FreeBSD only"), but that's not a particularily nice solution, given that it has no information about "what openvpn wants to undo" - so you practically need to write your own scripts to do all that.

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...
#10 lore raw
In reply to Gert Doering
Quoted 8 lines · Gert Doering

Hi,

Quoted 4 lines · Tony He

1. Add option "user nobody" to test ovpn-dco.
2. Start openvpn, below is the log. Then we will see tun0 is still there after openvpn exit. We must use the command "ip link del tunX" to delete. This is not friendly to end user.

Quoted 7 lines

Yes. This is currently unsolved - if you tell openvpn to give up its privileges, it will give up its privileges, and then it lacks privileges to tear down the interface again.

This should be doable with linux net capabilities, but right now, we have not investigated this option further. So, for now, do not use "user" together with DCO.

I just sent a patch ("Retain CAP_NET_ADMIN when dropping privileges") that solves this for me. It retains the CAP_NET_ADMIN capability while switching user.

Patch sits on top of the dco branch, since it uses functions from it.

I'm not seeing the patch yet, but my mail server claims it got delivered.

The patch is also on Github, on top of the dco branch in my fork:
https://github.com/BtbN/openvpn/tree/dco