#825  Gitea import doesn't authenticate correctly with private repositories
Released
Mango opened 2 years ago

Setup:

  • Gitea 1.17.0 (running on http port 8081) inside a container on LAN
  • Onedev 7.4.9 (running on http port 6610) inside a container on LAN
  • Onedev container can access gitea
  • Created an access token for onedev in gitea via Settings -> Applications -> Generate Token.

Started import via Projects -> Import -> From Gitea.

  • Selected mango-internal organization
  • Specified mango-internal/buildbot repository
  • Deselected import issues
  • Dry run reports "Repositories imported successfully"

When running Import, the dialog reports:

Please wait...
Cloning code from repository mango-internal/buildbot...

Curiously in my server console for onedev I get this printed:

20:06:31 INFO  i.o.s.e.impl.DefaultProjectManager - Initializing git repository in '/opt/onedev/site/projects/15/git'...
Username for 'http://mango-services:8081': Password for 'http://mango-services:8081':

If I press enter on the console the import dialog then changes to:

Please wait...
Cloning code from repository mango-internal/buildbot...
Failed to run command: git clone --mirror http://mango-services:8081/mango-internal/buildbot.git ., return code: 128
Cloning into bare repository '.'...
remote: Unauthorized
fatal: Authentication failed for 'http://mango-services:8081/mango-internal/buildbot.git/'
Error importing from gitea

If I manually import http://mango-services:8081/mango-internal/buildbot.git using "Import -> From URL" and specify my username and password for gitea, there are no problems.

I would guess based on the behavior I'm seeing that onedev doesn't seem to be handling git authentication correctly in the case of importing projects from gitea.

Robin Shen commented 2 years ago

Looks like your Gitea base url is incorrect and Gitea returns repository clone url incorrectly.

Mango commented 2 years ago

Re-read my issue and it seems that I mistyped the port number in my report. Gitea is in fact running on port 8081 (corrected it). 😮

Investigated a bit further and if I change the settings for my organization "mango-internal" in gitea so the visibility is public, the import works fine. The problem seems to be when my organization is set to be "private" (and thus, checking out the repository requires a login).

Robin Shen commented 2 years ago

Just tested with OneDev and Gitea running on docker and import can run successfully. Please check if http clone url of the repository is "http://mango-services:8081/mango-internal/buildbot.git" at Gitea side. Also please run below from command from within OneDev's container to see if it works:

git clone http://git:<gitea access token>mango-services:8081/mango-internal/buildbot.git 
Mango commented 2 years ago

Hi again,

Cloning from the onedev container using the access token seems to work. I'm half wondering here if either gitea or onedev isn't providing the access token correctly when cloning in this circumstance.

I've reproduced the issue in a test setup, as follows:

  1. gitea hosted at http://mango-test:3001 (with docker)
  2. onedev hosted at http://mango-test:6610 (with docker, can also access docker host via mango-test)
  3. gitea has organizations "org1" and "org2" with respective projects "org1/repo1" and "org2/repo2"
  4. "org2" is set to be private

I can't seem to reproduce the "git needs input before the web dialog completes" behavior using the docker containers, though it could be something weird going on with my other standalone setup.

A test environment can be grabbed from here: https://1drv.ms/u/s!AoBL85OZXmkc9CCjWFei_DMYbLul?e=PusXx5

Which can be started on a system with docker installed by running:

tar -xzpf containers.tar.gz
cd containers
./launch_gitea.sh <server ip address for mango-test>

If I use the following details to import from gitea (with username=mango, password=password):

url: http://mango-test:3001/api/v1
token: 0103e4e7a68ef908cdbc72885c8456155a27b4fb

3 different scenarios can occur when going through the Import wizard...

  1. Importing org1/repo1 and org2/repo2 at the same time

The following is reported in the dialog:

Please wait...
Cloning code from repository org1/repo1...
Cloning code from repository org2/repo2...
Failed to run command: git clone --mirror http://mango-test:3001/org2/repo2.git ., return code: 128
Cloning into bare repository '.'...
fatal: could not read Username for 'http://mango-test:3001': No such device or address

No projects are generated in onedev.

  1. Importing org1/repo1

repo1 is successfully imported into onedev.

  1. Importing org2/repo2

The following is reported in the dialog:

Please wait...
Cloning code from repository org2/repo2...
Failed to run command: git clone --mirror http://mango-test:3001/org2/repo2.git ., return code: 128
Cloning into bare repository '.'...
fatal: could not read Username for 'http://mango-test:3001': No such device or address

No projects are generated in onedev.

For now, I seem to be able to workaround the issue by making everything public on my gitea instance before importing, but this might not be a desirable option for someone operating in some form of public cloud environment.

Thanks for your assistance so far!

Robin Shen commented 2 years ago

Thanks for the info. Turns out that a public repo inside a private org still needs access token for clone. Will fix that in next patch release.

OneDev changed state to 'Closed' 2 years ago
Previous Value Current Value
Open
Closed
OneDev commented 2 years ago

State changed as code fixing the issue is committed

OneDev changed state to 'Released' 2 years ago
Previous Value Current Value
Closed
Released
OneDev commented 2 years ago

State changed as build #2856 is successful

issue 1 of 1
Type
Bug
Priority
Normal
Assignee
Affected Versions
Not Found
Issue Votes (1)
Watchers (4)
Reference
onedev/server#825
Please wait...
Page is in error, reload to recover