go-gitea / gitea

Git with a cup of tea! Painless self-hosted all-in-one software development service, including Git hosting, code review, team collaboration, package registry and CI/CD
https://gitea.com
MIT License
44.08k stars 5.41k forks source link

Can't access custom folder #28997

Closed PierreLouisPAUGAM closed 6 months ago

PierreLouisPAUGAM commented 7 months ago

Description

Hello,

I'm running a fresh install of gitea on a debian server and I have troubles customizing it following this documentation.

First of all it says in the documentation :

You can check the CustomPath using gitea help. You can also find the path on the Configuration tab in the Site Administration page.

But when I type gitea help I get :

DEFAULT CONFIGURATION:
   AppPath:    /usr/local/bin/gitea
   WorkPath:   /usr/local/bin
   CustomPath: /usr/local/bin/custom
   ConfigFile: /usr/local/bin/custom/conf/app.ini

While the site administration page gives me this : image

When I try to list these directories I get this :

user@server:~$ ls -la /usr/local/bin
total 134652
drwxr-xr-x  2 root root      4096 30 janv. 15:50 .
drwxr-xr-x 10 root root      4096 25 janv. 16:15 ..
-rwxr-xr-x  1 root root 137872608 30 janv. 15:50 gitea
user@server:~$ ls -la /var/lib/gitea
ls: impossible d'ouvrir le répertoire '/var/lib/gitea': Permission non accordée
user@server:~$ ls -la /var/lib
total 116
...
drwxr-xr-x  2 root          root          4096 28 févr.  2023 git
drwxr-x---  5 git           git           4096 30 janv. 15:50 gitea
...

For reference here is how I installed Gitea :

HOW I INSTALLED GITEA

**# Downloading** ```bash wget -O gitea https://dl.gitea.com/gitea/1.21.4/gitea-1.21.4-linux-amd64 chmod +x gitea wget -O gitea.asc https://dl.gitea.com/gitea/1.21.4/gitea-1.21.4-linux-amd64.asc ``` **# Key verification** ```bash sudo apt install gnupg gpg --keyserver keys.openpgp.org --recv 7C9E68152594688862D62AF62D9AE806EC1592E2 gpg --verify gitea.asc gitea ``` **# Git user creation** ```bash sudo adduser \ --system \ --shell /bin/bash \ --gecos 'Git Version Control' \ --group \ --disabled-password \ --home /home/git \ git ``` **# Directory structure creation (as root)** ```bash mkdir -p /var/lib/gitea/{custom,data,log} chown -R git:git /var/lib/gitea/ chmod -R 750 /var/lib/gitea/ mkdir /etc/gitea chown root:git /etc/gitea chmod 770 /etc/gitea ``` **# copied bin to final location** ```bash sudo cp gitea /usr/local/bin/gitea ``` **# Autocomplete scripts** [bash_autocomplete](https://raw.githubusercontent.com/go-gitea/gitea/main/contrib/autocompletion/bash_autocomplete) in /usr/share/bash-completion/completions/gitea [zsh_autocomplete](https://raw.githubusercontent.com/go-gitea/gitea/main/contrib/autocompletion/zsh_autocomplete) in /usr/share/zsh/_gitea

Then here are my gitea.service and reverse proxy configurations :

GITEA.SERVICE + REVERSE PROXY

**# Service creation** gitea.service [Service] block : ```bash [Service] RestartSec=2s Type=simple User=git Group=git WorkingDirectory=/var/lib/gitea/ #RuntimeDirectory=gitea ExecStart=/usr/local/bin/gitea web --config /etc/gitea/app.ini Restart=always Environment=USER=git HOME=/home/git GITEA_WORK_DIR=/var/lib/gitea ``` **# Reverse Proxy** ``` ProxyPreserveHost On ProxyRequests off AllowEncodedSlashes NoDecode ProxyPass / http://localhost:3000/ nocanon ```

