Skip to content

Commit a7294df

Browse files
committed
Don't try and enable sudo if ro/non-root even if set
1 parent a7e2b20 commit a7294df

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,15 @@ This image can be run with a read-only container filesystem. For details please
8585
### Caveats
8686

8787
* `/tmp` must be mounted to tmpfs
88-
* sudo will not be available
88+
* `sudo` will not be available
8989

9090
## Non-Root Operation
9191

9292
This image can be run with a non-root user. For details please [read the docs](https://docs.linuxserver.io/misc/non-root/).
9393

9494
### Caveats
9595

96-
* sudo will not be available
96+
* `sudo` will not be available
9797

9898
## Usage
9999

readme-vars.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ opt_param_env_vars:
3939
readonly_supported: true
4040
readonly_message: |
4141
* `/tmp` must be mounted to tmpfs
42-
* sudo will not be available
42+
* `sudo` will not be available
4343
nonroot_supported: true
4444
nonroot_message: |
45-
* sudo will not be available
45+
* `sudo` will not be available
4646
# application setup block
4747
app_setup_block_enabled: true
4848
app_setup_block: |

root/etc/s6-overlay/s6-rc.d/init-code-server/run

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,20 @@
33

44
mkdir -p /config/{extensions,data,workspace,.ssh}
55

6-
if [[ -n "${SUDO_PASSWORD}" ]] || [[ -n "${SUDO_PASSWORD_HASH}" ]]; then
7-
echo "setting up sudo access"
8-
if ! grep -q 'abc' /etc/sudoers; then
9-
echo "adding abc to sudoers"
10-
echo "abc ALL=(ALL:ALL) ALL" >> /etc/sudoers
11-
fi
12-
if [[ -n "${SUDO_PASSWORD_HASH}" ]]; then
13-
echo "setting sudo password using sudo password hash"
14-
sed -i "s|^abc:\!:|abc:${SUDO_PASSWORD_HASH}:|" /etc/shadow
15-
else
16-
echo "setting sudo password using SUDO_PASSWORD env var"
17-
echo -e "${SUDO_PASSWORD}\n${SUDO_PASSWORD}" | passwd abc
6+
if [[ -z ${LSIO_NON_ROOT_USER} ]] && [[ -z ${LSIO_READ_ONLY_FS} ]]; then
7+
if [[ -n "${SUDO_PASSWORD}" ]] || [[ -n "${SUDO_PASSWORD_HASH}" ]]; then
8+
echo "setting up sudo access"
9+
if ! grep -q 'abc' /etc/sudoers; then
10+
echo "adding abc to sudoers"
11+
echo "abc ALL=(ALL:ALL) ALL" >> /etc/sudoers
12+
fi
13+
if [[ -n "${SUDO_PASSWORD_HASH}" ]]; then
14+
echo "setting sudo password using sudo password hash"
15+
sed -i "s|^abc:\!:|abc:${SUDO_PASSWORD_HASH}:|" /etc/shadow
16+
else
17+
echo "setting sudo password using SUDO_PASSWORD env var"
18+
echo -e "${SUDO_PASSWORD}\n${SUDO_PASSWORD}" | passwd abc
19+
fi
1820
fi
1921
fi
2022

0 commit comments

Comments
 (0)