Skip to content

Commit

Permalink
webui: Run browser as liveuser instead of root
Browse files Browse the repository at this point in the history
It's not a good idea to run UI code as root if we can help it, and
since the webui separates front end from backend, we don't need to
run the front end code as root.

This commit changes webui-desktop to start firefox as the liveuser.

The entire script could probably be run unprivileged with a few
changes to the cockpit parts (different port, new polkit policy,
cockpit.spawn changes to run as superuser), but that's a change
for another time.
  • Loading branch information
halfline committed Aug 31, 2023
1 parent 1c6b6c0 commit 75fedfc
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions ui/webui/webui-desktop
Expand Up @@ -66,21 +66,32 @@ esac

# prepare empty firefox profile dir with theme based on the passed profile id
FIREFOX_THEME_DIR="/usr/share/anaconda/firefox-theme"
FIREFOX_PROFILE_PATH="/tmp/anaconda-firefox-profile"

# PKEXEC_UID is the uid for "gnome-initial-setup" or "liveuser"
# depending on how the installer gets started.
#
# It's unset on non-live-images, so we just use the current user then (root)
if [ -n "$PKEXEC_UID" ]; then
INSTALLER_USER=$(id -n -u ${PKEXEC_UID})
else
INSTALLER_USER=$(id -n -u)
fi

FIREFOX_PROFILE_PATH="${XDG_RUNTIME_DIR}/anaconda/firefox-profile"

# make sure the profile directory exists and is empty
if [ -d ${FIREFOX_PROFILE_PATH} ]
then
echo "Cleaning up existing Anaconda Firefox profile directory."
rm -rf ${FIREFOX_PROFILE_PATH}
fi
mkdir -p ${FIREFOX_PROFILE_PATH}
pkexec --user "${INSTALLER_USER}" mkdir -p ${FIREFOX_PROFILE_PATH}

# populate the profile directory with our custom Firefox theme
# - theme id is passed as the second argument of this script
THEME_PATH="${FIREFOX_THEME_DIR}/${THEME_ID}"

cp -a "${THEME_PATH}/." ${FIREFOX_PROFILE_PATH}
pkexec --user "${INSTALLER_USER}" cp -a "${THEME_PATH}/." ${FIREFOX_PROFILE_PATH}

# FIXME: is this hardcoded resolution necessary ?
BROWSER=(/usr/bin/firefox --new-instance --window-size "1024,768" --profile "${FIREFOX_PROFILE_PATH}")
Expand Down Expand Up @@ -122,11 +133,9 @@ else
sleep 3
fi

# We're running firefox as root, and it doesn't like that, so clear XAUTHORITY and
# XDG_RUNTIME_DIR so it is willing to start.
unset XAUTHORITY XDG_RUNTIME_DIR
readarray -t user_environment < <(pkexec --user "${INSTALLER_USER}" env XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR}" systemctl --user show-environment)

HOME="$BROWSER_HOME" "${BROWSER[@]}" http://"$WEBUI_ADDRESS""$URL_PATH" &
HOME="$BROWSER_HOME" pkexec --user $INSTALLER_USER env "${user_environment[@]}" "${BROWSER[@]}" http://"$WEBUI_ADDRESS""$URL_PATH" &
B_PID=$!

wait $B_PID

0 comments on commit 75fedfc

Please sign in to comment.