gitea icon indicating copy to clipboard operation
gitea copied to clipboard

embedded subcommand not working in Linux

Open SuperSandro2000 opened this issue 5 years ago • 18 comments

  • Gitea version (or commit ref): 1.12.1 (till latest)

Description

The embedded subcommand does not work list or extract any files.

Screenshots

bash-5.0# gitea -v
Gitea version 1.12.1 built with GNU Make 4.2.1, go1.14.4 : bindata, sqlite, sqlite_unlock_notify
bash-5.0# gitea embedded list '**'
bash-5.0#

Reason

Gitea embedded can not run with mismatched Linux user in an installed config, there will be no output at all.

Workaround

Run gitea with the correct Linux user (as in the app.ini), using su or sudo

SuperSandro2000 avatar Jun 28 '20 13:06 SuperSandro2000

~In fact the command name is embed not embedded~

lunny avatar Jul 05 '20 04:07 lunny

Yeah, this is wrong in the help:

bash-5.0# gitea help                                                                                                                                                                                              
NAME:                                                                                                                                                                                                             
   Gitea - A painless self-hosted Git service                                                                                                                                                                     
                                                                                                                                                                                                                  
USAGE:                                                                                                                                                                                                            
   gitea [global options] command [command options] [arguments...]                                                                                                                                                
                                                                                                                                                                                                                  
VERSION:                                                                                                                                                                                                          
   1.12.1 built with GNU Make 4.2.1, go1.14.4 : bindata, sqlite, sqlite_unlock_notify                                                                                                                             
                                                                                                                                                                                                                  
DESCRIPTION:                                                                                                                                                                                                      
   By default, gitea will start serving using the webserver with no                                                                                                                                               
arguments - which can alternatively be run by running the subcommand web.                                                                                                                                         
                                                                                                                                                                                                                  
COMMANDS:                                                                                                                                                                                                         
     web       Start Gitea web server                                                                                                                                                                             
     serv      This command should only be called by SSH shell                                                                                                                                                    
     hook      Delegate commands to corresponding Git hooks                                                                                                                                                       
     dump      Dump Gitea files and database                                                                                                                                                                      
     cert      Generate self-signed certificate                                                                                                                                                                   
     admin     Command line interface to perform common administrative operations                                                                                                                                 
     generate  Command line interface for running generators                                                                                                                                                      
     migrate   Migrate the database                                                                                                                                                                               
     keys      This command queries the Gitea database to get the authorized command for a given ssh key fingerprint                                                                                              
     convert   Convert the database                                                                                                                                                                               
     doctor    Diagnose problems                                                                                                                                                                                  
     manager   Manage the running gitea process                                                                                                                                                                   
     embedded  Extract embedded resources                                                                                                                                                                         
     help, h   Shows a list of commands or help for one command                                                                                                                                                   
                                                                                                                                                                                                                  
GLOBAL OPTIONS:                                                                                                                                                                                                   
   --port value, -p value         Temporary port number to prevent conflict (default: "3000")                                                                                                                     
   --pid value, -P value          Custom pid file path (default: "/var/run/gitea.pid")                                                                                                                            
   --custom-path value, -C value  Custom path file path (default: "/data/gitea")                                                                                                                                  
   --config value, -c value       Custom configuration file path (default: "/data/gitea/conf/app.ini")                                                                                                            
   --version, -v                  print the version                                                                                                                                                               
   --work-path value, -w value    Set the gitea working path (default: "/usr/local/bin")                                                                                                                          
   --help, -h                     show help     
                                                                                                                                                                                                                  
GLOBAL OPTIONS:                                                                                                                                                                                                   
   --port value, -p value         Temporary port number to prevent conflict (default: "3000")                                                                                                                     
   --pid value, -P value          Custom pid file path (default: "/var/run/gitea.pid")                                                                                                                            
   --custom-path value, -C value  Custom path file path (default: "/data/gitea")                                                                                                                                  
   --config value, -c value       Custom configuration file path (default: "/data/gitea/conf/app.ini")                                                                                                            
   --version, -v                  print the version                                                                                                                                                               
   --work-path value, -w value    Set the gitea working path (default: "/usr/local/bin")                                                                                                                          
   --help, -h                     show help                                                                                                                                                                       
                                                                                                                                                                                                                  
DEFAULT CONFIGURATION:                                                                                                                                                                                            
     CustomPath:  /data/gitea (GITEA_CUSTOM)                                                                                                                                                                      
     CustomConf:  /data/gitea/conf/app.ini                                                                                                                                                                        
     AppPath:     /usr/local/bin/gitea                                                                                                                                                                            
     AppWorkPath: /usr/local/bin                                                                                                                                                                                  

