testing: Fix 'unsafe repository' error when accessing Git repository

A recent security fix for Git added a fatal error if the directory that
contains the .git directory is not owned by the user that runs git in
that directory tree:

  Determine strongSwan version fatal: unsafe repository ('...' is owned by someone else)

To avoid this, we call the git commands as owner of the source
directory (the script has to run as root, so this is no problem).

The user/group ID and name is now also determined via `stat(1)` so it
directly depends on the actual source dir and should work even when not
using sudo.
This commit is contained in:
Tobias Brunner
2022-05-02 11:09:14 +02:00
parent d23c0ea81e
commit cc094c30d1
+6 -5
View File
@@ -8,9 +8,6 @@ DIR=$(dirname `readlink -f $0`)
[ -f "$BASEIMG" ] || die "Base image $BASEIMG not found"
running_any $STRONGSWANHOSTS && die "Please stop test environment before running $0"
SRCUID=${SUDO_UID:-$(id -u)}
SRCGID=${SUDO_GID:-$(id -g)}
check_commands partprobe qemu-img qemu-nbd
load_qemu_nbd
@@ -137,15 +134,19 @@ log_action "Remove SWID tags of previous strongSwan versions"
execute_chroot "find /usr/local/share -path '*strongswan*' -name *.swidtag -delete"
if [ -z "$TARBALL" ]; then
SRCUID=$(stat -c '%u' $SWANDIR)
SRCGID=$(stat -c '%g' $SWANDIR)
SRCUSER=$(stat -c '%U' $SWANDIR)
mkdir -p $LOOPDIR/root/strongswan
log_action "Mounting $SWANDIR as /root/strongswan"
execute "bindfs -u $SRCUID -g $SRCGID --create-for-user=$SRCUID --create-for-group=$SRCGID $SWANDIR $LOOPDIR/root/strongswan"
do_on_exit umount $LOOPDIR/root/strongswan
log_action "Determine strongSwan version"
desc=`git -C $SWANDIR describe --exclude 'android-*' --dirty`
desc=`runuser -u $SRCUSER -- git -C $SWANDIR describe --exclude 'android-*' --dirty`
if [ $? -eq 0 ]; then
version="$desc (`git -C $SWANDIR rev-parse --abbrev-ref HEAD`)"
version="$desc (`runuser -u $SRCUSER -- git -C $SWANDIR rev-parse --abbrev-ref HEAD`)"
else
version="`cat $SWANDIR/configure.ac | sed -n '/^AC_INIT/{ s/.*,\[\(.*\)\])$/\1/p }'`"
fi