geoserver image: add non-root / arbitrary-UID support (root remains default) - #84
geoserver image: add non-root / arbitrary-UID support (root remains default)#84jwkaltz wants to merge 2 commits into
Conversation
|
@jwkaltz I haven't reviewed the changes (and the conflicts yet), but how did you manage the shared raster data between GeoNode and GeoServer? You know that raster uploads are stored and served from a shared volume. |
@giohappy thanks for the note, I see that #85 made significant differences to these files. I will try to rewrite my pull request (resolving the conflicts), redo tests and get back to you. |
b9f3c3b to
d9f2e80
Compare
@giohappy I have rebased the pull request and tested the new version successfully (see "Testing" section in the description). Regarding your question,
|
Fixes #83
Makes the geoserver image able to run as a non-root user, including an arbitrary UID assigned at runtime. The image continues to run as root by default, so this is backward compatible.
Rebased onto #85, so this now builds on the current layout (Java 17 / GeoServer 2.28.4, helper scripts in
/usr/local/bin, data dir populated at runtime from the skeleton archive). The points below are the non-root adjustments on top of that.Changes
Scripts (
/usr/local/bin):entrypoint.sh/set_geoserver_auth.sh: replace the hardcoded/roothome with${GEOSERVER_HOME}(defaults to/root, preserving current behavior when running asroot). The
.bashrc/.override_envsourcing is guarded with[ -f ]so missingfiles are skipped instead of aborting under
set -e.entrypoint.sh: check thatGEOSERVER_HOMEis writable, so a non-root run without awritable home fails early with a clear message.
set_geoserver_auth.sh: write the temp file viamktempinstead ofxml.tmpin thecurrent working directory (not writable for a non-root user), and add explicit error
handling on the write-back.
Dockerfile:
geoserveruser (configurableGEOSERVER_UID, default 1000) in group 0, withchmod g=uon the writable dirs so the image can run as any UID in group 0. NoUSERstatement is added — root stays the default. Ownership is set to
${GEOSERVER_UID}:0;running as root is unaffected since root ignores file permissions.
catalina.properties, and creatingconf/Catalina/localhost) and set-XX:LogFileto
/tmp/jvm.log. This lets the image also run underreadOnlyRootFilesystemwhen thescratch dirs are mounted writable — optional, not required.
Backward compatibility
Root remains the default user and the default
GEOSERVER_HOMEfalls back to/root, soexisting root-based deployments are unaffected.
GEOSERVER_HOMEis configurable fornon-root use (e.g.
/tmp, or a writable volume mounted over/home/geoserver).Testing
Verified the rebased image (GeoServer 2.28.4) in these modes:
GEOSERVER_HOMEfalls back to/root.GEOSERVER_HOME: fails fast with a clear message.GEOSERVER_HOME, both--user 1000:0and an arbitrary UID(e.g.
4711:0): starts correctly and is fully functional.readOnlyRootFilesystem: runs non-root withGEOSERVER_HOME=/home/geoserver; raster upload via GeoNode and serving via GeoServerboth work (shared statics volume mounted read-only into GeoServer, common
fsGroup).