rockstorm101 / git-server-docker

Git server over SSH
GNU General Public License v3.0
59 stars 14 forks source link

GID already in use #6

Open xxlbug opened 1 year ago

xxlbug commented 1 year ago

Hi there,

thank you for making this, i got really frustrated with gitlab, gitea and gogs. Git-server seems to be all i need and is much leaner :-)

I have a small but important problem which prohibits me from using git-server right now:

On my host system the UID and GID i want to use for git-server are 99/100. On boot i get the error that GID 100 is already in use (from the default group "users" as seen in /etc/group).

08/01/2023 21:36:15 deluser: can't find git in /etc/group 08/01/2023 21:36:15 addgroup: gid '100' in use 08/01/2023 21:36:16 id: unknown user git 08/01/2023 21:36:16 deluser: unknown user git

I could change the dockerfile to manually change the gids around but wanted to try to find a better solution which also avoids this problem in the future for others.

My ideas so far:

I can make the changes and create an PR but would like to have some input before.

Thank you

rockstorm101 commented 1 year ago

Hi @xxlbug, thanks for reporting this. I am able to reproduce it. I totally overlooked this potential use case. I'll think about it and what could be the best approach to work around it.

rockstorm101 commented 1 year ago

After giving this some thought I would say the current behavior is the right one. Modifying/deleting system users/groups must be handled with care. The logic to do so (without installing any additional packages) goes far beyond the currently supplied simple setup script. Plus, I don't expect many users to stumble across conflicts with system user/group IDs to be honest. Most hosts will use IDs greater than 1000 for their user IDs. Let me know if you think otherwise.

For those that face errors like:

addgroup: gid '100' in use
adduser: uid '100' in use

Instead of modifying the Dockerfile, the current setup allows for custom scripts to be run during container initialization. One can create a script, e.g. 01-mod-system-users.sh, and mount it at /docker-entrypoint.d/. This way it will be run before the setup script (i.e. 10-setup.sh).

services:
  git-server:
    ...
    volumes:
      - ./01-mod-system-users.sh:/docker-entrypoint.d/01-mod-system-users.sh:ro

In this particular case, modifying the system users/groups to allow for UID:GID combination 99:100 to be used for git is pretty straight forward since those UID:GID do not own any files in the system. No delicate file ownership changes are required.

#!/bin/sh

deluser guest
delgroup users
addgroup -g 101 -S users
addgroup games users
adduser -u 405 -G users -h /dev/null -g 'guest' -S guest
delgroup guest users

So I'm inclined not to fix this issue but leave it open for future reference in case someone else finds the same problem. I know it is not great but I could not come up with an easy, quick and elegant way to allow for virtually any UID and GID to be used.

I'm open to suggestions on any aspect and from anyone, so please keep them coming and thanks for contributing.

xxlbug commented 1 year ago

@rockstorm101 thank you for the advice and script, it works now fine. I think it would be best to close this ticket and let people look in the closed tickets to search for solved problems. But up to you :-)