SuperSandro2000 avatar Jul 06 '20 14:07 SuperSandro2000

I'm confused by this response. embedded seems to be parsed properly while embed (or any other random string) merely attempts to boot up gitea.

ghost avatar Jul 29 '20 20:07 ghost

If the command is not understood it should error.

SuperSandro2000 avatar Jul 30 '20 17:07 SuperSandro2000

embedded is the correct sub-command name.
The reason strings that aren't valid sub-commands boot up gitea is because of https://github.com/go-gitea/gitea/blob/838fef2ae84f8752363e8e3e31c252d66a5c6027/main.go#L98-L101

We are setting the default command to be the same we gitea web


As for why the command isn't working for you, you need to specify the config file with the -c flag.

e.g. gitea -c /etc/gitea/app.ini embedded list

jolheiser avatar Jul 30 '20 17:07 jolheiser

I'm getting empty file listings in docker exec, while the paths are being detected without flags:

DEFAULT CONFIGURATION:
     CustomPath:  /data/gitea (GITEA_CUSTOM)
     CustomConf:  /data/gitea/conf/app.ini
     AppPath:     /usr/local/bin/gitea
     AppWorkPath: /usr/local/bin

I've however tried adding the flag, and no files were listed still.

/ # gitea -c /data/gitea/conf/app.ini embedded list '**'
/ #

ghost avatar Jul 30 '20 20:07 ghost

This issue has been automatically marked as stale because it has not had recent activity. I am here to help clear issues left open even if solved or waiting for more insight. This issue will be closed if no further activity occurs during the next 2 weeks. If the issue is still valid just add a comment to keep it alive. Thank you for your contributions.

stale[bot] avatar Sep 29 '20 05:09 stale[bot]

bump

SuperSandro2000 avatar Sep 29 '20 08:09 SuperSandro2000

I can't replicate your problem.

This works on gitea/gitea:latest:

docker pull gitea/gitea:latest
docker run gitea/gitea:latest &
docker exec $(docker ps | grep gitea | cut -f1 -d\ ) gitea embedded list "**"

This works on gitea/gitea:1.12:

docker pull gitea/gitea:1.12
docker run gitea/gitea:1.12 &
docker exec $(docker ps | grep gitea | cut -f1 -d\ ) gitea embedded list "**"

view appears to work

docker exec $(docker ps | grep gitea | cut -f1 -d\ ) gitea embedded view templates/user/settings/keys.tmpl

extract also works.

docker exec $(docker ps | grep gitea | cut -f1 -d\ ) gitea embedded extract templates/user/auth/change_passwd_inner.tmpl
docker exec $(docker ps | grep gitea | cut -f1 -d\ ) cat templates/user/auth/change_passwd_inner.tmpl

zeripath avatar Sep 29 '20 21:09 zeripath

This issue still seems to be present. I can get a result from embedded list but only by specifying an invalid config file.

(1) With invalid config file - works

bash-5.1# gitea -c garbage/app.ini embedded list templates/user/settings/keys.tmpl
2021/11/27 13:46:59 ...s/setting/setting.go:547:SetCustomPathAndConf() [W] Using 'custom' directory as relative origin for configuration file: '/data/gitea/garbage/app.ini'
2021/11/27 13:46:59 ...s/setting/setting.go:547:SetCustomPathAndConf() [W] Using 'custom' directory as relative origin for configuration file: '/data/gitea/garbage/app.ini'
2021/11/27 13:46:59 ...s/setting/setting.go:547:SetCustomPathAndConf() [W] Using 'custom' directory as relative origin for configuration file: '/data/gitea/garbage/app.ini'
templates/user/settings/keys.tmpl

(2) With correct path to config file - No Result

bash-5.1# gitea -c conf/app.ini embedded list templates/user/settings/keys.tmpl
2021/11/27 13:47:46 ...s/setting/setting.go:547:SetCustomPathAndConf() [W] Using 'custom' directory as relative origin for configuration file: '/data/gitea/conf/app.ini'
2021/11/27 13:47:46 ...s/setting/setting.go:547:SetCustomPathAndConf() [W] Using 'custom' directory as relative origin for configuration file: '/data/gitea/conf/app.ini'
2021/11/27 13:47:46 ...s/setting/setting.go:547:SetCustomPathAndConf() [W] Using 'custom' directory as relative origin for configuration file: '/data/gitea/conf/app.ini'
bash-5.1#

