简体   繁体   中英

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

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.xx 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

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 eg 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.

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM