Skip to content

Fix #14: allow for UID/GID specification via PUID/PGID env variables - #26

Open
flexd wants to merge 1 commit into
ropenttd:masterfrom
flexd:master
Open

Fix #14: allow for UID/GID specification via PUID/PGID env variables#26
flexd wants to merge 1 commit into
ropenttd:masterfrom
flexd:master

Conversation

@flexd

@flexd flexd commented Sep 9, 2025

Copy link
Copy Markdown

Hi there!

I made it so you can specify PUID/PGID when starting this container, fixing #14.

TLDR; Add the openttd user as normal, but run a new entrypoint as root which changes the uid/gid on "openttd" to the specified ones and then drops privileges to that user and runs the original entrypoint

I took some inspiration from how LinuxServers do it [1] , and also this Dockerfile/entrypoint where gosu was used https://github.com/sudo-bmitch/jenkins-docker/tree/main

Using gosu seems to be common practice [3]

[1] https://github.com/linuxserver/docker-baseimage-ubuntu/blob/focal/root/etc/s6-overlay/s6-rc.d/init-adduser/run
[2] (https://github.com/tianon/gosu?tab=readme-ov-file#gosu
[3] https://denibertovic.com/posts/handling-permissions-with-docker-volumes/

@flexd

flexd commented Sep 16, 2025

Copy link
Copy Markdown
Author

@duckfullstop Mentioning you in case you didn't see this :)

@duckfullstop duckfullstop self-assigned this Jan 15, 2026
@duckfullstop duckfullstop added the enhancement Something to enhance the project in some way - a new feature or functionality, perhaps. label Jan 15, 2026
@duckfullstop
duckfullstop self-requested a review January 15, 2026 23:44
@duckfullstop

duckfullstop commented Jan 15, 2026

Copy link
Copy Markdown
Collaborator

Sorry for the horrendous delay here, life happened 馃檱

I'm planning on reviewing this in the coming days when I'm a bit more awake, but my personal preference is to make the container run properly using an external UID/GID override (eg --USER 1001:65535, the docker-compose user: 1001:65535 flags, or Kubernetes's PodSecurityPolicy) for a more standards-driven approach to this problem. This, off the top of my head, should be trivial so long as the entrypoint and main binary are executable by all. (data files only need to be readable by all).

I'm not averse to additionally merging this to provide a simple envvar based way of handling the issue, but is there a strong argument to do so over simply being tolerant to any uid/gid combination running?

(Update: I have tested with the --USER flag in podman and all functionality seems to be working properly - can someone else verify for me? See #14)

@duckfullstop duckfullstop left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code itself LGTM though.

@duckfullstop duckfullstop added the question A question about the project, or life itself. label Jan 16, 2026
@flexd

flexd commented Jan 19, 2026

Copy link
Copy Markdown
Author

docker-compose files usually use environment variables for UID/PID as far as I know.
I'm mounting a folder into the containers from the host system, so I don't want to be changing the ownership or permissions on those files to whatever the container happenst to have internally. The solution in this PR of adopting the uid/gid that is specified for the openttd makes it so that it just works regardless.
I don't have any experience with podman so I don't know how it handles things

What this PR does differently over just overriding UID/GID is that the openttd user has it's UID/GID changed to the specified one. We no longer need to chown any of those files or change the permissions to be accessible by all

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Something to enhance the project in some way - a new feature or functionality, perhaps. question A question about the project, or life itself.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UID and GID Specification Allow setting the UID/GID of the container user

2 participants