Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access GitLab repo with project access token

According to the documentation, it should be possible to access GitLab repos with project access tokens:

The username is set to project_{project_id}_bot, such as project_123_bot.

Never mind that that's a lie -- the actual user is called project_4194_bot1 in my case; apparently they increment a number for subsequent tokens.

Either way -- and I have tried both with and without the trailing 1 -- I would expect

git clone "https://project_4194_bot1:[email protected]/my-group/my-project.git"

to succeed, same as with my.username:$PERSONAL_TOKEN (which works perfectly). However, I get

remote: HTTP Basic: Access denied
fatal: Authentication failed for '<snip>'

What may be going on here? How can I access GitLab repositories using project access tokens?


It's not as if we'd get that far, but FWIW, the token seems to have sufficient permissions:

enter image description here

like image 547
Raphael Avatar asked Sep 16 '20 16:09

Raphael


People also ask

How do I access my git access token?

Under your GitHub user profile (not the repository profile), click the “Settings” link. Scroll down and click the “Developer Settings” link. Click the GitHub “Personal access tokens” link. Click the “Generate new token” link and provide your password again if required.

What is a project access token?

Project access tokens are similar to passwords, except you can limit access to resources, select a limited role, and provide an expiry date. Use a project access token to authenticate: With the GitLab API. With Git, when using HTTP Basic Authentication, use: Any non-blank value as a username.


2 Answers

It seems that using the project name as username works. In your case replacing project_4194_bot1 with my-project should work:

git clone "https://my-project:[email protected]/my-group/my-project.git"

EDIT: One can actually use any non-blank value as a username (see docs), as others correctly pointed out.

like image 172
Rafael-WO Avatar answered Oct 17 '22 08:10

Rafael-WO


From the GitLab documentation:

With Git, when using HTTP Basic Authentication, use:

  • Any non-blank value as a username.
  • The project access token as the password.

In previous GitLab versions, it would have been necessary to use project_4194_bot1 as the username. However, the current version lets you use any username you wish:

git clone "https://anything:[email protected]/my-group/my-project.git"
like image 1
Gavin Uberti Avatar answered Oct 17 '22 08:10

Gavin Uberti