Skip to content

Commit da3a74c

Browse files
authored
Merge pull request #48 from linuxserver/hash
Allow setting sudo password via hash
2 parents d1ece86 + 9e43559 commit da3a74c

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ services:
9292
- TZ=Europe/London
9393
- PASSWORD=password #optional
9494
- SUDO_PASSWORD=password #optional
95+
- SUDO_PASSWORD_HASH= #optional
9596
- PROXY_DOMAIN=code-server.my.domain #optional
9697
volumes:
9798
- /path/to/appdata/config:/config
@@ -110,6 +111,7 @@ docker run -d \
110111
-e TZ=Europe/London \
111112
-e PASSWORD=password `#optional` \
112113
-e SUDO_PASSWORD=password `#optional` \
114+
-e SUDO_PASSWORD_HASH= `#optional` \
113115
-e PROXY_DOMAIN=code-server.my.domain `#optional` \
114116
-p 8443:8443 \
115117
-v /path/to/appdata/config:/config \
@@ -130,6 +132,7 @@ Container images are configured using parameters passed at runtime (such as thos
130132
| `-e TZ=Europe/London` | Specify a timezone to use EG Europe/London |
131133
| `-e PASSWORD=password` | Optional web gui password, if not provided, there will be no auth. |
132134
| `-e SUDO_PASSWORD=password` | If this optional variable is set, user will have sudo access in the code-server terminal with the specified password. |
135+
| `-e SUDO_PASSWORD_HASH=` | Optionally set sudo password via hash (takes priority over `SUDO_PASSWORD` var). Format is `$type$salt$hashed`. |
133136
| `-e PROXY_DOMAIN=code-server.my.domain` | If this optional variable is set, this domain will be proxied for subdomain proxying. See [Documentation](https://github.com/cdr/code-server/blob/master/doc/FAQ.md#sub-domains) |
134137
| `-v /config` | Contains all relevant configuration files. |
135138

@@ -247,6 +250,7 @@ Once registered you can define the dockerfile to use with `-f Dockerfile.aarch64
247250

248251
## Versions
249252

253+
* **23.12.20:** - Allow setting sudo password via hash using env var `SUDO_PASSWORD_HASH`.
250254
* **29.05.20:** - Add --domain-proxy support.
251255
* **21.05.20:** - Shrink images, install via yarn, fix arm32v7 build.
252256
* **18.05.20:** - Switch to multi-arch images, install via npm.

readme-vars.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,14 @@ param_ports:
4242
- { external_port: "8443", internal_port: "8443", port_desc: "web gui" }
4343
param_usage_include_env: true
4444
param_env_vars:
45-
- { env_var: "TZ", env_value: "Europe/London", desc: "Specify a timezone to use EG Europe/London"}
45+
- { env_var: "TZ", env_value: "Europe/London", desc: "Specify a timezone to use EG Europe/London" }
4646

4747
# optional container parameters
4848
opt_param_usage_include_env: true
4949
opt_param_env_vars:
50-
- { env_var: "PASSWORD", env_value: "password", desc: "Optional web gui password, if not provided, there will be no auth."}
51-
- { env_var: "SUDO_PASSWORD", env_value: "password", desc: "If this optional variable is set, user will have sudo access in the code-server terminal with the specified password."}
50+
- { env_var: "PASSWORD", env_value: "password", desc: "Optional web gui password, if not provided, there will be no auth." }
51+
- { env_var: "SUDO_PASSWORD", env_value: "password", desc: "If this optional variable is set, user will have sudo access in the code-server terminal with the specified password." }
52+
- { env_var: "SUDO_PASSWORD_HASH", env_value: "", desc: "Optionally set sudo password via hash (takes priority over `SUDO_PASSWORD` var). Format is `$type$salt$hashed`." }
5253
- { env_var: "PROXY_DOMAIN", env_value: "code-server.my.domain", desc: "If this optional variable is set, this domain will be proxied for subdomain proxying. See [Documentation](https://github.com/cdr/code-server/blob/master/doc/FAQ.md#sub-domains)" }
5354

5455
optional_block_1: false
@@ -68,7 +69,8 @@ app_setup_block: |
6869
6970
# changelog
7071
changelogs:
71-
- { date: "29.05.20:", desc: "Add --domain-proxy support."}
72+
- { date: "23.12.20:", desc: "Allow setting sudo password via hash using env var `SUDO_PASSWORD_HASH`." }
73+
- { date: "29.05.20:", desc: "Add --domain-proxy support." }
7274
- { date: "21.05.20:", desc: "Shrink images, install via yarn, fix arm32v7 build." }
7375
- { date: "18.05.20:", desc: "Switch to multi-arch images, install via npm." }
7476
- { date: "29.04.20:", desc: "Update start arguments." }

root/etc/cont-init.d/30-config

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,19 @@
22

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

5-
if [ -n "${SUDO_PASSWORD}" ]; then
5+
if [ -n "${SUDO_PASSWORD}" ] || [ -n "${SUDO_PASSWORD_HASH}" ]; then
66
echo "setting up sudo access"
77
if ! grep -q 'abc' /etc/sudoers; then
88
echo "adding abc to sudoers"
99
echo "abc ALL=(ALL:ALL) ALL" >> /etc/sudoers
1010
fi
11-
echo "setting sudo password"
12-
echo -e "${SUDO_PASSWORD}\n${SUDO_PASSWORD}" | passwd abc
11+
if [ -n "${SUDO_PASSWORD_HASH}" ]; then
12+
echo "setting sudo password using sudo password hash"
13+
sed -i "s|^abc:\!:|abc:${SUDO_PASSWORD_HASH}:|" /etc/shadow
14+
else
15+
echo "setting sudo password using SUDO_PASSWORD env var"
16+
echo -e "${SUDO_PASSWORD}\n${SUDO_PASSWORD}" | passwd abc
17+
fi
1318
fi
1419

1520
# permissions

0 commit comments

Comments
 (0)