Then after all that I went to https://mygiteadomain and went through installation process which gave my this /etc/gitea/app.ini :

APP.INI

```bash APP_NAME = (my app name) RUN_USER = git WORK_PATH = /var/lib/gitea RUN_MODE = prod [database] DB_TYPE = postgres HOST = (my bdd ip address) NAME = giteadb USER = gitea PASSWD = (my bdd password in clear ???) SCHEMA = SSL_MODE = disable PATH = /var/lib/gitea/data/gitea.db LOG_SQL = false [repository] ROOT = /var/lib/gitea/data/gitea-repositories [server] SSH_DOMAIN = (my gitea domain) DOMAIN = (my gitea domain) HTTP_PORT = 3000 ROOT_URL = https://(my gitea domain)/ APP_DATA_PATH = /var/lib/gitea/data DISABLE_SSH = false SSH_PORT = 22 LFS_START_SERVER = true LFS_JWT_SECRET = (a secret) OFFLINE_MODE = false [lfs] PATH = /var/lib/gitea/data/lfs [mailer] ENABLED = true PROTOCOL = SMTPS SMTP_ADDR = (my smtp server address) SMTP_PORT = (my smtp server port) FROM = (my smtp server address) USER = PASSWD = [service] REGISTER_EMAIL_CONFIRM = false ENABLE_NOTIFY_MAIL = true DISABLE_REGISTRATION = true ALLOW_ONLY_EXTERNAL_REGISTRATION = false ENABLE_CAPTCHA = false REQUIRE_SIGNIN_VIEW = true DEFAULT_KEEP_EMAIL_PRIVATE = false DEFAULT_ALLOW_CREATE_ORGANIZATION = false DEFAULT_ENABLE_TIMETRACKING = true NO_REPLY_ADDRESS = noreply [openid] ENABLE_OPENID_SIGNIN = false ENABLE_OPENID_SIGNUP = false [cron.update_checker] ENABLED = false [session] PROVIDER = file [log] MODE = console LEVEL = info ROOT_PATH = /var/lib/gitea/log [repository.pull-request] DEFAULT_MERGE_STYLE = merge [repository.signing] DEFAULT_TRUST_MODEL = committer [security] INSTALL_LOCK = true ```

I must admit I'm a little bit confused here so here are some questions :

  1. Why are gitea help and site administration displaying different directories ?
  2. Is it the intended behavior to be unable to access/modify /var/lib/gitea unless we are user 'git' ?
  3. Generally speaking, did I do something wrong and if so what ?

Gitea Version

1.21.4

Git Version

2.39.2

Operating System

Debian 12

Database

PostgreSQL

zokkis commented 7 months ago

I'm not the best with the config, but after a quick test I think you have to do something like

gitea --config /path/to/app.ini to get the same result for help and for the service

PierreLouisPAUGAM commented 7 months ago

Hello @zokkis and thanks for your answer. I pasted content from my gitea.service file in my initial post and I think the following line : ExecStart=/usr/local/bin/gitea web --config /etc/gitea/app.ini should perform what you suggested don't you agree ?

wxiaoguang commented 7 months ago

I think zokkis is right. Gitea detects its paths by the config file.

So you would see different outputs by gitea help --config /etc/gitea/app.ini and gitea help

For your case, your custom folder should be /var/lib/gitea/custom, you need some "sudo" trick to create the direcotry and access/manage these files.

PierreLouisPAUGAM commented 6 months ago

Thanks @wxiaoguang and @zokkis. I managed to access the folder and do some tests as the git user.

If anyone is stuck in the same way in the future, the only way around I found is to :

sudo -i to access custom folder and manage files in it, then once changes are done change files owner and permissions so that gitea can access the files :

chown -R git:git /var/lib/gitea/
chmod -R 750 /var/lib/gitea/

su - git as root to run commands as git if needed (for debug purposes)

github-actions[bot] commented 6 months ago

Automatically locked because of our CONTRIBUTING guidelines