0

I have run into issues trying to hit a specific API endpoint in GitLab for creating/retrieving files within a repository, but ONLY IF those files exist in a sub-directory within the repository.

API docs for getting a repo file via API

There is a post here that explains the issue occurs b/c of the proxy frontend. I am able to verify this is indeed the case. When I try to hit the endpoint locally from the GitLab server it works fine.

I have tried to add a custom Nginx config for not decoding the URL like what is mentioned in this post, but I cannot get it to work.

Here is an example layout of a test repository (project ID = 4):

test.py
src/
  |_
    main.py

When getting the test.py file from the root directory, the URL looks like this:
https://gitlab-server/api/v4/projects/4/repository/files/test%2Epy?ref=master

When getting the src/main.py file from the repo, the URL looks like this:
https://gitlab-server/api/v4/projects/4/repository/files/src%2Fmain%2Epy?ref=master

However... When this URL hits Nginx it is decoded into the following URL:
https://gitlab-server/api/v4/projects/4/repository/files/src/main.py?ref=master
This is changing the API endpoint into a URL that can't be found.

How can I write a custom Nginx config to add to the gitlab.rb conf file that will ignore decoding the URL for this specific API endpoint? I have tried the following block but this has not helped:

location ~ /api/v\d/projects/\d+/repository/files/ {
  proxy_cache off;
  proxy_pass http://gitlab-workhorse;
}

I find it frustrating that GitLab will not take this issue into consideration, even though they ship their Omnibus/Docker package with an Nginx proxy by default.

ShaneC
  • 29
  • 1
  • 8

0 Answers0