Gitlab api v4 returns 404 on project search when using namespace/projectname instead of id
Asked Answered
I

3

6

I try to use the Gitlab Workflow plugin for VS Code. Unfortunately it does not find my project. I debugged it and found that it calls

https://mydomain/gitlab/api/v4/projects/mygroup%2Fmyproject

and the api returns

{
error: "404 Project Not Found"
}

This should work according to the documentation.

If I call https://mydomain/gitlab/api/v4/projects/:id where id is the project number I get

path_with_namespace: "mygroup/myproject",

Browsing the internet I found some people claiming it does not work for them too but no solution. Others say it works perfectly for them.

I've tried with Gitlab CE 12.x.x and upgraded now to the latest version 13 (13.0.6) using https://github.com/sameersbn/docker-gitlab

I've tried with several projects to no avail.

I'm maintainer for the projects.

The access token has the rights api and read_user as requested by the plugin.

Clearly I'm missing something. But what?

EDIT:

My setup is having the docker container behind a reverse proxy apache. Maybe the authorization does not work as expected. The plugin sends a header PRIVATE-TOKEN. I'll check if the header is passed to the api.

Nope. The PRIVATE-TOKEN header is recieved by the docker container.

EDIT2:

I set up a public group and a public project to eliminate auth problems. Still does not work. Search returns 404.

EDIT3:

Since Dashrath Mundkar asked about the curl command:

curl -H "PRIVATE-TOKEN:XXXXXXX" https://mydomain/gitlab/api/v4/projects/mygroup%2Fmyproject
Irrepealable answered 24/7, 2020 at 12:50 Comment(1)
could share how you are calling api with full curl command (obviously hide your url and token just put XXXX there and paste here)Wigley
I
7

Ok. I found the answer and it is a bit specific to my setup.

Since it may be very well relevant for others too who are using Apache 2.4 as a reverse proxy in front of Gitlab, I answer my own question.

My config for Apache contained AllowEncodedSlashes NoDecode so that requests for Gitlab could contain an urlencoded path as needed by the Api e.g mygroup%2Fmyproject (otherwise Apache would already throw a 404, see AllowEncodedSlashes)

Unfortunately that was not enough. Normally, mod_proxy will canonicalise ProxyPassed URLs too.

So my backend recieved mygroup%252Fmyproject (notice the added 25, encoding the % char in %2F) which led to the 404 from Gitlab.

After I changed the Apache config to ProxyPass /gitlab http://gitlab.local:80/gitlab nocanon (I added nocanon) everything was working fine.

Irrepealable answered 25/7, 2020 at 17:31 Comment(1)
I faced that issue as well but while opening the WebIDE in GitLab where the WebIDE itself loaded well but the project could not get found. I had to add both, AllowEncodedSlashes NoDecode as well as the nocanon appendix.Matchmark
C
0

This worked for me

 <VirtualHost *:80>
    ServerName gitlab.example.lk

    ProxyRequests Off
    ProxyPreserveHost On
    ProxyVia Full

    <Proxy *>
        Require all granted
    </Proxy>

    AllowEncodedSlashes NoDecode
    ProxyPass / http://localhost:8181/ nocanon
    ProxyPassReverse / http://localhost:8181/
    RewriteEngine on
    RewriteCond %{SERVER_NAME} =www.gitlab.example.lk [OR]
    RewriteCond %{SERVER_NAME} =gitlab.example.lk
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
Colan answered 17/9, 2022 at 19:11 Comment(0)
B
0

In my case AllowEncodedSlashes NoDecode and nocanon were not enough, I had to add NE flag to the RewriteRule as well, so that it looks like

RewriteRule .* http://127.0.0.1:8181%{REQUEST_URI} [P,QSA,NE]
Bencion answered 26/10, 2023 at 15:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.