Skip to content

Commit a7e2b20

Browse files
committed
Support ro/non-root
1 parent badac0c commit a7e2b20

File tree

15 files changed

+57
-16
lines changed

15 files changed

+57
-16
lines changed

.editorconfig

100755100644
File mode changed.

.github/CONTRIBUTING.md

100755100644
File mode changed.

.github/FUNDING.yml

100755100644
File mode changed.

.github/ISSUE_TEMPLATE/config.yml

100755100644
File mode changed.

.github/ISSUE_TEMPLATE/issue.bug.yml

100755100644
File mode changed.

.github/ISSUE_TEMPLATE/issue.feature.yml

100755100644
File mode changed.

.github/workflows/call_issue_pr_tracker.yml

100755100644
File mode changed.

.github/workflows/call_issues_cron.yml

100755100644
File mode changed.

.github/workflows/greetings.yml

100755100644
File mode changed.

.github/workflows/permissions.yml

100755100644
File mode changed.

LICENSE

100755100644
File mode changed.

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,23 @@ git config --global user.email "email address"
7878

7979
How to create the [hashed password](https://github.com/cdr/code-server/blob/master/docs/FAQ.md#can-i-store-my-password-hashed).
8080

81+
## Read-Only Operation
82+
83+
This image can be run with a read-only container filesystem. For details please [read the docs](https://docs.linuxserver.io/misc/read-only/).
84+
85+
### Caveats
86+
87+
* `/tmp` must be mounted to tmpfs
88+
* sudo will not be available
89+
90+
## Non-Root Operation
91+
92+
This image can be run with a non-root user. For details please [read the docs](https://docs.linuxserver.io/misc/non-root/).
93+
94+
### Caveats
95+
96+
* sudo will not be available
97+
8198
## Usage
8299

83100
To help you get started creating a container from this image you can either use docker-compose or the docker cli.
@@ -147,6 +164,8 @@ Containers are configured using parameters passed at runtime (such as those abov
147164
| `-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/coder/code-server/blob/main/docs/guide.md#using-a-subdomain) |
148165
| `-e DEFAULT_WORKSPACE=/config/workspace` | If this optional variable is set, code-server will open this directory by default |
149166
| `-v /config` | Contains all relevant configuration files. |
167+
| `--read-only=true` | Run container with a read-only filesystem. Please [read the docs](https://docs.linuxserver.io/misc/read-only/). |
168+
| `--user=1000:1000` | Run container with a non-root user. Please [read the docs](https://docs.linuxserver.io/misc/non-root/). |
150169

151170
## Environment variables from files (Docker secrets)
152171

readme-vars.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ opt_param_env_vars:
3636
- {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`."}
3737
- {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/coder/code-server/blob/main/docs/guide.md#using-a-subdomain)"}
3838
- {env_var: "DEFAULT_WORKSPACE", env_value: "/config/workspace", desc: "If this optional variable is set, code-server will open this directory by default"}
39+
readonly_supported: true
40+
readonly_message: |
41+
* `/tmp` must be mounted to tmpfs
42+
* sudo will not be available
43+
nonroot_supported: true
44+
nonroot_message: |
45+
* sudo will not be available
3946
# application setup block
4047
app_setup_block_enabled: true
4148
app_setup_block: |

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,19 @@ if [[ ! -f /config/.profile ]]; then
2626
cp /root/.profile /config/.profile
2727
fi
2828

29-
# fix permissions (ignore contents of workspace)
30-
PUID=${PUID:-911}
31-
if [[ ! "$(stat -c %u /config/.profile)" == "${PUID}" ]]; then
32-
echo "Change in ownership or new install detected, please be patient while we chown existing files"
33-
echo "This could take some time"
34-
find /config -path "/config/workspace" -prune -o -exec lsiown abc:abc {} +
35-
lsiown abc:abc /config/workspace
36-
fi
37-
chmod 700 /config/.ssh
38-
if [[ -n "$(ls -A /config/.ssh)" ]]; then
39-
find /config/.ssh/ -type d -exec chmod 700 '{}' \;
40-
find /config/.ssh/ -type f -exec chmod 600 '{}' \;
41-
find /config/.ssh/ -type f -iname '*.pub' -exec chmod 644 '{}' \;
29+
if [[ -z ${LSIO_NON_ROOT_USER} ]]; then
30+
# fix permissions (ignore contents of workspace)
31+
PUID=${PUID:-911}
32+
if [[ ! "$(stat -c %u /config/.profile)" == "${PUID}" ]]; then
33+
echo "Change in ownership or new install detected, please be patient while we chown existing files"
34+
echo "This could take some time"
35+
find /config -path "/config/workspace" -prune -o -exec lsiown abc:abc {} +
36+
lsiown abc:abc /config/workspace
37+
fi
38+
chmod 700 /config/.ssh
39+
if [[ -n "$(ls -A /config/.ssh)" ]]; then
40+
find /config/.ssh/ -type d -exec chmod 700 '{}' \;
41+
find /config/.ssh/ -type f -exec chmod 600 '{}' \;
42+
find /config/.ssh/ -type f -iname '*.pub' -exec chmod 644 '{}' \;
43+
fi
4244
fi

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,21 @@ else
1414
PROXY_DOMAIN_ARG="--proxy-domain=${PROXY_DOMAIN}"
1515
fi
1616

17-
exec \
18-
s6-notifyoncheck -d -n 300 -w 1000 -c "nc -z 127.0.0.1 8443" \
19-
s6-setuidgid abc \
17+
if [[ -z ${LSIO_NON_ROOT_USER} ]]; then
18+
exec \
19+
s6-notifyoncheck -d -n 300 -w 1000 -c "nc -z 127.0.0.1 8443" \
20+
s6-setuidgid abc \
21+
/app/code-server/bin/code-server \
22+
--bind-addr 0.0.0.0:8443 \
23+
--user-data-dir /config/data \
24+
--extensions-dir /config/extensions \
25+
--disable-telemetry \
26+
--auth "${AUTH}" \
27+
"${PROXY_DOMAIN_ARG}" \
28+
"${DEFAULT_WORKSPACE:-/config/workspace}"
29+
else
30+
exec \
31+
s6-notifyoncheck -d -n 300 -w 1000 -c "nc -z 127.0.0.1 8443" \
2032
/app/code-server/bin/code-server \
2133
--bind-addr 0.0.0.0:8443 \
2234
--user-data-dir /config/data \
@@ -25,3 +37,4 @@ exec \
2537
--auth "${AUTH}" \
2638
"${PROXY_DOMAIN_ARG}" \
2739
"${DEFAULT_WORKSPACE:-/config/workspace}"
40+
fi

0 commit comments

Comments
 (0)