From: "mattock (Code Review)" Date: Tue, 25 Jun 2024 12:59:24 +0000 In-Reply-To: References: Reply-To: samuli@...515..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="kO69M0z64/U="; 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 --kO69M0z64/U= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld, 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 (#2). 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/2 diff --git a/doc/t_server_null.rst b/doc/t_server_null.rst index e3a098a..7acb09d 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 persist 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" =20 +# 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: 2 Gerrit-Owner: mattock Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: flichtenheld Gerrit-MessageType: newpatchset --kO69M0z64/U= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: flichtenheld, plaisthos.

mattock uploaded patch set #2 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/2
diff --git a/doc/t_server_null.rst b/d=
oc/t_server_null.rst
index e3a098a..7acb09d 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 persist keepenv :wheel<= /span>
+
Te= chnical implementation
------------------------
=
@@ -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 fil= es. Each client kills itself after some delay using an "--up" scr= ipt.


= -Note that "make check" moves on once *t_server_null_client.sh* h= as exited. At
-that poi= nt *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 = that launching "make check" runs too
-quickly might cause test failures or unexpected be= havior such as leftover
-OpenVPN server processes.
-
Configuration
-------------=

diff --git a/tests/t_server_null.rc-sample b/te= sts/t_server_null.rc-sample
index 28c3773..98d7869 100644
--- a/tests/t_server_null.rc-sample
+++ b/te= sts/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.s= h
@@ -1,4 +1,4 @@
-#!/usr/bin/env sh
+#!/bin/sh
#
TSERVER_NULL_SKIP_R= C=3D"${TSERVER_NULL_SKIP_RC:-77}"

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


srcdir=3D"${s= rcdir:-.}"

-if [ -z "${RUN_SUDO}" ]; then
- "${srcdir}/t_server_null_server.sh= " &
-else
- $RUN_SUDO "${srcd= ir}/t_server_null_server.sh" &
-fi
-<= /span>
+"${srcdir}/t_se= rver_null_server.sh" &
"${srcdir}/t_server_n= ull_client.sh"
retval=3D$?
diff --git a/tests/t_server_null_client.sh b/tests/t_server_null_cl= ient.sh
index 8890007..e7dd332 100755
--- a= /tests/t_server_null_client.sh
+++ b/tests/t_server_null_cl= ient.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 'SER= VER_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 values
# and some don't. Using "set -o= posix" which would resolve this problem is
# not= supported in all shells.
+ #
+ # Wh= ile inactive server configurations may get checked they won't increase<= /span>
+ # the active ser= ver count as the processes won't be running.
for i= in `set|grep 'SERVER_NAME_'|cut -d "=3D" -f 2|tr -d &quo= t;[\']"`; do
server_pid=3D$(cat $i.pid 2&= gt; /dev/null)
- = server_pids=3D"${server_pids} ${server_pid}"
+ if ps -p $server_pid > /dev/= null 2>&1; then
+ fi
done<= br>
- servers= _up=3D$(ps -p $server_pids 2>/dev/null|sed '1d'|wc -l)-
echo &quo= t;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_defaul= t.rc

index 63b6bcd..825bb52 100755
--- a/te= sts/t_server_null_default.rc
+++ b/tests/t_server_null_defa= ult.rc
@@ -24,7 +24,7 @@
MAX_CLIENTS=3D&qu= ot;10"
CLIENT_MATCH=3D"Test-Client"<= br> 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_C= LIENTS --persist-tun --verb 3"
SERVER_CIPHER_OPTS=3D&= quot;"
SERVER_CERT_OPTS=3D"--ca ${CA} --dh ${DH}= --cert ${SERVER_CERT} --key ${SERVER_KEY} --tls-auth ${TA} 0"<= br> SERVER_CONF_BASE=3D"${SERVER_BASE_OPTS} ${SERVER_CIPHER_OPTS= } ${SERVER_CERT_OPTS}"
@@ -32,14 +32,16 @@
<= span> 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"111= 94"
SERVER_EXEC_1=3D"${SERVER_EXEC}"=
-SERVER_CONF_1=3D"${SERV= ER_CONF_BASE} --lport 1194 --proto udp --management 127.0.0.1 ${SERVER_MGMT= _PORT_1}"
+SERVE= R_CONF_1=3D"${SERVER_CONF_BASE} ${SERVER_SERVER_1} --lport 1194 --prot= o udp --management 127.0.0.1 ${SERVER_MGMT_PORT_1}"
<= /span>
SERVER_NAME_2=3D"t_server_null_server-1195_tcp"<= /span>
+SERVER_SERVER_2=3D&q= uot;--server 10.29.42.0 255.255.255.0"
SERVER_MGMT_PO= RT_2=3D"11195"
SERVER_EXEC_2=3D"${SERVER_EX= EC}"
-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} --l= port 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_ser= ver.sh
index 9bc0c88..037baf7 100755
--- a/= tests/t_server_null_server.sh
+++ b/tests/t_server_null_ser= ver.sh
@@ -1,4 +1,4 @@
-#!/usr/bin/env sh
+#!/bin/sh

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


= - # Ensure that old status, lo= g and pid files are gone
-
- "${server_exec}" \
= - $server_conf \- --status "${status= }" 1 \
- --= log "${log}" \
- --explicit-exit-notify 3
-
+ if [ -z "${RUN_SUDO}" ]; then
+ rm -f "${status}" &q= uot;${log}" "${pid}"
+ "${server_exec}" \
+ $server_conf \
+ --status "${status}&quo= t; 1 \
+ --lo= g "${log}" \
+ --explicit-exit-notify 3
+ else
+ $RUN_SUDO rm -f "${status}" &q= uot;${log}" "${pid}"
+ $RUN_SUDO "${server_exec}" \
+ $server_conf = \

+ = --status "${status}" 1 \
+ --log "${log}" \
+ --writepid &qu= ot;${pid}" \

+ = --explicit-exit-notify 3
+ fi
}
# Load base/default configuration
@@ -64,15 +71,30 = @@

echo "All clients have disconnec= ted from all servers"

+# Make sure that the server processes are truly de= ad before exiting. If a
+# server process does not exit in 15 seconds assume it never will, mov= e on and
+# hope for = the best.
+echo "= ;Waiting for servers to exit"
for PID_FILE in $server= _pid_files
do
SERVER_PID=3D$(cat &quo= t;${PID_FILE}")
- = $KILL_EXEC "${SERVER_PID}"

- # Make sure that the server process= es are truly dead before exiting
- while :
+ $KILL_EXEC "${SERVER_PID}"
+ else
+ $RUN_SUDO $KILL_EXEC "= ;${SERVER_PID}"

= + fi
+
<= span style=3D"color: hsl(120, 100%, 40%);">+ 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
+ fi
done
diff --git a/tests/t_server_null_stress.sh= b/tests/t_server_null_stress.sh
index 1281397..0bb9452 100= 755
--- 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 ch= ange 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: 2
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: flichtenheld <frank@...2375...= 41...>
Gerrit-MessageType: newpatchset
--kO69M0z64/U=--