mirror of
https://github.com/go-gitea/gitea.git
synced 2026-03-12 02:24:21 -05:00
[Summary] USER_UID/uid related problems (snap/docker) #10478
Open
opened 2025-11-02 09:08:29 -06:00 by GiteaMirror
·
33 comments
No Branch/Tag Specified
main
release/v1.25
release/v1.24
release/v1.23
release/v1.22
release/v1.21
release/v1.20
release/v1.19
release/v1.18
release/v1.17
release/v1.16
release/v1.15
release/v1.14
release/v1.13
release/v1.12
release/v1.11
release/v1.10
release/v1.9
release/v1.8
v1.25.3
v1.25.2
v1.25.1
v1.25.0
v1.24.7
v1.25.0-rc0
v1.26.0-dev
v1.24.6
v1.24.5
v1.24.4
v1.24.3
v1.24.2
v1.24.1
v1.24.0
v1.23.8
v1.24.0-rc0
v1.25.0-dev
v1.23.7
v1.23.6
v1.23.5
v1.23.4
v1.23.3
v1.23.2
v1.23.1
v1.23.0
v1.23.0-rc0
v1.24.0-dev
v1.22.6
v1.22.5
v1.22.4
v1.22.3
v1.22.2
v1.22.1
v1.22.0
v1.23.0-dev
v1.22.0-rc1
v1.21.11
v1.22.0-rc0
v1.21.10
v1.21.9
v1.21.8
v1.21.7
v1.21.6
v1.21.5
v1.21.4
v1.21.3
v1.21.2
v1.20.6
v1.21.1
v1.21.0
v1.21.0-rc2
v1.21.0-rc1
v1.20.5
v1.22.0-dev
v1.21.0-rc0
v1.20.4
v1.20.3
v1.20.2
v1.20.1
v1.20.0
v1.19.4
v1.21.0-dev
v1.20.0-rc2
v1.20.0-rc1
v1.20.0-rc0
v1.19.3
v1.19.2
v1.19.1
v1.19.0
v1.19.0-rc1
v1.20.0-dev
v1.19.0-rc0
v1.18.5
v1.18.4
v1.18.3
v1.18.2
v1.18.1
v1.18.0
v1.17.4
v1.18.0-rc1
v1.19.0-dev
v1.18.0-rc0
v1.17.3
v1.17.2
v1.17.1
v1.17.0
v1.17.0-rc2
v1.16.9
v1.17.0-rc1
v1.18.0-dev
v1.16.8
v1.16.7
v1.16.6
v1.16.5
v1.16.4
v1.16.3
v1.16.2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v1.4.0-rc1
v1.3.2
v1.3.1
v1.3.0
v1.3.0-rc2
v1.3.0-rc1
v1.2.3
v1.2.2
v1.2.1
v1.2.0
v1.2.0-rc3
v1.2.0-rc2
v1.1.4
v1.2.0-rc1
v1.1.3
v1.1.2
v1.1.1
v1.1.0
v1.0.2
v1.0.1
v1.0.0
v0.9.99
Labels
Clear labels
$20
$250
$50
$500
backport/done
💎 Bounty
docs-update-needed
good first issue
hacktoberfest
issue/bounty
issue/confirmed
issue/critical
issue/duplicate
issue/needs-feedback
issue/not-a-bug
issue/regression
issue/stale
issue/workaround
lgtm/need 2
modifies/api
modifies/translation
outdated/backport/v1.18
outdated/theme/markdown
outdated/theme/timetracker
performance/bigrepo
performance/cpu
performance/memory
performance/speed
pr/breaking
proposal/accepted
proposal/rejected
pr/wip
pull-request
reviewed/wontfix
💰 Rewarded
skip-changelog
status/blocked
topic/accessibility
topic/api
topic/authentication
topic/build
topic/code-linting
topic/commit-signing
topic/content-rendering
topic/deployment
topic/distribution
topic/federation
topic/gitea-actions
topic/issues
topic/lfs
topic/mobile
topic/moderation
topic/packages
topic/pr
topic/projects
topic/repo
topic/repo-migration
topic/security
topic/theme
topic/ui
topic/ui-interaction
topic/ux
topic/webhooks
topic/wiki
type/bug
type/deprecation
type/docs
type/enhancement
type/feature
type/miscellaneous
type/proposal
type/question
type/refactoring
type/summary
type/testing
type/upstream
Mirrored from GitHub Pull Request
No Label
type/bug
Milestone
No items
No Milestone
Projects
Clear projects
No project
No Assignees
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: github-starred/gitea#10478
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @wxiaoguang on GitHub (Mar 22, 2023).
Background
setting.go:322:loadRunModeFrom() [F] Expect user 'gitea' but current user is: root.AddPublicKey, calcFingerprintSSHKeygen: 'ssh-keygen -lf /tmp/....' failed with error 'exec(64c52017-2:AddPublicKey) failed: exit status 255(<nil>) stdout: stderr: No user exists for uid 999 ': No user exists for uid 999TODO
I haven't spent time on these problems. Some brief thoughts:
I guess Gitea needs to spend some time on these problems, work them out, clarify the behaviors and improve documents.
@lunny commented on GitHub (Mar 22, 2023):
For the ssh protocol of git, the run user name is also the name which be used in the SSH URL when install with Open SSHD.
@wxiaoguang commented on GitHub (Mar 22, 2023):
That's not true for Builtin SSH Server, eg: docker-rootless. Only SSH_USER is necessary, the RUN_USER shouldn't be mixed there.
I updated the description, added this context: "Builtin SSH Server & Docker-rootless only needs a virtual SSH_USER."
@bd4 commented on GitHub (Apr 27, 2023):
I have this problem with
gitea/gitea:latest-rootless. No changes to configuration, I have been usinguser: "1016:1017"in the docker-compose.yml, RUN_USER git in app.ini, and it used to work. Now it no longer works, I get errors like this:@wxiaoguang commented on GitHub (Apr 27, 2023):
Could you help to provide more details? What are the operations before the bug occurs?
Or, you you provide detailed reproducible setup steps? Then I can try to reproduce it on my side.
@bd4 commented on GitHub (Apr 27, 2023):
I did not test carefully last time I upgraded, but when I rolled back to
gitea/gitea:1.18-rootless, the problem goes away. I have a user/groupgiteaon host system, with uid/gid 1016/1017, and my docker-compose looks like this:Maybe it is enough to just have user: set in docker-compose and upgrade to 1.19? In
config/app.ini, I have:Not sure if RUN_USER has anything to do with it.
@bd4 commented on GitHub (Apr 27, 2023):
To be more clear, doing
docker-compose pullfollowed bydocker-compose up -dto upgrade to 1.19 from 1.18 reproduces, and rolling back to 1.18 by changing the image fromgitea/gitea:latest-rootlesstogitea/gitea:1.18-rootlessfixes it.@bd4 commented on GitHub (Apr 27, 2023):
It is running on Ubuntu 22.04, but no snaps - just have docker and docker-compose installed and manage some docker instances manually.
@bota87 commented on GitHub (Apr 28, 2023):
I have probably the same issue as reported in #24385
I just tried with the latest release
1.19.2-rootlessand the issue persist, if I removeuser: "1016:1017"it works@wxiaoguang commented on GitHub (Apr 28, 2023):
I have a question, why did you set
user: "1016:1017"?@bota87 commented on GitHub (Apr 28, 2023):
because user 1000 it's already used for another service and I want to keep permissions separated
@wxiaoguang commented on GitHub (Apr 28, 2023):
I'm not sure whether it's related (haven't looked into the problem at the moment):
Gitea's docker-rootless hard-coded 1000:
ad03c6e0a3/Dockerfile.rootless (L40-L49)ad03c6e0a3/Dockerfile.rootless (L62)@bd4 commented on GitHub (Apr 28, 2023):
My understanding is that the USER from the dockerfile is the default, but it's it can be overridden by the user config in docker compose or appropriate docker run args: https://docs.docker.com/compose/compose-file/05-services/#user
@wxiaoguang commented on GitHub (Apr 28, 2023):
Yup, but Gitea can't find the user's name for UID=10xx (non-1000), then bug occurs ..... actually it's also related another problem (#24389), the IsRunUserMatchCurrentUser logic is fragile.
@bd4 commented on GitHub (Apr 28, 2023):
Ok so the issue happens when using a host UID that does not exist in the docker image? And it stopped working in 1.19 because the code is trying to determine the user name, and before it wasn't?
@wxiaoguang commented on GitHub (Apr 28, 2023):
Yes (I guess so)
@wxiaoguang commented on GitHub (Apr 29, 2023):
Sorry for bothering, one more question, do you have "DISABLE_SSH=false" and "START_SSH_SERVER=true" in your app.ini , aka, have you enabled Gitea's builtin SSH server?
@bd4 commented on GitHub (Apr 29, 2023):
Yes I have both those set in the config, so is using the builtin server.
@wxiaoguang commented on GitHub (Apr 30, 2023):
If you could build your own docker image, welcome to try this fix https://github.com/go-gitea/gitea/pull/24435. Or I think it could be merged in one or two days soon then you can try the 1.19 nightly image.
@wxiaoguang commented on GitHub (Apr 30, 2023):
https://hub.docker.com/r/gitea/gitea/tags?page=1&name=1.19-dev these images contain https://github.com/go-gitea/gitea/pull/24435
@bota87 commented on GitHub (May 2, 2023):
1.19-dev-rootless isn't updated and didn't worked for me, 1.19-dev-linux-amd64-rootless works
@wxiaoguang commented on GitHub (May 2, 2023):
@techknowlogick
@lonix1 commented on GitHub (Jun 23, 2023):
@wxiaoguang as discussed on discord, here is my analysis of the problem.
Assumptions:
githis user on host andgitcis user in containerProblem 1: uid:gid for gith and gitc differ
githwill have some random values when createdgitcis hardcoded to1000:1000, and that's impossible to change viaenvironment:in thedocker-compose.yml(as suggested by the docs, incorrectly)githandgitcare diffferent, and that's the core problemgithupon creation, but on debian/ubuntu distros (maybe others too?) the primary user already has1000:1000by default, so there's no way to match these valuesProblem 2: ssh rules
From the man page for
sshd:So these paths must have proper permissions on the host:
/home/gith//home/gith/.ssh//home/gith/.ssh/authorized_keysResults
On the host:
$ ssh -T gith@server; that will connect but the tunnel will fail, which means ssh on the host is correctIn the container:
githdiffer to those ofgitcgit clone/whatever ...action, it always fails withgitcuser's 1000:1000 to fix that problem, then of course you won't be able to ssh to the host (because that is incorrect for the host'sgithuser).Recommendations
gitcuser's hardcoded uid:gid from 1000:1000 to something else (e.g. 1010:1010). That also isn't perfect but will eliminate 99% of problems out here, because as explained above, 1000:1000 is already used for the default user on the host. If you use 1010:1010, then when creatinggithwe could specify 1010:1010 for that user and thus match the values, and so eliminate the problem.Dockerfileand set uid:gid manually forgitcuser.ports: 2222:22).ssh -L ...) but I don't have time to test that. It could be MUCH simpler than we think, but someone else must investigate that. There are many examples on StackOverflow, so if someone has time, start there.Whatever you guys decide, one thing that's important to do right way, is put a "warning" box in that section on the docs stating that this is a very advanced scenario and that most users would probably not be able to get it to work. (I think it's impossible, but I may be wrong.) Don't let people waste time on this.
@lonix1 commented on GitHub (Jun 23, 2023):
Another thing, I set
ENABLE_SSH_LOG = trueto be able to diagnose ssh problems in the container's sshd, but no sshd errors were written to the log file (which is working for other cases). I wonder if that setting is working?@wxiaoguang commented on GitHub (Jun 23, 2023):
That's another longstanding problem: difficult to debug SSH part with logs. "ENABLE_SSH_LOG" only sends a few (usually the last error log) to the web server, then the error log will be shown in Gitea server's log with prefix "ssh: ". It's not useful in most cases.
@lonix1 commented on GitHub (Jun 23, 2023):
TL;DR
The problem is here - the UID and GID are hardcoded in the
Dockerfile.Dockerfile(ENV),docker-compose.yml(environment:) or via docker cli (docker run -e).Most of this issue (and MANY others) are based on this one problem. Please consider it as a major issue - because of this, we cannot use passthrough.
@krokosik commented on GitHub (Sep 21, 2023):
@lonix1 great work, I also spent lots of time with the documentation, thinking I'm plain stupid. We are currently using Alternative 3 from your recommendation, but would love a simpler solution
@tomholford commented on GitHub (Oct 3, 2023):
@lonix1 thanks for sharing your findings. I also spent many hours trying to debug this issue. A configurable UID / GID via docker env vars would be really useful
@tomholford commented on GitHub (Oct 3, 2023):
@wxiaoguang @lonix1 @wkrasnicki I started on a potential solution in #27405. Could use your feedback to see if this direction makes sense, and what other changes need to be made to resolve this issue.
@wxiaoguang commented on GitHub (Oct 3, 2023):
Thank you for inviting me to review. At the moment I don't have full understanding for this problem. So feel free to propose a complete solution (with explanation and documents), maybe other users&maintainers could help and suggest.
@maykelvink commented on GitHub (Nov 2, 2023):
I encountered the same issue, but resolved it by linking the passwd file in the Docker Compose configuration. I adjusted the user ID to match the ones on my system. I opted for SSH Container pass through to make use of my yubikey / security key. Everything operates smoothly now.
This is the extracted passwd file from the gitea/gitea:1.20.5-rootless docker image. You can see as mentioned above it's hard coded as 1000:1000 thus can't run correctly if you run it as an user with a different UID even if you run it as a specific user.
When starting your docker container you can overwrite this file with using an bind mapping and store your custom passwd file next to your docker-compose.yml. I've updated the passwd to reflect my local git UID and GID
e.g. i've updated the last line in the passwd file
@tuomotalvitie commented on GitHub (Nov 8, 2023):
After spending some time wondering about this, I've been looking at the difference between
gitea/docker/root/usr/bin/entrypointand
gitea/docker/rootless/usr/local/bin/docker-entrypoint.shThe first one has sed magic for changing the USER_GID and USER_ID which the second one lacks. If the second one is actually used by rootless, this might have something to do with the issue.
@maykelvink commented on GitHub (Nov 9, 2023):
Ideally you want to overwrite the UID/GID that's being used to start the Gitea binary as environment arguments. You cannot add arguments to the Dockerfile if you are not going to build it locally. e.g. I'm pulling a pre-build image from dockerhub.
In order to start the binary as a certain user you could add a PUID/PGID as environment variables in docker compose and adjust the dockerfile to start the binary with for example S6 Overlay.
exec s6-setuidgid "$PUID:$PGID" gitea
@jmptbl commented on GitHub (Aug 8, 2024):
Hello! I was surprised to see this issue persisting for so long. The simplest fix would be to just give this Docker image a less common UID and GID, with the expectation that a random UID+GID would be unlikely to clash with an existing user account on the host system. It seems strange to release a public image that uses UID and GID 1000!
Anyhow, the easiest workaround without building a custom image is to follow @maykelvink /etc/passwd bind mounting method. I combined it with an /etc/group bind mount as well, so that I could change the UID and GID. Like this I've gotten SSH pass-through working with the Docker shell method.