Skip to content

feat: run foreground as current user, support arbitrary UIDs - #136

Open
dotconfig404 wants to merge 1 commit into
OpenVoxProject:mainfrom
dotconfig404:feat/foreground-arbitrary-uid
Open

feat: run foreground as current user, support arbitrary UIDs#136
dotconfig404 wants to merge 1 commit into
OpenVoxProject:mainfrom
dotconfig404:feat/foreground-arbitrary-uid

Conversation

@dotconfig404

@dotconfig404 dotconfig404 commented Jul 27, 2026

Copy link
Copy Markdown

Pull Request (PR) description

Currently the foreground script is used to switch to a service user when executed as root (among other things). It also lets you keep the user that you executed it as in this check (added in this PR).

That check resolves id -u ${USER} to check if it matches the executing UID, but when running containers with arbitrary UIDs the runtime user usually does not have a username. Currently the server container is using a sed command to clear the USER variable, as id -u without an argument resolves in the current user's ID. This PR would remove the need for the USER variable when no user switch is required (or possible).

If running as root and USER is set, switch to user. If not, just run. Before it would also effectively check if USER matches the executing user's name (by comparing the UID that belongs to the username). This and the su/sudo branches do not make sense anymore if the script is intended as container only, which it is.

Behaviour changes: a non-root UID that doesn't match USER now starts the service as that UID instead of failing in the sudo/su branches, and root with an empty USER now runs as root instead of failing with runuser: user does not exist.

PS: the runuser: user does not exist error can be replicated using:

docker run --rm --user 0 --entrypoint /bin/bash ghcr.io/openvoxproject/openvoxserver:latest -c '
  grep -n "^ *USER=" /etc/default/puppetserver
  /opt/puppetlabs/server/bin/puppetserver foreground
  echo "exit code: $?"'

runuser: user does not exist or the user entry does not contain all the required fields

EDIT: The reason I swapped to cd was that popd was unreachable anyways, exec replaces the shell with the JVM. popd/pushd does not make sense here.

Copilot AI review requested due to automatic review settings July 27, 2026 14:00

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the container-focused foreground startup script to better support container runtimes that run with arbitrary UIDs (often without a corresponding username). It removes the prior UID/username matching and sudo/su branching, and instead only drops privileges when running as root and a service USER is set.

Changes:

  • Replace pushd/popd with a simple cd into ${INSTALL_DIR} before launching.
  • When started as root and USER is non-empty (and runuser exists), drop privileges via runuser.
  • Otherwise, run the service as the current runtime user/UID (supporting arbitrary UID containers).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

sudo -H -u "${USER}" $COMMAND
else
su "${USER}" -s /bin/bash -c "$COMMAND"
cd "${INSTALL_DIR}"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a new behaviour, previously pushd also assumed INSTALL_DIR to exist, but the error happened silently (&> /dev/null). Since there is no set -e here it'd continue either way, using cd or not, except that right now it's visible due to no redirection of stderr.

Also, the reason I swapped to cd was that popd was unreachable anyways, exec replaces the shell with the JVM. popd/pushd does not make sense here. Going to edit my PR body to mention this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants