-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
[Summary] USER_UID/uid related problems (snap/docker) #23632
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
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. |
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." |
I have this problem with
|
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. |
I did not test carefully last time I upgraded, but when I rolled back to
Maybe it is enough to just have user: set in docker-compose and upgrade to 1.19? In
Not sure if RUN_USER has anything to do with it. |
To be more clear, doing |
It is running on Ubuntu 22.04, but no snaps - just have docker and docker-compose installed and manage some docker instances manually. |
I have probably the same issue as reported in #24385 |
I have a question, why did you set |
because user 1000 it's already used for another service and I want to keep permissions separated |
I'm not sure whether it's related (haven't looked into the problem at the moment): Gitea's docker-rootless hard-coded 1000: Lines 40 to 49 in ad03c6e
Line 62 in ad03c6e
|
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 |
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. |
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? |
Yes (I guess so) |
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? |
Yes I have both those set in the config, so is using the builtin server. |
If you could build your own docker image, welcome to try this fix #24435. Or I think it could be merged in one or two days soon then you can try the 1.19 nightly image. |
Many users report that 1.19 has a regression bug: the rootless image can't start if the UID is not 1000. #23632 (comment) https://discourse.gitea.io/t/gitea-doesnt-start-after-update-to-1-19/6920/9 The problem is that the IsRunUserMatchCurrentUser logic is fragile, the "SSH" config is not ready when it executes. This PR is just a quick fix for 1.19. For 1.20, we need a clear and stable solution.
https://hub.docker.com/r/gitea/gitea/tags?page=1&name=1.19-dev these images contain #24435 |
1.19-dev-rootless isn't updated and didn't worked for me, 1.19-dev-linux-amd64-rootless works |
|
@wxiaoguang as discussed on discord, here is my analysis of the problem. Assumptions:
Problem 1: uid:gid for gith and gitc differ
Problem 2: ssh rulesFrom the man page for
So these paths must have proper permissions on the host:
ResultsOn the host:
In the container:
Recommendations
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. |
Another thing, I set |
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. |
TL;DR The problem is here - the UID and GID are hardcoded in the
|
@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 |
@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 |
Per go-gitea#23632, there are several issues with the hardcoded values (1000:1000) in the existing Docker installation flow. This is the first step in a series of changes to resolve this issue.
@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. |
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. |
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
|
After spending some time wondering about this, I've been looking at the difference between The 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. |
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 |
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. |
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 999
TODO
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.
The text was updated successfully, but these errors were encountered: