3232# DBX_CONTAINER_MANAGER
3333# DBX_CONTAINER_NAME
3434# DBX_CONTAINER_CLEAN_PATH
35+ # DBX_CONTAINER_RUNUSER
3536# DBX_NON_INTERACTIVE
3637# DBX_VERBOSE
3738# DBX_SKIP_WORKDIR
@@ -109,6 +110,7 @@ headless=0
109110skip_workdir=0
110111verbose=0
111112clean_path=0
113+ use_runuser=0
112114version=" 1.8.2.3"
113115
114116# Source configuration files, this is done in an hierarchy so local files have
@@ -146,6 +148,9 @@ if [ "$(id -ru)" -ne 0 ]; then
146148 distrobox_sudo_program=${DBX_SUDO_PROGRAM:- ${distrobox_sudo_program:- " sudo" } }
147149fi
148150
151+ # Read distrobox_container_runuser from config or env
152+ distrobox_container_runuser=${DBX_CONTAINER_RUNUSER:- ${distrobox_container_runuser:- 0} }
153+
149154[ -n " ${DBX_CONTAINER_MANAGER} " ] && container_manager=" ${DBX_CONTAINER_MANAGER} "
150155[ -n " ${DBX_CONTAINER_NAME} " ] && container_name=" ${DBX_CONTAINER_NAME} "
151156[ -n " ${DBX_CONTAINER_CLEAN_PATH} " ] && clean_path=1
158163[ " ${non_interactive} " = " false" ] && non_interactive=0
159164[ " ${verbose} " = " true" ] && verbose=1
160165[ " ${verbose} " = " false" ] && verbose=0
166+ [ " ${distrobox_container_runuser} " = " true" ] && use_runuser=1
167+ [ " ${distrobox_container_runuser} " = " false" ] && use_runuser=0
168+ [ " ${distrobox_container_runuser} " = " 1" ] && use_runuser=1
169+ [ " ${distrobox_container_runuser} " = " 0" ] && use_runuser=0
161170
162171# show_help will print usage to stdout.
163172# Arguments:
@@ -193,6 +202,7 @@ Options:
193202 --root/-r: launch podman/docker/lilipod with root privileges. Note that if you need root this is the preferred
194203 way over "sudo distrobox" (note: if using a program other than 'sudo' for root privileges is necessary,
195204 specify it through the DBX_SUDO_PROGRAM env variable, or 'distrobox_sudo_program' config variable)
205+ --container-runuser/-R: inside the container, use runuser instead of su for user switching (only when unshare_groups is enabled)
196206 --dry-run/-d: only print the container manager command generated
197207 --verbose/-v: show more verbosity
198208 --version/-V: show version
@@ -231,6 +241,10 @@ while :; do
231241 shift
232242 skip_workdir=1
233243 ;;
244+ -R | --container-runuser)
245+ shift
246+ use_runuser=1
247+ ;;
234248 -n | --name)
235249 if [ -n " $2 " ]; then
236250 container_name=" $2 "
@@ -696,7 +710,7 @@ if [ "${container_custom_command}" -eq 0 ]; then
696710fi
697711
698712# If we have a command and we're unsharing groups, we need to execute those
699- # command using su $container_command_user
713+ # command using su $container_command_user (or runuser if --runuser is specified)
700714# if we're in a tty, also allocate one
701715if [ " ${unshare_groups:- 0} " -eq 1 ]; then
702716 # shellcheck disable=SC2089,SC2016
@@ -707,7 +721,11 @@ if [ "${unshare_groups:-0}" -eq 1 ]; then
707721 fi
708722 set -- " -m" " $@ "
709723 set -- " ${container_command_user} " " $@ "
710- set -- " su" " $@ "
724+ if [ " ${use_runuser} " -eq 1 ]; then
725+ set -- " runuser" " $@ "
726+ else
727+ set -- " su" " $@ "
728+ fi
711729fi
712730
713731# Generate the exec command and run it
0 commit comments