openSUSE / microos-toolbox

Script to run a toolbox container on openSUSE MicroOS
Apache License 2.0
54 stars 15 forks source link

Toolbox user created with the useradd default shell (/bin/sh) rather than ${TOOLBOX_SHELL}. #46

Open GentleHumour opened 1 year ago

GentleHumour commented 1 year ago

I'm on OpenSuSE with an Ubuntu Toolbox built according to the toolbox-images/images Ubuntu 20.04 Containerfile.

It was working great, but when I rebuilt a toolbox image dervied from ubuntu-toolbox, suddenly $SHELL is /bin/sh and /etc/passwd shows my toolbox user has /bin/sh as its shell. I note that my toolbox script has not changed, and neither has my ubuntu-toolbox container image. I suspect this is the unintended consequence of a sudo apt-get update in a proprietary installer I am running in a derived toolbox image. Haha no actually that's my fault for alias cat=bat recently, which is of course a terrible blunder and I have undone that, but perhaps that's also another bug in the toolbox script - not specifying the full path to cat? I see that even with cat unaliased, when I enter that toolbox, my $SHELL is /bin/sh, as configured in /etc/passwd, contrary to my desires.

I see in the toolbox script that you are using useradd. On Ubuntu systems, useradd is considered "low level", intended to add both human users and system users, and so the default shell for useradd (configured in /etc/default/useradd) is set to /bin/sh. For interactive users, Ubuntu would prefer that you use adduser instead. Ubuntu further optimises sh by using a fast shell called dash instead.

In my Dockerfile for toolboxen derived from ubuntu-toolbox, I am in fact disabling the dash optimisation because it doesn't play nice with some proprietary tools I'm using.

RUN echo "dash dash/sh boolean false" | debconf-set-selections && \
    DEBIAN_FRONTEND=noninteractive dpkg-reconfigure dash

As a work-around, I could set the system-wide default in the Ubuntu toolbox with sudo useradd -D -s /bin/bash. However, I am concerned about possible unintended consequences for system users added thereafter when packages are installed.

In this context, toolbox is adding an interactive user (usually) and so should use the shell that the interactive user would like to use. So my request is, please add the -s ${TOOLBOX_SHELL} argument to your use of useradd in the toolbox script.

All that said: I tried adding the -s ${TOOLBOX_SHELL} to my local toolbox script and it didn't work, and useradd says that my user already exists in the toolbox, which I find confusing since I am creating a new toolbox and have previously deleted all of the locally cached images with podman rmi. It looks to me like the base ubuntu-toolbox doesn't add a user and it looks like toolbox does add the user on the first create, so I'm confused.

Since I can't work it out, I have resorted to adding:

# AFTER: ${SUDO} $CLI exec --user root "${TOOLBOX_NAME}" bash "${tmp_user_setup}" &> "${tmp_user_setup_log}"
${SUDO} $CLI exec --user root "${TOOLBOX_NAME}" bash -c "chsh -s ${TOOLBOX_SHELL} ${USER_NAME}" 2>&1 >> "${tmp_user_setup_log}"

and that works.