Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed root processes #216

Merged
merged 39 commits into from
Feb 18, 2024
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
21b9419
Added test changes for using user instead of puid and guid
Dashboy1998 Jan 27, 2024
8c1867b
Changes to rcon.yaml
Dashboy1998 Jan 27, 2024
3cc064d
Removes root processes
Dashboy1998 Jan 27, 2024
6a8f307
Running without root
Dashboy1998 Jan 27, 2024
2ae547c
Merge branch 'minimize-root-processes' into removed-root-processes
Dashboy1998 Jan 28, 2024
5ece38b
Merge branch 'minimize-root-processes' into removed-root-processes
Dashboy1998 Jan 28, 2024
1e6756d
Quick fix testing
Dashboy1998 Jan 28, 2024
9eb51ae
Merge branch 'main' into removed-root-processes
Dashboy1998 Jan 30, 2024
41cca9b
Changed so default user is steam
Dashboy1998 Jan 30, 2024
4a99caa
Removed root check from backup.sh
Dashboy1998 Jan 30, 2024
974b96c
Added in root check for init.sh
Dashboy1998 Jan 30, 2024
2cff0dc
Fixed root check
Dashboy1998 Jan 30, 2024
3ff4385
Updated message as PUID/PGID is not used
Dashboy1998 Jan 30, 2024
deadf8d
Fixed permission issue
Dashboy1998 Jan 30, 2024
909835c
Set default user to 1000:1000
Dashboy1998 Jan 30, 2024
207168e
Fixed default port in docker compose
Dashboy1998 Jan 30, 2024
0f442d0
Updated readme
Dashboy1998 Jan 30, 2024
1d706ac
Updated .env.example
Dashboy1998 Jan 30, 2024
3d8fd4f
Added runas for k8s
Dashboy1998 Jan 30, 2024
0390f60
Modified to support PUID/PGID by default
Dashboy1998 Jan 31, 2024
eb4bfde
Updated readme
Dashboy1998 Jan 31, 2024
c55c4b1
Updated readme
Dashboy1998 Jan 31, 2024
b5980bf
Updated linting errors
Dashboy1998 Jan 31, 2024
2bf64ba
Merge branch 'main' into removed-root-processes
Dashboy1998 Feb 1, 2024
0b241ec
Merge branch 'main' into removed-root-processes
Dashboy1998 Feb 2, 2024
7b6b4d8
Merge branch 'main' into removed-root-processes
Dashboy1998 Feb 2, 2024
a724075
Added check to see if /palworld is writable
Dashboy1998 Feb 2, 2024
4080158
Updated permissions
Dashboy1998 Feb 2, 2024
67388de
Merge branch 'main' into removed-root-processes
Dashboy1998 Feb 9, 2024
c321eeb
Merge branch 'main' into removed-root-processes
Dashboy1998 Feb 13, 2024
ea6252f
Changed signle to double quotes
Dashboy1998 Feb 13, 2024
dcbe775
Merge branch 'main' into removed-root-processes
Dashboy1998 Feb 14, 2024
54cea25
Removed k8s in readme
Dashboy1998 Feb 15, 2024
f5e6923
Updated readme and compose to add user
Dashboy1998 Feb 15, 2024
a66d21f
Merge branch 'main' into removed-root-processes
Dashboy1998 Feb 16, 2024
ef4c152
Merge branch 'main' into removed-root-processes
Dashboy1998 Feb 17, 2024
4806147
Remove user in compose and docker run
Dashboy1998 Feb 17, 2024
fe1e2e5
Merge branch 'main' into removed-root-processes
thijsvanloef Feb 18, 2024
02e3a60
update docusaurus
thijsvanloef Feb 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ RUN chmod +x /home/steam/server/*.sh && \
mv /home/steam/server/restore.sh /usr/local/bin/restore

WORKDIR /home/steam/server
RUN touch rcon.yaml crontab && \
chmod o+w rcon.yaml crontab && \
chown steam:steam -R /home/steam && \
chmod -R o+w /home/steam/steamcmd

HEALTHCHECK --start-period=5m \
CMD pgrep "PalServer-Linux" > /dev/null || exit 1
Expand Down
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,29 @@ All files you will need to deploy this container to kubernetes are located in th

Follow the steps in the [README.md here](k8s/readme.md) to deploy it.

### Running without root

This is only for advanced users

It is possible to run this container and
[override the default user](https://docs.docker.com/engine/reference/run/#user) which is root in this image.

Because you are specifiying the user and group `PUID` and `PGID` are ignored.

If you want to find your UID: `id -u`
If you want to find your GID: `id -g`

You must set user to `NUMBERICAL_UID:NUMBERICAL_GID`

Below we assume your UID is 1000 and your GID is 1001

* In docker run add `--user 1000:1001 \` above the last line.
* In docker compose add `user: 1000:1001` above ports.

If you wish to run it with a different UID/GID than your own you will need to change the ownership of the directory that
is being bind: `chown UID:GID palworld/`
or by changing the permissions for all other: `chmod o=rwx palworld/`

#### Using helm chart

The official helm chart can be found in a seperate repository, [palworld-server-chart](https://github.com/Twinki14/palworld-server-chart)
Expand Down
30 changes: 22 additions & 8 deletions scripts/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,27 @@
# shellcheck source=/dev/null
source "/home/steam/server/helper_functions.sh"

if [[ ! "${PUID}" -eq 0 ]] && [[ ! "${PGID}" -eq 0 ]]; then
LogAction "EXECUTING USERMOD"
usermod -o -u "${PUID}" steam
groupmod -o -g "${PGID}" steam
else
LogError "Running as root is not supported, please fix your PUID and PGID!"
if [[ "$(id -u)" -eq 0 ]] && [[ "$(id -g)" -eq 0 ]]; then
if [[ "${PUID}" -ne 0 ]] && [[ "${PGID}" -ne 0 ]]; then
LogAction "EXECUTING USERMOD"
usermod -o -u "${PUID}" steam
groupmod -o -g "${PGID}" steam
chown -R steam:steam /palworld /home/steam/
else
LogError "Running as root is not supported, please fix your PUID and PGID!"
exit 1
fi
elif [[ "$(id -u)" -eq 0 ]] || [[ "$(id -g)" -eq 0 ]]; then
LogError "Running as root is not supported, please fix your user!"
exit 1
fi

if ! [ -w "/palworld" ]; then
LogError "/palworld is not writable."
exit 1
fi

mkdir -p /palworld/backups
chown -R steam:steam /palworld /home/steam/

# shellcheck disable=SC2317
term_handler() {
Expand All @@ -30,7 +40,11 @@ term_handler() {

trap 'term_handler' SIGTERM

su steam -c ./start.sh &
if [[ "$(id -u)" -eq 0 ]]; then
su steam -c ./start.sh &
else
./start.sh &
fi
# Process ID of su
killpid="$!"
wait "$killpid"
Expand Down
2 changes: 1 addition & 1 deletion scripts/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ else
fi

LogAction "GENERATING CRONTAB"
rm -f "/home/steam/server/crontab"
truncate -s 0 "/home/steam/server/crontab"
if [ "${BACKUP_ENABLED,,}" = true ]; then
LogInfo "BACKUP_ENABLED=${BACKUP_ENABLED,,}"
LogInfo "Adding cronjob for auto backups"
Expand Down