How to use a password manager to provide personal access token to git push/pull

Viewed 674

Context

Assuming that:

  • I have a repository on GitLab and I have already cloned it on my machine.
  • I have a GitLab token allowing me to push from and pull to this repository.
  • This token is already saved into my Bitwarden vault.
  • Thanks to the Bitwarden CLI, I can authenticate/lock/unlock my vault programmatically.

Question

Is there a way to programmatically chain/pipe the GitLab token fetched on the fly by Bitwarden to the git push and pull commands in order to authenticate/authorize these operations?

Investigations

I heard about the following solutions to workaround the issue but they do not comply with the security rules I need to face: I can't store any secret in plain text on disk.

  • The GitLab token can be put in git credentials helper.store file. Here the GitLab token needs to be stored in plain text in the store file.
  • The git remote URLs can be modified to include the credentials in them. Here the GitLab token needs to be stored in plain text in git remote URLs.

Notes

  • I can't use SSH keys, I need to stay on the HTTPS protocol.
  • The git version I target is the one proposed from official Ubuntu packages (2.17.1 at the time of writing).
1 Answers

You can check if the custom Git credential helper AZMCode/git-credential-bw does what you need.

This is a project to integrate the Bitwarden CLI with Git so as to avoid inconveniences in having to retype a password multiple times, or manage multiple Bitwarden credentials for different sites.

git config credential.helper bw
Related