From: "mattock (Code Review)" Date: Wed, 26 Jun 2024 05:24:57 +0000 In-Reply-To: References: Reply-To: samuli@...515..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <9d681859a243d4c9737874bb1de43d11e0db5443-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="UckVUFfjTeI="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: t_server_null: multiple improvements and fixes List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld Cc: openvpn-devel --UckVUFfjTeI= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: mattock, plaisthos. Hello flichtenheld, plaisthos, I'd like you to reexamine a change. Please visit http://gerrit.openvpn.net/c/openvpn/+/669?usp=3Demail to look at the new patch set (#3). Change subject: t_server_null: multiple improvements and fixes ...................................................................... t_server_null: multiple improvements and fixes - exit after a timeout if unable to kill servers - use sudo or equivalent only for server stop/start - use /bin/sh directly instead of through /usr/bin/env - simplify sudo call in the sample rc file - remove misleading and outdated documentation - make it work on OpenBSD 7.5 Change-Id: I2cce8ad4e0d262e1404ab1eb6ff673d8590b6b3a Signed-off-by: Samuli Sepp=C3=A4nen --- M doc/t_server_null.rst M tests/t_server_null.rc-sample M tests/t_server_null.sh M tests/t_server_null_client.sh M tests/t_server_null_default.rc M tests/t_server_null_server.sh M tests/t_server_null_stress.sh 7 files changed, 61 insertions(+), 40 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/69/669/3 diff --git a/doc/t_server_null.rst b/doc/t_server_null.rst index e3a098a..5fe9080 100644 --- a/doc/t_server_null.rst +++ b/doc/t_server_null.rst @@ -43,6 +43,12 @@ * run as root * a privilege escalation tool (sudo, doas, su) and the permission to bec= ome root +If you use "doas" you should enable nopass feature in */etc/doas.conf*. For +example to allow users in the *wheel* group to run commands without a pass= word +prompt:: + + permit nopass keepenv :wheel + Technical implementation ------------------------ @@ -73,13 +79,6 @@ * Waits until servers have launched. Then launch all clients, wait f= or them to exit and then check test results by parsing the client log files= . Each client kills itself after some delay using an "--up" script. -Note that "make check" moves on once *t_server_null_client.sh* has exited.= At -that point *t_server_null_server.sh* is still running, because it exists o= nly -after waiting a few seconds for more client connections to potentially app= ear. -This is a feature and not a bug, but means that launching "make check" run= s too -quickly might cause test failures or unexpected behavior such as leftover -OpenVPN server processes. - Configuration ------------- diff --git a/tests/t_server_null.rc-sample b/tests/t_server_null.rc-sample index 28c3773..98d7869 100644 --- a/tests/t_server_null.rc-sample +++ b/tests/t_server_null.rc-sample @@ -1,6 +1,5 @@ # Uncomment to run tests with sudo -#SUDO_EXEC=3D`which sudo` -#RUN_SUDO=3D"${SUDO_EXEC} -E" +#RUN_SUDO=3D"sudo -E" TEST_RUN_LIST=3D"1 2 3 10 11" diff --git a/tests/t_server_null.sh b/tests/t_server_null.sh index 0e53ba4..7627edf 100755 --- a/tests/t_server_null.sh +++ b/tests/t_server_null.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env sh +#!/bin/sh # TSERVER_NULL_SKIP_RC=3D"${TSERVER_NULL_SKIP_RC:-77}" @@ -57,12 +57,7 @@ srcdir=3D"${srcdir:-.}" -if [ -z "${RUN_SUDO}" ]; then - "${srcdir}/t_server_null_server.sh" & -else - $RUN_SUDO "${srcdir}/t_server_null_server.sh" & -fi - +"${srcdir}/t_server_null_server.sh" & "${srcdir}/t_server_null_client.sh" retval=3D$? diff --git a/tests/t_server_null_client.sh b/tests/t_server_null_client.sh index 8890007..e7dd332 100755 --- a/tests/t_server_null_client.sh +++ b/tests/t_server_null_client.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env sh +#!/bin/sh launch_client() { test_name=3D$1 @@ -76,19 +76,22 @@ count=3D0 server_max_wait=3D15 while [ $count -lt $server_max_wait ]; do - server_pids=3D"" - server_count=3D$(set|grep 'SERVER_NAME_'|wc -l) + servers_up=3D0 + server_count=3D$(echo $TEST_SERVER_LIST|wc -w) # We need to trim single-quotes because some shells return quoted valu= es # and some don't. Using "set -o posix" which would resolve this proble= m is # not supported in all shells. + # + # While inactive server configurations may get checked they won't incr= ease + # the active server count as the processes won't be running. for i in `set|grep 'SERVER_NAME_'|cut -d "=3D" -f 2|tr -d "[\']"`; do server_pid=3D$(cat $i.pid 2> /dev/null) - server_pids=3D"${server_pids} ${server_pid}" + if ps -p $server_pid > /dev/null 2>&1; then + servers_up=3D$(( $servers_up + 1 )) + fi done - servers_up=3D$(ps -p $server_pids 2>/dev/null|sed '1d'|wc -l) - echo "OpenVPN test servers up: ${servers_up}/${server_count}" if [ $servers_up -ge $server_count ]; then @@ -101,6 +104,7 @@ if [ $count -eq $server_max_wait ]; then retval=3D1 + exit $retval fi done diff --git a/tests/t_server_null_default.rc b/tests/t_server_null_default.rc index 63b6bcd..825bb52 100755 --- a/tests/t_server_null_default.rc +++ b/tests/t_server_null_default.rc @@ -24,7 +24,7 @@ MAX_CLIENTS=3D"10" CLIENT_MATCH=3D"Test-Client" SERVER_EXEC=3D"${top_builddir}/src/openvpn/openvpn" -SERVER_BASE_OPTS=3D"--daemon --local 127.0.0.1 --dev tun --topology subnet= --server 10.29.41.0 255.255.255.0 --max-clients $MAX_CLIENTS --persist-tun= --verb 3" +SERVER_BASE_OPTS=3D"--daemon --local 127.0.0.1 --dev tun --topology subnet= --max-clients $MAX_CLIENTS --persist-tun --verb 3" SERVER_CIPHER_OPTS=3D"" SERVER_CERT_OPTS=3D"--ca ${CA} --dh ${DH} --cert ${SERVER_CERT} --key ${SE= RVER_KEY} --tls-auth ${TA} 0" SERVER_CONF_BASE=3D"${SERVER_BASE_OPTS} ${SERVER_CIPHER_OPTS} ${SERVER_CER= T_OPTS}" @@ -32,14 +32,16 @@ TEST_SERVER_LIST=3D"1 2" SERVER_NAME_1=3D"t_server_null_server-1194_udp" +SERVER_SERVER_1=3D"--server 10.29.41.0 255.255.255.0" SERVER_MGMT_PORT_1=3D"11194" SERVER_EXEC_1=3D"${SERVER_EXEC}" -SERVER_CONF_1=3D"${SERVER_CONF_BASE} --lport 1194 --proto udp --management= 127.0.0.1 ${SERVER_MGMT_PORT_1}" +SERVER_CONF_1=3D"${SERVER_CONF_BASE} ${SERVER_SERVER_1} --lport 1194 --pro= to udp --management 127.0.0.1 ${SERVER_MGMT_PORT_1}" SERVER_NAME_2=3D"t_server_null_server-1195_tcp" +SERVER_SERVER_2=3D"--server 10.29.42.0 255.255.255.0" SERVER_MGMT_PORT_2=3D"11195" SERVER_EXEC_2=3D"${SERVER_EXEC}" -SERVER_CONF_2=3D"${SERVER_CONF_BASE} --lport 1195 --proto tcp --management= 127.0.0.1 ${SERVER_MGMT_PORT_2}" +SERVER_CONF_2=3D"${SERVER_CONF_BASE} ${SERVER_SERVER_2} --lport 1195 --pro= to tcp --management 127.0.0.1 ${SERVER_MGMT_PORT_2}" # Test client configurations CLIENT_EXEC=3D"${top_builddir}/src/openvpn/openvpn" diff --git a/tests/t_server_null_server.sh b/tests/t_server_null_server.sh index 9bc0c88..037baf7 100755 --- a/tests/t_server_null_server.sh +++ b/tests/t_server_null_server.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env sh +#!/bin/sh launch_server() { server_name=3D$1 @@ -8,16 +8,23 @@ status=3D"${server_name}.status" pid=3D"${server_name}.pid" - # Ensure that old status, log and pid files are gone - rm -f "${status}" "${log}" "${pid}" - - "${server_exec}" \ - $server_conf \ - --status "${status}" 1 \ - --log "${log}" \ - --writepid "${pid}" \ - --explicit-exit-notify 3 - + if [ -z "${RUN_SUDO}" ]; then + rm -f "${status}" "${log}" "${pid}" + "${server_exec}" \ + $server_conf \ + --status "${status}" 1 \ + --log "${log}" \ + --writepid "${pid}" \ + --explicit-exit-notify 3 + else + $RUN_SUDO rm -f "${status}" "${log}" "${pid}" + $RUN_SUDO "${server_exec}" \ + $server_conf \ + --status "${status}" 1 \ + --log "${log}" \ + --writepid "${pid}" \ + --explicit-exit-notify 3 + fi } # Load base/default configuration @@ -64,15 +71,30 @@ echo "All clients have disconnected from all servers" +# Make sure that the server processes are truly dead before exiting. If a +# server process does not exit in 15 seconds assume it never will, move on= and +# hope for the best. +echo "Waiting for servers to exit" for PID_FILE in $server_pid_files do SERVER_PID=3D$(cat "${PID_FILE}") - $KILL_EXEC "${SERVER_PID}" - # Make sure that the server processes are truly dead before exiting - while : + if [ -z "${RUN_SUDO}" ]; then + $KILL_EXEC "${SERVER_PID}" + else + $RUN_SUDO $KILL_EXEC "${SERVER_PID}" + fi + + count=3D0 + maxcount=3D75 + while [ $count -le $maxcount ] do ps -p "${SERVER_PID}" > /dev/null || break + count=3D$(( count + 1)) sleep 0.2 done + + if [ $count -ge $maxcount ]; then + echo "WARNING: could not kill server with pid ${SERVER_PID}!" + fi done diff --git a/tests/t_server_null_stress.sh b/tests/t_server_null_stress.sh index 1281397..0bb9452 100755 --- a/tests/t_server_null_stress.sh +++ b/tests/t_server_null_stress.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env sh +#!/bin/sh # # Run this stress test as root to avoid sudo authorization from timing out. -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/669?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I2cce8ad4e0d262e1404ab1eb6ff673d8590b6b3a Gerrit-Change-Number: 669 Gerrit-PatchSet: 3 Gerrit-Owner: mattock Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: mattock Gerrit-MessageType: newpatchset --UckVUFfjTeI= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: mattock, plaisthos.

