Project Import Status API returns a 403 when 'GitLab Export' import source is disabled

Summary

Invoking an API call to get project import status such as: GET /projects/:id/import fails if 'GitLab Export' is not ticked within the Import Sources section Visibility and Access controls section of Settings.

Full path:

Admin Area > Settings > General > Visibility and access controls > Import Sources

Steps to reproduce

  1. Import a project into a self-managed GitLab instance, using any type of import option.
  2. Within the self-managed instance, with a user with administator permissions, navigate to Admin Area > Settings > General > Visibility and access controls.
  3. De-select 'GitLab export' checkbox, then Save Changes
  4. Create an access token for your account with API-level access.
  5. Attempt a curl command similar to: curl -i -H "PRIVATE-TOKEN: EXAMPLE" https://gitlab.example.com/api/v4/projects/PROJECT/import

Example Project

N/A - Self-managed instances only due to Admin Area not being available to standard users.

Relevant ZD Ticket

This may also be related to 403 errors returned by the GitLab terraform provider as noted in this GitHub issue

What is the current bug behavior?

With GitLab export disabled, the curl command will return a 403 Forbidden error and no applicable API data.

What is the expected correct behavior?

A successful 200 return message from nginx along with the expected API data.

Relevant logs and/or screenshots

With GitLab Export enabled:

==> /var/log/gitlab/gitlab-rails/production.log <==
Started GET "/api/v4/projects/2/import" for 127.0.0.1 at 2021-12-20 22:46:15 +0000

==> /var/log/gitlab/gitlab-rails/api_json.log <==
{"time":"2021-12-20T22:46:15.748Z","severity":"INFO","duration_s":0.02774,"db_duration_s":0.00528,"view_duration_s":0.02246,"status":200,"method":"GET","path":"/api/v4/projects/2/import","params":[],"host":"localhost","remote_ip":"127.0.0.1, 127.0.0.1","ua":"curl/7.74.0-DEV","route":"/api/:version/projects/:id/import","user_id":2,"username":"test","queue_duration_s":0.009215,"db_count":12,"db_write_count":0,"db_cached_count":1,"cpu_s":0.03206,"mem_objects":12264,"mem_bytes":907808,"mem_mallocs":2599,"mem_total_bytes":1398368,"correlation_id":"01FQD0C9CY9780JB090B24M721","meta.user":"test","meta.project":"root/iterm2","meta.root_namespace":"root","meta.caller_id":"GET /api/:version/projects/:id/import","meta.remote_ip":"127.0.0.1","meta.feature_category":"importers","meta.client_id":"user/2"}

==> /var/log/gitlab/gitlab-workhorse/current <==
{"content_type":"application/json","correlation_id":"01FQD0C9CY9780JB090B24M721","duration_ms":38,"host":"localhost","level":"info","method":"GET","msg":"access","proto":"HTTP/1.1","referrer":"","remote_addr":"127.0.0.1:0","remote_ip":"127.0.0.1","route":"^/api/","status":200,"system":"http","time":"2021-12-20T22:46:15Z","ttfb_ms":38,"uri":"/api/v4/projects/2/import","user_agent":"curl/7.74.0-DEV","written_bytes":295}

==> /var/log/gitlab/nginx/gitlab_access.log <==
127.0.0.1 - - [20/Dec/2021:22:46:15 +0000] "GET /api/v4/projects/2/import HTTP/1.1" 200 295 "" "curl/7.74.0-DEV" -

With GitLab export disabled:

==> /var/log/gitlab/gitlab-rails/production.log <==
Started GET "/api/v4/projects/2/import" for 127.0.0.1 at 2021-12-20 23:11:57 +0000

==> /var/log/gitlab/gitlab-rails/api_json.log <==
{"time":"2021-12-20T23:11:57.863Z","severity":"INFO","duration_s":0.01608,"db_duration_s":0.0,"view_duration_s":0.01608,"status":403,"method":"GET","path":"/api/v4/projects/2/import","params":[],"host":"localhost","remote_ip":"127.0.0.1, 127.0.0.1","ua":"curl/7.74.0-DEV","route":"/api/:version/projects/:id/import","queue_duration_s":0.051818,"db_count":0,"db_write_count":0,"db_cached_count":0,"cpu_s":0.055968,"mem_objects":9775,"mem_bytes":3053544,"mem_mallocs":4807,"mem_total_bytes":3444544,"correlation_id":"01FQD1VBB1J8N4ZPYJMD0XQSRT","meta.caller_id":"GET /api/:version/projects/:id/import","meta.remote_ip":"127.0.0.1","meta.feature_category":"importers","meta.client_id":"ip/127.0.0.1"}

