* Backend daemon drops privileges after initialization (to not run as root)

* New config option `CLICON_USER` with default value `clicon`
  * Can also be set with `-U <user>` clixon_backend command-line option
This commit is contained in:
Olof hagsand 2019-09-11 21:24:14 +02:00
parent 3806f7652e
commit 3d5abb77f9
60 changed files with 238 additions and 93 deletions

View file

@ -91,6 +91,9 @@ testname=
: ${IETFRFC=../yang/standard}
#: ${IETFRFC=$YANGMODELS/standard/ietf/RFC}
# Backend user
BUSER=clicon
# Follow the binary programs that can be parametrized (eg with valgrind)
: ${clixon_cli:=clixon_cli}
@ -170,6 +173,7 @@ stop_backend(){
sleep 1
checkvalgrind
fi
sudo pkill -f clixon_backend # extra ($BUSER?)
}
# Wait for restconf to stop sending 502 Bad Gateway

View file

@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
# yang augment and identityref tests in different modules
# See RFC7950 Sec 7.17
# This test defines an example-augment module which augments an interface
@ -218,12 +218,11 @@ fi
new "Kill backend"
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
sudo pkill -u root -f clixon_backend
rm -rf $dir

View file

@ -287,7 +287,7 @@ fi
new "Kill backend"
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi

View file

@ -126,7 +126,7 @@ fi
new "Kill backend"
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi

View file

@ -118,7 +118,7 @@ fi
new "Kill backend"
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi

View file

@ -132,7 +132,7 @@ fi
new "Kill backend"
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi

View file

@ -163,7 +163,7 @@ fi
new "Kill backend"
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi

View file

@ -191,7 +191,7 @@ fi
new "Kill backend"
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi

View file

@ -316,7 +316,7 @@ fi
new "Kill backend"
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi

View file

@ -194,7 +194,7 @@ fi
new "Kill backend"
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi

View file

@ -231,7 +231,7 @@ fi
new "Kill backend"
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi

View file

@ -188,7 +188,7 @@ fi
new "Kill backend"
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi

View file

@ -153,7 +153,7 @@ EOF
if [ $BE -ne 0 ]; then # Bring your own backend
new "Kill backend"
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi

View file

@ -216,7 +216,7 @@ fi
new "Kill backend"
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi

View file

@ -279,7 +279,7 @@ fi
new "Kill backend"
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi

View file

@ -258,7 +258,7 @@ fi
new "Kill backend"
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi

View file

@ -223,7 +223,7 @@ fi
new "Kill backend"
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi

View file

@ -211,7 +211,7 @@ fi
new "Kill backend"
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi

View file

@ -395,7 +395,7 @@ fi
new "Kill backend"
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi

View file

@ -743,7 +743,7 @@ expectfn "$clixon_cli -1f $cfg -l o set c threematch abcg" 255 '^CLI syntax erro
if [ $BE -ne 0 ]; then
new "Kill backend"
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi

View file

@ -237,7 +237,7 @@ fi
new "Kill backend"
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi

View file

@ -145,7 +145,7 @@ fi
new "Kill backend"
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi

View file

@ -278,7 +278,7 @@ fi
new "Kill backend"
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi

View file

@ -200,7 +200,7 @@ fi
new "Kill backend"
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi

View file

@ -116,7 +116,7 @@ fi
new "Kill backend"
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi

View file

@ -261,7 +261,7 @@ fi
new "Kill backend"
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi

View file

@ -157,7 +157,7 @@ fi
new "Kill backend"
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi

View file

@ -209,7 +209,7 @@ fi
new "Kill backend"
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi

View file

@ -89,7 +89,7 @@ testrun(){
if [ $BE -ne 0 ]; then
new "Kill backend"
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi
@ -120,8 +120,11 @@ sudo rm -f $dir/startup_db;
new "Run without startup option, check running is copied"
testrun ""
new "Check startup should not exist"
if [ -f $dir/startup_db ]; then
err "startup should not exist"
new "Check startup is empty"
if [ ! -f $dir/startup_db ]; then
err "startup does not exist"
fi
if [ -s $dir/startup_db ]; then
err "startup is not empty"
fi
rm -rf $dir

View file

@ -164,7 +164,7 @@ fi
new "Kill backend"
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi

View file

@ -102,7 +102,7 @@ testrun(){
new "Kill backend"
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi

View file

@ -291,7 +291,7 @@ fi
new "Kill backend"
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi

View file

@ -224,7 +224,7 @@ fi
new "Kill backend"
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi

View file

@ -311,7 +311,7 @@ fi
new "Kill backend"
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi

View file

@ -628,7 +628,7 @@ EOF
if [ $BE -ne 0 ]; then
new "Kill backend"
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi

View file

@ -306,7 +306,7 @@ testrange string "012" "01234567890" ""
if [ $BE -ne 0 ]; then
new "Kill backend"
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi

View file

@ -107,7 +107,7 @@ fi
new "Kill backend"
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi

View file

@ -216,7 +216,7 @@ fi
new "Kill backend"
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi

View file

@ -283,7 +283,7 @@ runtest(){
if [ $BE -ne 0 ]; then
new "Kill backend"
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi

View file

@ -274,7 +274,7 @@ stop_restconf
if [ $BE -ne 0 ]; then
new "Kill backend"
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi

View file

@ -285,7 +285,7 @@ testrun(){
if [ $BE -ne 0 ]; then
new "Kill backend"
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi

View file

@ -151,7 +151,7 @@ stop_restconf
if [ $BE -ne 0 ]; then
new "Kill backend"
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi

View file

@ -147,7 +147,7 @@ fi
new "Kill backend"
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi

View file

@ -112,7 +112,7 @@ fi
new "Kill backend"
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi

View file

@ -286,12 +286,11 @@ fi
new "Kill backend"
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi
# kill backend
stop_backend -f "$cfg"
sudo pkill -u root -f clixon_backend
rm -rf "$dir"

View file

@ -114,7 +114,7 @@ expecteof "$clixon_netconf -qf $cfg -D $DBG" 0 "<rpc><get-config><source><candid
if [ $BE -ne 0 ]; then
new "Kill backend"
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi

View file

@ -100,7 +100,7 @@ expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><edit-config><target><candidate/></
if [ $BE -ne 0 ]; then
new "Kill backend"
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi
@ -149,7 +149,7 @@ expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><edit-config><target><candidate/></
if [ $BE -ne 0 ]; then
new "Kill backend"
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi
@ -193,7 +193,7 @@ expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><edit-config><target><candidate/></
if [ $BE -ne 0 ]; then
new "Kill backend"
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi
@ -237,7 +237,7 @@ expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><edit-config><target><candidate/></
if [ $BE -ne 0 ]; then
new "Kill backend"
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi
@ -281,7 +281,7 @@ expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><edit-config><target><candidate/></
if [ $BE -ne 0 ]; then
new "Kill backend"
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi
@ -326,7 +326,7 @@ expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><edit-config><target><candidate/></
if [ $BE -ne 0 ]; then
new "Kill backend"
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi
@ -372,7 +372,7 @@ expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><edit-config><target><candidate/></
if [ $BE -ne 0 ]; then
new "Kill backend"
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi
@ -418,7 +418,7 @@ expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><edit-config><target><candidate/></
if [ $BE -ne 0 ]; then
new "Kill backend"
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi

View file

@ -137,7 +137,7 @@ if [ $BE -eq 0 ]; then
fi
new "Kill backend"
# Check if premature kill
pid=`pgrep -u root -f clixon_backend`
pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi