Don't try and enable sudo if ro/non-root even if set

This commit is contained in:
thespad 2025-05-11 14:36:04 +01:00
parent a7e2b20ca2
commit a7294dfb09
No known key found for this signature in database
3 changed files with 18 additions and 16 deletions

View File

@ -85,7 +85,7 @@ This image can be run with a read-only container filesystem. For details please
### Caveats
* `/tmp` must be mounted to tmpfs
* sudo will not be available
* `sudo` will not be available
## Non-Root Operation
@ -93,7 +93,7 @@ This image can be run with a non-root user. For details please [read the docs](h
### Caveats
* sudo will not be available
* `sudo` will not be available
## Usage

View File

@ -39,10 +39,10 @@ opt_param_env_vars:
readonly_supported: true
readonly_message: |
* `/tmp` must be mounted to tmpfs
* sudo will not be available
* `sudo` will not be available
nonroot_supported: true
nonroot_message: |
* sudo will not be available
* `sudo` will not be available
# application setup block
app_setup_block_enabled: true
app_setup_block: |

View File

@ -3,18 +3,20 @@
mkdir -p /config/{extensions,data,workspace,.ssh}
if [[ -n "${SUDO_PASSWORD}" ]] || [[ -n "${SUDO_PASSWORD_HASH}" ]]; then
echo "setting up sudo access"
if ! grep -q 'abc' /etc/sudoers; then
echo "adding abc to sudoers"
echo "abc ALL=(ALL:ALL) ALL" >> /etc/sudoers
fi
if [[ -n "${SUDO_PASSWORD_HASH}" ]]; then
echo "setting sudo password using sudo password hash"
sed -i "s|^abc:\!:|abc:${SUDO_PASSWORD_HASH}:|" /etc/shadow
else
echo "setting sudo password using SUDO_PASSWORD env var"
echo -e "${SUDO_PASSWORD}\n${SUDO_PASSWORD}" | passwd abc
if [[ -z ${LSIO_NON_ROOT_USER} ]] && [[ -z ${LSIO_READ_ONLY_FS} ]]; then
if [[ -n "${SUDO_PASSWORD}" ]] || [[ -n "${SUDO_PASSWORD_HASH}" ]]; then
echo "setting up sudo access"
if ! grep -q 'abc' /etc/sudoers; then
echo "adding abc to sudoers"
echo "abc ALL=(ALL:ALL) ALL" >> /etc/sudoers
fi
if [[ -n "${SUDO_PASSWORD_HASH}" ]]; then
echo "setting sudo password using sudo password hash"
sed -i "s|^abc:\!:|abc:${SUDO_PASSWORD_HASH}:|" /etc/shadow
else
echo "setting sudo password using SUDO_PASSWORD env var"
echo -e "${SUDO_PASSWORD}\n${SUDO_PASSWORD}" | passwd abc
fi
fi
fi