==> /var/log/gitlab/gitlab-workhorse/current <==
{"content_type":"application/json","correlation_id":"01FQD1VBB1J8N4ZPYJMD0XQSRT","duration_ms":72,"host":"localhost","level":"info","method":"GET","msg":"access","proto":"HTTP/1.1","referrer":"","remote_addr":"127.0.0.1:0","remote_ip":"127.0.0.1","route":"^/api/","status":403,"system":"http","time":"2021-12-20T23:11:57Z","ttfb_ms":72,"uri":"/api/v4/projects/2/import","user_agent":"curl/7.74.0-DEV","written_bytes":27}

==> /var/log/gitlab/nginx/gitlab_access.log <==
127.0.0.1 - - [20/Dec/2021:23:11:57 +0000] "GET /api/v4/projects/2/import HTTP/1.1" 403 27 "" "curl/7.74.0-DEV" -

Output of checks

Results of GitLab environment info

This has been taken from a spun-up docker environment replicate the reported client's environment.

Expand for output related to GitLab environment info
```
System information
System:
Proxy:          no
Current User:   git
Using RVM:      no
Ruby Version:   2.7.2p137
Gem Version:    3.1.4
Bundler Version:2.1.4
Rake Version:   13.0.3
Redis Version:  6.0.14
Git Version:    2.31.1
Sidekiq Version:5.2.9
Go Version:     unknown

GitLab information
Version:        13.12.12-ee
Revision:       7f1dc4f5c29
Directory:      /opt/gitlab/embedded/service/gitlab-rails
DB Adapter:     PostgreSQL
DB Version:     12.6
URL:            https://bking-basic.sr.gitlab.support
HTTP Clone URL: https://bking-basic.sr.gitlab.support/some-group/some-project.git
SSH Clone URL:  git@bking-basic.sr.gitlab.support:some-group/some-project.git
Elasticsearch:  no
Geo:            no
Using LDAP:     no
Using Omniauth: yes
Omniauth Providers:

GitLab Shell
Version:        13.18.1
Repository storage paths:
- default:      /var/opt/gitlab/git-data/repositories
GitLab Shell path:              /opt/gitlab/embedded/service/gitlab-shell
Git:            /opt/gitlab/embedded/bin/git
```

Results of GitLab application Check

Expand for output related to the GitLab application check
Checking GitLab subtasks ...

Checking GitLab Shell ...

GitLab Shell: ... GitLab Shell version >= 13.18.1 ? ... OK (13.18.1) Running /opt/gitlab/embedded/service/gitlab-shell/bin/check Internal API available: OK Redis available via internal API: OK gitlab-shell self-check successful

Checking GitLab Shell ... Finished

Checking Gitaly ...

Gitaly: ... default ... OK

Checking Gitaly ... Finished

Checking Sidekiq ...

Sidekiq: ... Running? ... yes Number of Sidekiq processes (cluster/worker) ... 1/1

Checking Sidekiq ... Finished

Checking Incoming Email ...

Incoming Email: ... Reply by email is disabled in config/gitlab.yml

Checking Incoming Email ... Finished

Checking LDAP ...

LDAP: ... LDAP is disabled in config/gitlab.yml

Checking LDAP ... Finished

Checking GitLab App ...

Git configured correctly? ... yes Database config exists? ... yes All migrations up? ... yes Database contains orphaned GroupMembers? ... no GitLab config exists? ... yes GitLab config up to date? ... yes Log directory writable? ... yes Tmp directory writable? ... yes Uploads directory exists? ... yes Uploads directory has correct permissions? ... yes Uploads directory tmp has correct permissions? ... skipped (no tmp uploads folder yet) Init script exists? ... skipped (omnibus-gitlab has no init script) Init script up-to-date? ... skipped (omnibus-gitlab has no init script) Projects have namespace: ... 2/1 ... yes 1/2 ... yes Redis version >= 5.0.0? ... yes Ruby version >= 2.7.2 ? ... yes (2.7.2) Git version >= 2.31.0 ? ... yes (2.31.1) Git user has default SSH configuration? ... yes Active users: ... 1 Is authorized keys file accessible? ... yes GitLab configured to store new projects in hashed storage? ... yes All projects are in hashed storage? ... yes Elasticsearch version 7.x (6.4 - 6.x deprecated to be removed in 13.8)? ... skipped (elasticsearch is disabled)

Checking GitLab App ... Finished

Checking GitLab subtasks ... Finished

Possible fixes

This specific line within project_import.rb appears to perform the relevant checks for if GitLab export is enabled.

Within Gitlab::CurrentSettings.import_sources, GitLab export is handled as gitlab_project.

Possible solutions may include:

  • Removal of this check entirely, if this is not required.
  • Increasing the scope of the import_sources check, to permit the API call as long as any one type of import source is enabled
  • Updating of API documentation to indicate you must have GitLab export enabled.