mattock uploaded patch set #3 to this change.

View Change<= /a>

t_server_null: multiple improvements and fixes

- exit after a ti= meout if unable to kill servers
- use sudo or equivalent only for server= stop/start
- use /bin/sh directly instead of through /usr/bin/env
- = simplify sudo call in the sample rc file
- remove misleading and outdate= d documentation
- make it work on OpenBSD 7.5

Change-Id: I2cce8ad= 4e0d262e1404ab1eb6ff673d8590b6b3a
Signed-off-by: Samuli Sepp=C3=A4nen &l= t;samuli.seppanen@...277...>
---
M doc/t_server_null.rst
M test= s/t_server_null.rc-sample
M tests/t_server_null.sh
M tests/t_server_n= ull_client.sh
M tests/t_server_null_default.rc
M tests/t_server_null_= server.sh
M tests/t_server_null_stress.sh
7 files changed, 61 inserti= ons(+), 40 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/o=
penvpn refs/changes/69/669/3
diff --git a/doc/t_server_null.rst b/d=
oc/t_server_null.rst
index e3a098a..5fe9080 100644--- a/doc/t_server_null.rst
+++ b/doc/t_server_null= .rst
@@ -43,6 +43,12 @@
* run as root
* a privilege escalation tool (sudo, doas, su) and the per= mission to become root

+If you use "doas" you should enable nopass f= eature in */etc/doas.conf*. For
+example to allow users in the *wheel* group to run commands wit= hout a password
+prom= pt::
+
+ permit nopass keepenv :wheel
+
Tec= hnical implementation
------------------------
<= span>

@@ -73,13 +79,6 @@

* Waits until servers have launched. Then launch all clients, wait = for them to exit and then check test results by parsing the client log file= s. Each client kills itself after some delay using an "--up" scri= pt.

-= Note that "make check" moves on once *t_server_null_client.sh* ha= s exited. At
-that poin= t *t_server_null_server.sh* is still running, because it exists only=
-after waiting a few seconds = for more client connections to potentially appear.
-This is a feature and not a bug, but means tha= t launching "make check" runs too
-quickly might cause test failures or unexpected behav= ior such as leftover
-O= penVPN server processes.
-#SUDO_EXEC=3D`which sudo`
-#RUN_SUDO=3D"${SUDO_EXEC} -E"
+#RUN_SUDO=3D"sudo -E"<= br>
TEST_RUN_LIST=3D"1 2 3 10 11"<= br>
diff --git a/tests/t_server_null.sh b/tests/t_se= rver_null.sh
index 0e53ba4..7627edf 100755
= --- a/tests/t_server_null.sh
+++ b/tests/t_server_null.sh
@@ -1,4 +1,4 @@
-#!/usr/bin/env sh
+#!/bin/sh
#
TSERVER_NULL_SKIP_RC= =3D"${TSERVER_NULL_SKIP_RC:-77}"

@@ -57,12 +57,7 @@


srcdir=3D"${sr= cdir:-.}"

-if [ -z "${RUN_SUDO}" ]; then
- "${srcdir}/t_server_null_server.sh&qu= ot; &
-else<= br>- $RUN_SUDO "${srcdir}= /t_server_null_server.sh" &
-fi
-
+"${srcdir}/t_serve= r_null_server.sh" &
"${srcdir}/t_server_null= _client.sh"
retval=3D$?

<= span>diff --git a/tests/t_server_null_client.sh b/tests/t_server_null_clien= t.sh

index 8890007..e7dd332 100755
--- a/te= sts/t_server_null_client.sh
+++ b/tests/t_server_null_clien= t.sh
@@ -1,4 +1,4 @@
-#!/usr/bin/env sh
+#!/bin/sh

launch_client() {=
test_name=3D$1
@@ -76,19 +76,22 @@
count=3D0
server_max_wait=3D15
while [ $count -lt $server_max_wait ]; do

- server_pids=3D""
- server_count=3D$(set|grep 'SERVER= _NAME_'|wc -l)
+ = servers_up=3D0
+ = server_count=3D$(echo $TEST_SERVER_LIST|wc -w)
# We need to trim single-quotes because some shells return quo= ted values
# and some don't. Using "set -o po= six" which would resolve this problem is
# not su= pported in all shells.
+ # While= inactive server configurations may get checked they won't increase
+ # the active server= count as the processes won't be running.
for i in= `set|grep 'SERVER_NAME_'|cut -d "=3D" -f 2|tr -d "[= \']"`; do
server_pid=3D$(cat $i.pid 2>= /dev/null)
- se= rver_pids=3D"${server_pids} ${server_pid}"
+ if ps -p $server_pid > /dev/nu= ll 2>&1; then
= + servers_up=3D$(( $servers_up + 1 ))
+ fi
done
- servers_u= p=3D$(ps -p $server_pids 2>/dev/null|sed '1d'|wc -l)
<= span style=3D"color: hsl(0, 100%, 40%);">-

echo "= OpenVPN test servers up: ${servers_up}/${server_count}"

if [ $servers_up -ge $server_count ]; then<= br>@@ -101,6 +104,7 @@

if [ $c= ount -eq $server_max_wait ]; then
retval=3D1

+ exit $retval
fi
done

diff --git a/tests/t_server_null_default.rc b/tests/t_server_null_default.= rc

index 63b6bcd..825bb52 100755
--- a/test= s/t_server_null_default.rc
+++ b/tests/t_server_null_defaul= t.rc
@@ -24,7 +24,7 @@
MAX_CLIENTS=3D"= ;10"
CLIENT_MATCH=3D"Test-Client" SERVER_EXEC=3D"${top_builddir}/src/openvpn/openvpn"
-SERVER_BASE_OPTS=3D"--= daemon --local 127.0.0.1 --dev tun --topology subnet --server 10.29.41.0 25= 5.255.255.0 --max-clients $MAX_CLIENTS --persist-tun --verb 3"<= br>+SERVER_BASE_OPTS=3D"--= daemon --local 127.0.0.1 --dev tun --topology subnet --max-clients $MAX_CLI= ENTS --persist-tun --verb 3"
SERVER_CIPHER_OPTS=3D&qu= ot;"
SERVER_CERT_OPTS=3D"--ca ${CA} --dh ${DH} -= -cert ${SERVER_CERT} --key ${SERVER_KEY} --tls-auth ${TA} 0" SERVER_CONF_BASE=3D"${SERVER_BASE_OPTS} ${SERVER_CIPHER_OPTS} = ${SERVER_CERT_OPTS}"
@@ -32,14 +32,16 @@
TEST_SERVER_LIST=3D"1 2"


S= ERVER_NAME_1=3D"t_server_null_server-1194_udp"
+SERVER_SERVER_1=3D"--server 10.29= .41.0 255.255.255.0"
SERVER_MGMT_PORT_1=3D"11194= "
SERVER_EXEC_1=3D"${SERVER_EXEC}"-SERVER_CONF_1=3D"${SERVER= _CONF_BASE} --lport 1194 --proto udp --management 127.0.0.1 ${SERVER_MGMT_P= ORT_1}"
+SERVER_= CONF_1=3D"${SERVER_CONF_BASE} ${SERVER_SERVER_1} --lport 1194 --proto = udp --management 127.0.0.1 ${SERVER_MGMT_PORT_1}"

SERVER_NAME_2=3D"t_server_null_server-1195_tcp"
+SERVER_SERVER_2=3D&quo= t;--server 10.29.42.0 255.255.255.0"
SERVER_MGMT_PORT= _2=3D"11195"
SERVER_EXEC_2=3D"${SERVER_EXEC= }"
-SERVER_CONF_2= =3D"${SERVER_CONF_BASE} --lport 1195 --proto tcp --management 127.0.0.= 1 ${SERVER_MGMT_PORT_2}"
+SERVER_CONF_2=3D"${SERVER_CONF_BASE} ${SERVER_SERVER_2} --lp= ort 1195 --proto tcp --management 127.0.0.1 ${SERVER_MGMT_PORT_2}"

# Test client configurations
CLIENT_EXEC=3D"${top_builddir}/src/openvpn/openvpn"

= diff --git a/tests/t_server_null_server.sh b/tests/t_server_null_serv= er.sh
index 9bc0c88..037baf7 100755
--- a/t= ests/t_server_null_server.sh
+++ b/tests/t_server_null_serv= er.sh
@@ -1,4 +1,4 @@
-#!/usr/bin/env sh
+#!/bin/sh

launch_server() = {
server_name=3D$1
@@ -8,16 +8,23 @@
status=3D"${server_name}.status"
pid=3D"${server_name}.pid"


<= span style=3D"color: hsl(0, 100%, 40%);">- # Ensure that old status, log= and pid files are gone

- rm -f "${status}" "${log}" "${pid}"
-
- "${server_exec}" \
- $server_conf \

- --status "${status}&q= uot; 1 \

- --log= "${log}" \
-= --writepid "${pid}" \
- --explicit-exit-notify 3
-
+ if [ -z "${RUN_SUDO}" ]; then
+ rm -f "${status}" "= ;${log}" "${pid}"
+ "${server_exec}" \
+ $server_conf \
+ --status "${status}" 1= \
+ --log &q= uot;${log}" \
+ = --writepid "${pid}" \
+ --explicit-exit-notify 3
+ else
+ $RUN_SUDO rm -f "${status}" "= ${log}" "${pid}"
+ $RUN_SUDO "${server_exec}" \
+ $server_conf \
+ --s= tatus "${status}" 1 \
+ --log "${log}" \
+ --writepid "$= {pid}" \
+ = --explicit-exit-notify 3
+ fi
}

# Load base/default configuration

@@ -64,15 +71,30 @@

echo "All clients have disconnected = from all servers"

+# Make sure that the server processes are truly dead b= efore exiting. If a
= +# server process does not exit in 15 seconds assume it never will, move on= and
+# hope for the = best.
+echo "Wai= ting for servers to exit"
for PID_FILE in $server_pid= _files
do
SERVER_PID=3D$(cat "${= PID_FILE}")
- $= KILL_EXEC "${SERVER_PID}"

- # Make sure that the server processes a= re truly dead before exiting
- while :
+ = if [ -z "${RUN_SUDO}" ]; then
+ $KILL_EXEC "${SERVER_PID}"<= br>+ else
+ $RUN_SUDO $KILL_EXEC "${S= ERVER_PID}"
+ = fi
+
+ count=3D0

+ maxcount=3D75
+ while [ $count -le $maxcount ]=
do
ps -p "${SERVER_PID}" = > /dev/null || break
+ count=3D$(( count + 1))
sleep 0.2
done
+
+ if [ $count -= ge $maxcount ]; then
= + echo "WARNING: could not kill server with pid ${SERVER_PID}!&= quot;
+ fi<= br> done
diff --git a/tests/t_server_null_stress.sh b= /tests/t_server_null_stress.sh
index 1281397..0bb9452 10075= 5
--- a/tests/t_server_null_stress.sh
+++ b= /tests/t_server_null_stress.sh
@@ -1,4 +1,4 @@
-#!/usr/bin/env sh

+#!/bin/sh
#<= br> # Run this stress test as root to avoid sudo authorization from t= iming out.


To view, v= isit chan= ge 669. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I2cce8ad4e0d262e1404ab1eb6ff= 673d8590b6b3a
Gerrit-Change-Number: 669
Gerrit-PatchSet: 3
Gerrit-Owner: mattock <samuli@...515...>=
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
Gerrit-Attention: mattock <samuli@...515...= >
Gerrit-MessageType: newpatchset
--UckVUFfjTeI=--