mirror of
https://github.com/go-gitea/gitea.git
synced 2026-03-09 12:46:42 -05:00
Invalid default configuration, undocumented configuration options, and no session error logging #3290
Open
opened 2025-11-02 05:06:48 -06:00 by GiteaMirror
·
5 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.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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/proposal
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#3290
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 @cbednarski on GitHub (May 5, 2019).
Gitea version (or commit ref):
Gitea version 1.8.0 built with go1.12.4 : bindata, sqlite, sqlite_unlock_notifyGit version: dna
Operating system: Ubuntu 18.04
Database (use
[x]):Can you reproduce the bug at https://try.gitea.io:
Log gist:
Description
I am just installing gitea for the first time on Ubuntu as a linux service.
The data for my installation is located under
/data/gitea.Here is a snippet of my configuration
Here's my service file
When I try to login the username and password are validated but I am returned to the login screen with an empty form. There is no error on the web. There is no error output in the logs. The only messages that show up are these:
However, the session was not actually being written anywhere and instead failed silently. I had to guess and add the following configuration:
There are several bugs and/or unfortunate design choices here:
There is no logging when Gitea fails to create a session file. All other failures during the installation (and there were many because of various data path and permission issues) resulted in a crash or fatal exit. However, sessions failed silently.
GITEA_WORK_DIRseems to be required but this is not explicit in the documentation, it (apparently) cannot be configured by the configuration file, and gitea will happily start without it -- i.e. it is not actually required, but gitea will just be horribly broken.The default data path
/usr/local/bin(based on the application path) is completely surprising. I have never seen another service work this way. I would expect it to use service defaults (/etc,/var/lib, etc.) or the well-established conventions$HOME/.config/appname/or$HOME/.appname/) or PWD.Required configuration should not be specified via a totally optional environment variable. Rather, it should be a command-line argument like
gitea web /var/lib/gitea. Seeminio /data/diras an example. This makes it 100% obvious that it is required for things to work and also prevents the application from starting up in a broken state.gitea should sanity check the configuration before attempting to start with a configuration that will never work. See
nginx -tas an example.The web install UI happily creates an invalid configuration that will never work. I used the web installer and then gitea crashed as soon as it had written the config file. This is likely because of the above issues.
APP_DATA_PATHis mentioned in the FAQ, but not mentioned or explained in the docs, and it's not clear what this does. It seems there are three different ways to configure the same thing. This is at least one too many.The setup process for gitea has been extremely frustrating. I spent about 5 minutes setting up minio the other day. By contrast, Gitea took about 3 hours of configuration whack-a-mole because it will happily start up with a completely broken, invalid configuration that will never work and then crash or fatal exit with vague or no error messages. I have Gitea up and running now and it's very nice, but the setup process was frustrating.
@zeripath commented on GitHub (May 10, 2019):
I suspect that part of the issue is that
log.Fatalmessages are currently silently disappearing on 1.8 - they're fixed on 1.9.@zeripath commented on GitHub (May 10, 2019):
OK now I've looked a bit more at your issue I'll try to reply some of these. I'm sorry you've had difficulty - Gitea isn't built like a normal debian/ubuntu package, (more is the shame), and I think you've tried to force it to work like one without completely copying our documentation for it.
First of all did you look at: https://docs.gitea.io/en-us/linux-service/ and https://github.com/go-gitea/gitea/blob/master/contrib/systemd/gitea.service? Your service file is missing several key components that are required and likely caused your trouble. As I said above Gitea isn't built like a debian/ubuntu package - and has only just since #6631 been able to built in such a way but we don't build it that way by default.
Gitea is effectively built to expect to be run from its own directory with the location of the gitea executable and the working directory the same. (If you just moved the gitea binary to /home/gitea and ran it from there as the gitea user you would never have experienced these problems.) There are several environment variables that will override the default places gitea uses and these have been added over time to eventually create a gitea that could work like an expected debian/ubuntu package but only if these are variables are set. This is very similar to how firefox and google-chrome work, and if you look at these executables on debian they are scripts that will set environments correctly. We currently don't have a script for gitea although I would almost certainly recommend that anyone packaging gitea for debian/ubuntu should shadow the gitea binary with such a script - if only to help prevent problems like this in future. PRs are more than welcome here.
Now since #6631, it is possible to build gitea in such a way that you will probably not need to use these environment variables - however, which configuration variables depend on working directory vs. app path needs to be clearly looked at. (Personally I don't understand the reasoning behind some of these choices - However its very difficult to change these without breaking existing users) Unfortunately, we won't be able to change the default provided gitea on gitea.io to have the correct #6631 settings set during build as it will break existing users - so either debian packagers will either have to use a shadowing script described above or should rebuild with the correct variables.
Now to address some specific points. Regarding sessions, unfortunately the macaron.session package doesn't provide a way to test to see whether a configuration is acceptable. And in fact it is only when you attempt to login that session files should be created. It is at that point that they should cause a panic but they certainly shouldn't fail silently. Did you get a panic? You almost certainly experienced this problem because your default location was not accessible to the gitea service as your service file was incorrect.
Your issue with the GITEA_WORK_DIR and default data path are because you didn't set the service file correctly - I think I've explained above what these are doing.
I think you're partially right about checking configuration - there are certainly places were Gitea can determine whether it can create files where it wants to. However, as you see above the validity of a configuration file depends on the environment variables configured. Your configuration file is a perfectly valid file - just not from where you put gitea and where you ran it. As I said above, if you moved the gitea binary to /home/gitea and ran it from there with the gitea user you'd almost certainly have no trouble - depending on your values. We can do better, but we can't do this perfectly.
Now, what can we actually do to help prevent anyone else from experiencing these problems?
However, please don't suffer in silence for 3 hours - use our discord and look at the documentation!
@cbednarski commented on GitHub (May 11, 2019):
Thanks for the detailed response! I'll try to read through and follow-up on some of these things. I would also be happy to write some config validation code when I get some time, since this seems like low-hanging fruit.
log.Fatal fixes in 1.9
That's great! I'll pull a version from master and see if that does anything interesting for me.
Install Docs
I did see the linux service page but since I am familiar with systemd I wrote the
.servicefile by hand. Also I did not notice the example service file since it was linked, while most other examples in the docs were inline. Oops!I did read this part of the binary installation guide page that says:
That line seems to be flat-out wrong, or at least misleading.
Duplicate Configs
I just took a look at https://github.com/go-gitea/gitea/blob/master/contrib/systemd/gitea.service and I noticed it has the following (partial snippet):
In my (now working) configuration I have
Userset in my service file but I did not setUSERalso. This seems redundant -- is that actually required? If so, why is it required twice? Likewise forWorkingDirectoryandGITEA_WORK_DIRit seems like the same thing is configured the same thing twice which is confusing.I have now set
GITEA_WORK_DIRbut notWorkingDirectory. If I setWorkingDirectoryonly and notGITEA_WORK_DIR, the app crashes on startup. SoGITEA_WORK_DIRstill seems to be required either way.USERseems extraneous.Default Settings
I'm curious to know more about this. I have only skimmed a bit of 6631 so far, but on the surface I could see a simple approach:
Either
--work-dirflag / argument / config option orGIT_WORK_DIRmust be present to start the program. If neither is set, it exits.I've done quite a bit of backwards-compatibility surgery in the past and it seems like there could be a reasonable upgrade path here. For example, the unspecified "magic" configuration could be marked as deprecated, and warn that the config is invalid and the option must be explicitly configured.
A future version of gitea will implement the correct behavior and refuse to start if the config is missing. The user simply has to specify the configuration to continue, but their current database and working directory will not need to be changed manually.
Sessions
As far as I could tell there was no panic. After I entered my username and password I would be immediately returned to the login page with a blank form. The logs were empty. I will double-check this.
(In)valid Configuration
While the config may be syntactically valid it is not correct, and in that sense it is not going to work. But most importantly, this is opaque to me. I don't actually know what gitea is doing internally, so there's no way for me to know it's incorrect.
This is so surprising to me! I can't think of another program that doesn't expect to be run from the path, and where the location of the binary rather than pwd controls its behavior. It's very unusual.
Gitea is pulling configuration from 5 places(!): the environment, it's current binary path, the command line flags, the configuration file, and baked-in constants. At a minimum it uses 4 of these config sources. This is very complicated. My gut tells me it could/should use a minimum of 2.
Distro conventions
I am coming from regularly using consul, nomad, vault, nginx, git, postgres etc. which do not strictly conform to debian packaging conventions, but also are compatible with them. FWIW I have also used FreeBSD and CentOS / RHEL and generally things use
/etc/there too.Regardless of any small differences between unixes, gitea's behavior breaks all the standard conventions I can think of. Is that intended, or just incidental? I can't discern a design goal that would preclude it so I think gitea would be improved by following the same convention as everything else. Path of least surprise.
Forward
I realize that there are some past decisions here that are not easy to unwind. I have sporadically followed Gitea's development since before the Gogs fork, so I do not begrudge that there were decisions made in the past that were beyond your control. I'm also willing to put in a patch or two, though right now I am still trying to understand how things work and the best path forward.
Based on what you've said above I think a config-checker is the most straight foward way to proceed. At the very least it will make visible whatever logic and hidden or magic constants gitea is using, and make the problem more visible.
For the time being I think it would also be a good idea to emphasize the important of
GITEA_WORK_DIRas being the thing that makes everything work. If I ran gitea as root (i.e. in docker) I would not notice most of these problems because with root permissions it will happily clobber everything else. In a traditional linux environment this option is still required.@zeripath commented on GitHub (May 12, 2019):
OK work-path CLI option PR has been made.
@zeripath commented on GitHub (May 12, 2019):
I've also added a Contrib script in #6923 which we could use to shadow the gitea binary to set reasonable defaults.