Import from GitHub enterprise via API fails with error: `Import failed due to a GitHub error: (HTTP 406)`
Summary
GitLab returns the error: Import failed due to a GitHub error: (HTTP 406)
when trying to import a project from GitHub enterprise server via the import API. Importing the project via UI works fine.
This works fine with GitLab 16.2 and earlier.
Steps to reproduce
Use the Import API to import a project.
Example Project
What is the current bug behavior?
Importing projects from GitHub enterprise server via the Import API results in HTTP 406 error.
What is the expected correct behavior?
Import via API should succeed.
Relevant logs and/or screenshots
API call response: Import failed due to a GitHub error: (HTTP 406)
.
This bug was originally reported by one of our customers through the ticket: https://gitlab.zendesk.com/agent/tickets/490604 (internal use). They were kind enough to run a packet capture of outgoing requests from GitLab 16.2.1 and 16.7.3. In the pcap output, we can see that v16.2.1 requests for the repositories with path /api/v3/repositories/<id>
while v16.7.2 misses out on the /api/v3
prefix. See the following pcap for details:
v16.2.1:
11:11:20.472096 IP x.x.x.234.53752 > x.x.x.239.http: Flags [P.], seq 1:288, ack 1, win 8212, length 287: HTTP: GET /api/v3/repositories/1 HTTP/1.1
11:11:20.514584 IP x.x.x.239.http > x.x.x.234.53752: Flags [.], ack 288, win 42, length 0
11:11:20.565307 IP x.x.x.239.http > x.x.x.234.53752: Flags [P.], seq 1:2674, ack 288, win 42, length 2673: HTTP: HTTP/1.1 200 OK
v16.7.3:
10:38:51.821722 IP x.x.x.234.49892 > x.x.x.239.http: Flags [P.], seq 1:324, ack 1, win 8212, length 323: HTTP: GET /login?return_to=http%3A%2F%2Fx.x.x.239%2Frepositories%2F1 HTTP/1.1
10:38:51.836940 IP x.x.x.239.http > x.x.x.234.49892: Flags [.], seq 1:1461, ack 324, win 42, length 1460: HTTP: HTTP/1.1 406 Not Acceptable
Output of checks
Results of GitLab environment info
Expand for output related to GitLab environment info
(For installations with omnibus-gitlab package run and paste the output of: `sudo gitlab-rake gitlab:env:info`) (For installations from source run and paste the output of: `sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production`)
Results of GitLab application Check
Expand for output related to the GitLab application check
(For installations with omnibus-gitlab package run and paste the output of:
sudo gitlab-rake gitlab:check SANITIZE=true
)(For installations from source run and paste the output of:
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true
)(we will only investigate if the tests are passing)
Possible fixes
The path prefix api/v3
got dropped from the GitHub Import on 16.5 when the importer stopped using Gitlab::LegacyGithubImport::Client which automatically adds the prefix when importing from a GitHub Enterprise URL
To fix the problem, we should add the prefix when importing from a GitHub Enterprise URL and update the GitHub Import API documentation mentioning that users should manually add the prefix when importing using a GitLab version from 16.5 to 17.1
Docs first update: Add known issue and its workaround for GH importer (!158330 - merged) - will have to be changes slightly when the issue is fixed.