[英]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.我尝试将 Gitlab Workflow 插件用于 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 api 返回
{
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如果我打电话给https://mydomain/gitlab/api/v4/projects/:id
其中 id 是我得到的项目号
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我已经尝试使用 Gitlab CE 12.xx 并现在使用https://github.com/sameersbn/docker-gitlab升级到最新版本 13 (13.0.6)
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 .访问令牌具有插件请求的api 和 read_user 权限。
Clearly I'm missing something.显然我错过了一些东西。 But what?但是什么?
EDIT:编辑:
My setup is having the docker container behind a reverse proxy apache.我的设置是在反向代理 apache 后面安装 docker 容器。 Maybe the authorization does not work as expected.也许授权没有按预期工作。 The plugin sends a header PRIVATE-TOKEN
.该插件发送一个 header PRIVATE-TOKEN
。 I'll check if the header is passed to the api.我将检查 header 是否已传递给 api。
Nope.没有。 The PRIVATE-TOKEN header is recieved by the docker container. PRIVATE-TOKEN header 由 docker 容器接收。
EDIT2:编辑2:
I set up a public group and a public project to eliminate auth problems.我建立了一个公共组和一个公共项目来消除身份验证问题。 Still does not work.还是不行。 Search returns 404.搜索返回 404。
EDIT3:编辑3:
Since Dashrath Mundkar asked about the curl command:由于 Dashrath Mundkar 询问了 curl 命令:
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.因为它可能与其他使用 Apache 2.4 作为 Gitlab 前面的反向代理的人非常相关,所以我回答了我自己的问题。
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 ) 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.通常, mod_proxy 也会规范化 ProxyPassed URL 。
So my backend recieved mygroup%252Fmyproject
(notice the added 25, encoding the % char in %2F) which led to the 404 from Gitlab.所以我的后端收到了mygroup%252Fmyproject
(注意添加的 25,编码 %2F 中的 % 字符),这导致来自 Gitlab 的 404。
After I changed the Apache config to ProxyPass /gitlab http://gitlab.local:80/gitlab nocanon
(I added nocanon) everything was working fine.在我将 Apache 配置更改为ProxyPass /gitlab http://gitlab.local:80/gitlab nocanon
(我添加了 nocanon)之后,一切正常。
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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.