From f6ab2aaab3e6a95578eeccf1c44f316d241eafd7 Mon Sep 17 00:00:00 2001 From: Geoff Bourne Date: Fri, 7 Apr 2023 20:05:09 -0500 Subject: [PATCH] By default, generate random RCON password at startup (#2071) --- Dockerfile | 2 +- README.md | 4 ++-- scripts/start | 8 ++++++++ scripts/start-configuration | 3 +++ tests/setuponlytests/defaults/verify.sh | 1 - 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index c6dba2d8..35fc72f3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -58,7 +58,7 @@ WORKDIR /data STOPSIGNAL SIGTERM # End user MUST set EULA and change RCON_PASSWORD -ENV TYPE=VANILLA VERSION=LATEST EULA="" UID=1000 GID=1000 RCON_PASSWORD=minecraft +ENV TYPE=VANILLA VERSION=LATEST EULA="" UID=1000 GID=1000 COPY --chmod=755 scripts/start* / COPY --chmod=755 bin/ /usr/local/bin/ diff --git a/README.md b/README.md index 4df59543..0ae4b4f2 100644 --- a/README.md +++ b/README.md @@ -1188,9 +1188,9 @@ The server icon which has been set doesn't get overridden by default. It can be RCON is **enabled by default** to allow for graceful shut down the server and coordination of save state during backups. RCON can be disabled by setting `ENABLE_RCON` to "false". -The default password is "minecraft" but **change the password before deploying into production** by setting `RCON_PASSWORD`. +The RCON password can be set via `RCON_PASSWORD` or the name of a file that contains the password can be referenced by setting `RCON_PASSWORD_FILE`. If not set, a random password will be generated at each startup. -**DO NOT MAP THE RCON PORT EXTERNALLY** unless you aware of all the consequences and have set a **secure password** with `RCON_PASSWORD`. +Regardless of the password set or defaulted, **DO NOT MAP THE RCON PORT EXTERNALLY** unless you sure that is what you intended. > Mapping ports (`-p` command line or `ports` in compose) outside the container and docker networking needs to be a purposeful choice. Most production Docker deployments do not need any of the Minecraft ports mapped externally from the server itself. diff --git a/scripts/start b/scripts/start index 4efe066c..00565f59 100755 --- a/scripts/start +++ b/scripts/start @@ -10,10 +10,18 @@ umask 0002 chmod g+w /data +if isTrue "${ENABLE_RCON:-true}" && ! [ -v RCON_PASSWORD ] && ! [ -v RCON_PASSWORD_FILE ]; then + RCON_PASSWORD=$(openssl rand -hex 12) + export RCON_PASSWORD +fi + if ! isTrue "${SKIP_SUDO:-false}" && [ "$(id -u)" = 0 ]; then runAsUser=minecraft runAsGroup=minecraft + # For rcon-cli access running via exec, which by default is running as root + echo "password=${RCON_PASSWORD}" > "$HOME/.rcon-cli.env" + if [[ -v UID ]]; then if [[ $UID != 0 ]]; then if [[ $UID != $(id -u minecraft) ]]; then diff --git a/scripts/start-configuration b/scripts/start-configuration index 35cb4ef4..db7d66db 100755 --- a/scripts/start-configuration +++ b/scripts/start-configuration @@ -83,6 +83,9 @@ if [[ $RCON_PASSWORD_FILE ]]; then log "" fi +# For rcon-cli access +echo "password=${RCON_PASSWORD}" > "$HOME/.rcon-cli.env" + function fixJavaPath() { # Some Docker management UIs grab all the image declared variables and present them for configuration. # When upgrading images across Java versions, that creates a mismatch in PATH's expected by base image. diff --git a/tests/setuponlytests/defaults/verify.sh b/tests/setuponlytests/defaults/verify.sh index b6d87238..4a64fed3 100644 --- a/tests/setuponlytests/defaults/verify.sh +++ b/tests/setuponlytests/defaults/verify.sh @@ -1,3 +1,2 @@ -mc-image-helper assert propertyEquals --file=server.properties --property=rcon.password --expect=minecraft mc-image-helper assert propertyEquals --file=server.properties --property=rcon.port --expect=25575 mc-image-helper assert propertyEquals --file=server.properties --property=enable-rcon --expect=true