(3) With no path specified (presumably using /data/gitea/conf/app.ini) - No Result

bash-5.1# gitea embedded list templates/user/settings/keys.tmpl
bash-5.1#

stat showing the config file exists at the location used for (2) (3)

bash-5.1# stat /data/gitea/conf/app.ini
  File: /data/gitea/conf/app.ini
  Size: 2449            Blocks: 8          IO Block: 4096   regular file
Device: 802h/2050d      Inode: 31590370    Links: 1
Access: (0600/-rw-------)  Uid: ( 1000/     git)   Gid: ( 1000/     git)
Access: 2021-11-27 04:13:00.305459938 +0100
Modify: 2021-11-27 10:49:48.344909082 +0100
Change: 2021-11-27 10:49:48.344909082 +0100

So a workaround seems to be to specify an incorrect config file. I'm using gitea docker 1.15.6

rmawatson avatar Nov 27 '21 15:11 rmawatson

I meet the similar problem on my side: embedded list outputs nothing.

If I do TAGS=bindata make build (1.16) on macOS, then ./gitea embedded list can output the correct list.

But if I do GOOS=... TAGS=bindata make build (1.16) and copy the binary into the Linux docker, ./gitea embedded list outputs nothing. (I know my operation is a little strange, but whatever happens the output should not be empty)

wxiaoguang avatar Nov 27 '21 16:11 wxiaoguang

I should note that it seems that when using an 'invalid' app.ini path, the file and path gets created with the content:

[security]
INTERNAL_TOKEN = eyJhbGciOiJIUzI1NiIsInR5cCI6......................VRdGT1imauIcCNegCJi0xjZQyB46FGa7v7qtUF_IAc

rmawatson avatar Nov 27 '21 16:11 rmawatson

I should note that it seems that when using an 'invalid' app.ini path, the file and path gets created with the content:

[security]
INTERNAL_TOKEN = eyJhbGciOiJIUzI1NiIsInR5cCI6......................VRdGT1imauIcCNegCJi0xjZQyB46FGa7v7qtUF_IAc

@rmawatson That's a bug, will be fixed in https://github.com/go-gitea/gitea/pull/17779

You can delete these files & directories safely.

wxiaoguang avatar Nov 27 '21 16:11 wxiaoguang

Thanks - have deleted.

Unfortunately when #17779 is merged, it will give an error according to the change list

Show errors in CLI code if an incorrect app.ini is used

So the current 'workaround' to specify an invalid app.ini wont work.

rmawatson avatar Nov 27 '21 16:11 rmawatson

Thanks - have deleted.

Unfortunately when #17779 is merged, it will give an error according to the change list

Show errors in CLI code if an incorrect app.ini is used

So the current 'workaround' to specify an invalid app.ini wont work.

Nope, that PR just does correct things, embeded sub-commands don't require an app.ini actually, so you won't see that error message.

And that PR is not related to this bug, I will hide these two comments here.

wxiaoguang avatar Nov 27 '21 16:11 wxiaoguang

Some thoughts (maybe conclusions):

  1. This bug is not Docker-related: I can reproduce it in a real Linux server
  2. This bug is not config (app.ini) related: The embedded sub-commands don't need it
  3. The embedded list and embedded view may output nothing (even with the with non-existing file paths): it's abnormal, embedded view should output error messages if the target doesn't exist.
  4. The bug seems related with the console output mechanism (according 3)

ps: I haven't investigated this problem carefully, these information is just FYI, correct me if I was wrong.

wxiaoguang avatar Nov 27 '21 17:11 wxiaoguang

@lunny I think this is a bug, not related to docker. See my comments above. So maybe we should keep this open.

wxiaoguang avatar Dec 06 '21 02:12 wxiaoguang

I found the root case of this bug.

  1. There is a check: https://github.com/go-gitea/gitea/blob/72f9050689912f5910a08d593ebe53078fe85aa4/modules/setting/setting.go#L954 . The code is pretty old (as early as 2014)
  2. The embedded command removes loggers: https://github.com/go-gitea/gitea/blob/72f9050689912f5910a08d593ebe53078fe85aa4/cmd/embedded.go#L115

Then bad thing happens: Gitea embedded can not run with mismatched Linux user in an installed config, and no error is outputted.

wxiaoguang avatar Dec 29 '21 09:12 wxiaoguang

working that way:

# ls -l conf/app.ini
-rw-r--r-- 1 git git 2611 Jan 16 19:09 conf/app.ini

# su git -s /usr/local/bin/gitea embedded list

grubjack avatar Jan 17 '23 10:01 grubjack