-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Gitea can overwrite users gitconfig when using XDG spec #33039
Comments
What user is your gitea being run as? A dedicated user would have the XDG set correctly for the dedicated user (git on Gentoo, gitea on alpine) |
@eeyrjmr I believe this issue is reporting the case when tests are run, that it'll use the xdg path as well, which in the case of tests is run as the user testing rather than that of a dedicated user. |
Correct, either tests or a quick No real production use is affected by this as there isn't a clash of
I can always unset it manually now that I know it's an issue, but I figured reporting it won't hurt. It might save someone some time wondering why tests want to sign commits at worst. |
Haven't looked into it, just FYI, some backgrounds are here-> Proposal: make Gitea use its own customized global config #19709
Need to figure out why/how XDG_CONFIG_HOME affects git's home-behavior and/or how to disable it. Oops, I could somewhat understand the problem now .... On a fresh startup, there is no So I prefer to use method 2 (Unset XDG_CONFIG_HOME in gitea), since XDG_CONFIG_HOME is mainly for desktop users, it shouldn't appear in a server process. |
Just to be clear, you are mangling the env $HOME that is automatically set via /usr/bin/login (or ssh) to facilitate the testing? I ask because @wxiaoguang is advocating unsetting XDG_CONFIG_HOME, a variable that is set via PAM when triggered via a login session manager (systemd-logind, elogind, turnstile, or via a script for compatibility reason) I ask because this looks like your use-case is a valid user and thus has
Thus for gitea to unset XDG_CONFIG_HOME might cause other issues... Also it isn't enough to unset XDG_CONFIG_HOME since git (as this is fundamentally a git feature) actually checks for
Thus unsetting XDG_CONFIG_HOME isn't enough and HOME would also need to be overridden, which you have done in your testcase BUT isn't a normal thing todo ... be it either via writing into env or via updating Line 36 in d45456b
GitExecutable = "git" -> GitExecutable = "XDG_CONFIG_HOME=""git"
unsetting HOME and XDG_CONFIG_HOME needs to be thought about IF gitea is to manage this edgecase. |
I don't see "other issues" at the moment. Could you elaborate and show some real examples?
I think it is enough ..... because Gitea's git's HOME environment is managed by us: ps: although there is another solution: setting "GIT_CONFIG_GLOBAL", but we can't use it because it requires git >= 2.32 ....... |
It comes down to how XDG_CONFIG_HOME (from the perspective of /usr/bin/git) is unset and what the login session is also used for. My crude test (which I know was going to break things) was done to find that git looks for $HOME/.config/git/config as well. Thus unset XDG_CONFIG_HOME has wider system ramifications HOWEVER... within a golang application,
does not bleed outside of the application, so yes this should be ok |
That's what we are discussing about method 2: |
The only real downside to this is ... gitea would only support a gitconfig in $HOME not where the trend for the last decade has been (server or desktop...) ... move dot files into $HOME/.config (hence git's hard-coded 2nd check area being $HOME/.config/git). When you then consider what triggered this was a non-standard modification of a login session and technically LINUX breaking configuration where $HOME is being overridden but the rest of an XDG setup isn't... how much should an application support this? especially since git doesn't and this is actually occuring due to git (not gitea) |
This can be left without fix - it's non-trivial to get in the first place and requires actively messing with the configuration. It's just it is really annoying when I run gitea for quick experiments and it messes with my gitconfigs or wants to sign every webui commit. One other thing that I thought of is a sanity check (is $HOME in $XDG_CONFIG_HOME so if os.getenv("HOME") not in os.getenv("XDG_CONFIG_HOME"):
os.unsetenv("XDG_CONFIG_HOME") Gitea itself also doesn't really use XDG base dir standard in any way so that itself might be interesting to explore, but probably not relevant to the program. |
@eeyrjmr The env vars override/unset will only affect Gitea itself or sub-progress, not other applications. So that I think it's safe. |
yup, there was a part of me that was cautious about how this was to be done and then should it be done. now whether os.Unsetenv('XDG_HOME_DIR") should be called is the question because it will work, but should aspects of git be worked around for an invalid setup, a setup that was created for testing. |
If we go with unset route it would support Also consider that git by default doesn't use |
Unfortunately that isn't the case. It can check 3 locations (it assumes two should be the same for a VALID XDG configured system) and it reads them in the order: $XDG_CONFIG_HOME/.config/git/config -> $HOME/.config/git/config -> $HOME/.gitconfig and thus ~/.gitconfig takes preceidence in overwriting any values previously loaded from any of the other config files BUT they are all loaded and parsed. To confirm this I did
As you can see 1 and 2 were read (3 wasn't because the git code checks if XDG_CONFIG_HOME is set) There are weird and wacky ways that people can have their system setup and not realise what is being loaded but its all to support legacy systems which is exactly what triggered the scenario in the this issue report. I am just trying to point out the potential pitfalls in trying to mitigate a technically inconsistent user environment (from the perspective of git) as it assumes that $HOME is set by /usr/bin/login (or ssh) and XDG_* is set by systemd-logind/elogind/turnstile/$script and they are all consistent with each other. Options I see are
I honestly see an issue being opened in a few years where someone states that gitea won't load the git config from ~/.config/git/config as per git's manual |
Huh... Admittedly I did check the behavior on two keys (user.name and user.email) and when I had name and email in git/config and name in .gitconfig, then even though list showed both configs loaded, get global returned name from .gitconfig and empty email. I guess I need to run more checks and see if the behavior is consistent when section and key aren't defined... I don't remember if I did that.
It would though? Just .gitconfig would take priority.1 As I mentioned before, I see nothing wrong with saying it's not a bug. It's obscure and misconfiguration to a degree (to a degree because I haven't actually misconfigured it, Gitea just set a new HOME which caused this). I mainly wanted to have it somewhat documented that it is a thing that might happen - and it results in git tests misbehaving and failing. Footnotes
|
Gitea should never do that, see the background in my comment above: #33039 (comment) -> Proposal: make Gitea use its own customized global config #19709 To be honest ..... let's keep it simple: Gitea should be fully self-managed, it is not a desktop program, so let's just unset the XDG_CONFIG_HOME in Gitea, welcome to propose PRs (I could also propose one some days later when I get some time). (Update: ideally Gitea should only accept the environments which it clearly knows instead of unsetting the ones it doesn't want, but this would be a breaking change and it seems not bringing enough benefits to end users, so at the moment we could still keep "unsetting the unnecessary environments") |
done |
Description
Finally tracked that one, I was wondering why git tests always used my local config and messed with it.
If user has $XDG_CONFIG_HOME/git/config file and the XDG_CONFIG_HOME variable is set, gitea uses it both for run and tests.
I see two solutions for this:
commonBaseEnvs
First option has the downside of hardcoding the value of the variable.
Git config manual page for reference
Gitea Version
a92f505
Can you reproduce the bug on the Gitea demo site?
No
Log Gist
No response
Screenshots
No response
Git Version
No response
Operating System
No response
How are you running Gitea?
self-built
Database
SQLite
The text was updated successfully, but these errors were encountered: