VSCode + Gitlab PAT... help!

Have been using VSCode with Gitlab for a long time, connecting to multiple projects within the same Gitlab account without problems. I have been using the Gitlab Workflow VSCode extension, and set up a PAT to work with that extension some time ago.

Recently I got a notification that the PAT was going to expire.
So I created a new PAT and installed it following the instructions given with the Extension, but now have lost all access to the Gitlab projects within my account. One factor is what path I should use when installing the new PAT - should it be to the parent account directory, or to each specific project separately: I only ever installed one PAT when I set up the system. Documentation is not clear about what needs to be done.

Can anyone give me any guidance on how to resolve this issue so that my projects can reconnect with my Gitlab account? Many thanks in advance for any help that can be provided for this!

Thanks for taking the time to be thorough in your request, it really helps! :blush:

Hi,

Can you share details how and where you created the personal access token? Maybe it is the wrong user with limited access to projects.

Cheers,
Michael

Hi.
I opened up Gitlab website, logged into my account, clicked on my avatar and chose ā€œPreferencesā€, then clicked on the ā€œAccess Tokensā€ option on LH menu, and then created a new personal access token with read_user and api permissions.

Hi,

thatā€™s strange. Iā€™ve checked my PAT permissions for using the VS Code extension, looks the same.

I donā€™t follow what you mean by the parent account directory. Can you share the project and group structure you are using, and the membership permissions? The personal access token is tied to your user which needs to have appropriate permissions into groups and projects.

(There is something which is called a project access token, that is something different, mainly used for automation)

Also, please share whether it is a self-managed GitLab instance, including the version, or GitLab.com SaaS.

Cheers,
Michael

Hi Michael.
Itā€™s a gitlab hosted thing.
So the path to the account is https://gitlab.com/account
The path to a project is https://gitlab.com/account/project
There are multiple projects held within the account (so account/project_1, account/project_2 etc.)
VSCode is connecting to each project separately, but I have (as far as I am aware) only ever created one PAT to allow Gitlab Workflow extension to see / interact with the projects.
So I am not clear if I create a new PAT for https://gitlab.com/account or one each for https://gitlab.com/account_1 ā€¦ etc.
Have tried doing both types, and neither have worked.
VSCode reports ā€œGit: Host key verification failed.ā€ when I try to sync to one of the projects.
Terminal reports ā€œHost key verification failed.
fatal: Could not read from remote repository.ā€
So am baffledā€¦
Thank you so much for taking an interest, I hope there is a way for me to understand enough to fix this!

Aaaaaah. I thought you do not see any projects, thus lacking permissions with using the PAT for authentication.

It seems though that the sync is not using HTTPS, where it would use the PAT. A host key verification error originates from SSH.

AFAIK VS Code uses the local git client on your system, and the .git/config in your project directory. Can you open it, and show the remote origin?

My guess is that it was cloned with SSH once, looking like git@gitlabserver.com:user/project.git.

For using a PAT, it needs to be https://gitlabserver.com/user/project.git, and when asked for credentials, user = user, password = PAT.

Letā€™s try to fix SSH first, following Host Key Verification Failed - GitLab with Visual Studio Code on macOS - Stack Overflow

In your home directory, thereā€™s ~/.ssh/known_hosts which caches the host key from your GitLab server. Search for the hostname in there, and delete the line.

Try to sync again. If it doesnā€™t work, lookup the servers IP address in the file and delete the line too.

If it works, you can keep the git operations with SSH, or change the origin to https shown above.

Cheers,
Michael

Hi Michael
Thanks for the extra info. I tried to reset the ssh connection / host key but that simply moved the issue. Now Iā€™m getting the report back on trying to sync with the Gitlab account
Git: git@gitlab.com: Permission denied (publickey,keyboard-interactive).
This may be progress, or may not.
Any more thoughts?

Hi,

so now the message says that your SSH key was rejected in your user profile.

Git: git@gitlab.com: Permission denied (publickey,keyboard-interactive).

Then there is no better way than to change to https instead of SSH in your Git config.

Use your preferred editor and open .git/config in the current project. Edit the remote origin entry

-git@gitlabserver.com:user/project.git.
+https://gitlabserver.com/user/project.git

Then try a fetch/sync again. It will ask for your username (use the username) and the password (use the PAT). Allow Git to store the credentials in your OSā€™es credential store.

If it helps, you can also delete the project locally, and clone it again with

git clone https://gitlabserver.com/user/project.git

It will ask for your username (use the username) and the password (use the PAT). Allow Git to store the credentials in your OSā€™es credential store.

Cheers,
Michael

Michael
Thanks again for your patience with this.
We finally go there, not 100% same as you suggested, so noting here in case useful to another:

  1. edited the .git/config file for the problem projects as you suggested - it looks like it was already doing https syncing, but I replaced what was there with a simple https://ā€¦ entry of the type you suggested
  2. went to the VSCode pop up menu and selected ā€˜Gitlab: Remove Your Gitlab Personal Access Tokenā€™ and then selected a project (to remove that token from that project)
  3. created a new PAT in Gitlab web interface
  4. went to VSCode pop up menu and selected ā€˜Gitlab: Set Gitlab Personal Access Tokenā€™ and then entered the project URL on gitlab for the project and then pasted in the PAT
  5. synced the project - went through no problems
  6. repeat for other projectsā€¦

Thank you very very much for helping me to this happy place - I simply would not have got this sorted neatly without your helpā€¦ next option was blowing the git project folders locally and re-creating, which would have been a pain!

2 Likes

Hi @jcogs,

glad you could figure it out, even being a tough call :slight_smile: I learned new things myself, and future users can benefit from your detailed comments. Maybe youā€™d like to stick around here and help with your expertise and/or feedback? Together we can answer more questions, and ensure that there more happy GitLab users out there :fox_face:

Kind regards,
Michael

1 Like