Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Git: Support prompting for GPG password #43809

Open
deeprobin opened this issue Feb 16, 2018 · 49 comments
Open

Git: Support prompting for GPG password #43809

deeprobin opened this issue Feb 16, 2018 · 49 comments
Assignees
Labels
feature-request Request for new features or functionality git GIT issues help wanted Issues identified as good community contribution opportunities
Milestone

Comments

@deeprobin
Copy link

  • VSCode Version: 1.19.3
  • OS Version: Windows 10

Hey, Git don't work in Visual Studio Code, when i have gpg signing activated.

Steps to reproduce: https://help.github.com/articles/signing-commits-with-gpg/

Does this issue occur when all extensions are disabled?: Yes

@vscodebot vscodebot bot added the git GIT issues label Feb 16, 2018
@stevenhay
Copy link

It doesn't work if you use in gits default gpg feature, however, if you install Gpg4win and tell git to use that instead then it works.

git config --global gpg.program "C:\Program Files (x86)\GnuPG\bin\gpg.exe"

@deeprobin
Copy link
Author

deeprobin commented Feb 16, 2018

@stevenhay Yes, but it's nice if visual studio code supports it from his self (without any other applications)

@stevenhay
Copy link

Oh yeah I agree, definitely. Just thought I'd give a workaround for now though, I could have been more clear.

@joaomoreno joaomoreno reopened this Feb 19, 2018
@joaomoreno joaomoreno changed the title Git GPG Signing do not work Support git GPG signing Feb 19, 2018
@joaomoreno joaomoreno added this to the Backlog milestone Feb 19, 2018
@joaomoreno joaomoreno added the feature-request Request for new features or functionality label Feb 19, 2018
@joaomoreno joaomoreno removed their assignment Feb 19, 2018
@NatoBoram
Copy link

NatoBoram commented Apr 17, 2018

Solutions proposed here did not solve my problem.

Error :

gpg: cannot open tty `/dev/tty': No such device or address
error: gpg failed to sign the data
fatal: failed to write commit object

Configuration :

git config --global commit.gpgsign
true

cat ~/.gnupg/gpg-agent.conf
default-cache-ttl 46000
pinentry-program /usr/bin/pinentry-gtk-2
allow-preset-passphrase

If someone could shed some light on gpg-agent.conf, I'd like to know what settings are actually useful to sign my commits.

VSCode-Insiders :

{
	"git.enableCommitSigning": true,
}

OS :

neofetch --backend off
OS: Ubuntu 16.04.4 LTS x86_64 
Kernel: 4.13.0-39-generic 
Uptime: 17 hours, 15 mins 
Packages: 2984 
Shell: bash 4.3.48 
Resolution: 1024x768, 1920x1080 
DE: GNOME 3.18.5 
WM: GNOME Shell 
WM Theme: Adwaita 
Theme: Adwaita [GTK2/3] 
Icons: Elementary-xfce-dark [GTK2/3] 
CPU: Intel i5 660 (4) @ 2.895GHz 
GPU: NVIDIA GeForce 8400 GS Rev. 2 
Memory: 2452MiB / 7840MiB 

So... How do we GPG-sign our commits with VSCode?

@pedzed
Copy link

pedzed commented Aug 27, 2018

@NahomAgidew For Ubuntu 18.04, it should be

pinentry-program /usr/bin/pinentry-gnome3

As can be seen with

ls -l /usr/bin/ | grep pinentry

But that does not seem to be enough.

P.S. This issue is a dupe of #5065.

@pedzed
Copy link

pedzed commented Aug 27, 2018

Thanks to @DrSensor, run this:

git config --global gpg.program $(which gpg)

@DrSensor
Copy link

DrSensor commented Aug 27, 2018

Glad it helps ☺️

Seems it needs to be added in VSCode documentation. Just like this error, it should pop up a notification when the error gpg: cannot open tty '/dev/tty': No such device or address occur would be a great update for the next release 🙂

@joaomoreno joaomoreno changed the title Support git GPG signing Git: Support GPG signing Sep 18, 2018
@mzabaluev
Copy link

mzabaluev commented Oct 31, 2018

It would be nice if Visual Studio Code itself provided interactive passphrase prompts via the gpg-agent protocol. It's not an issue for a non-sandboxed installation, but it would help in Flatpak and Snap.

@holms
Copy link

holms commented Oct 31, 2018 via email

@mzabaluev
Copy link

I've handled this already. You need to set git to call GPG auth from UI. And then it will work for you.

It does not when the gpg-agent socket is not forwarded into the app container.

@holms
Copy link

holms commented Nov 9, 2018

.Try this config:

holms@debian ~/.aws> cat   ~/.gnupg/gpg-agent.conf 
default-cache-ttl 46000
pinentry-program /usr/bin/pinentry-gtk-2
allow-preset-passphrase

That's when I've got GUI auth window once committing to git from vscode. By default you've got cli auth, and then vscode doesn't nothing, once I've switch to pinentry-gtk-2 it started to work.

Don't forget to install pinentry :)

@plibither8
Copy link

Hi @joaomoreno, any updates regarding this issue? I can't find a conculsive solution anywhere on GitHub or the internet :/

@holms
Copy link

holms commented Apr 5, 2019

@plibither8 you need to gnome for this work or setup pinentry from my comment above

@plibither8
Copy link

@holms, tried that, I'm still getting the following error:
image

@plibither8
Copy link

plibither8 commented Apr 12, 2019

Update: Solved this issue on my machine by configuring git to use gnupg2 instead of the regular gpg. Password is stored in the computer's password manager and I'm able to use VSCode's GUI to commit now.

Reference: https://askubuntu.com/a/805550

@joaomoreno joaomoreno added the help wanted Issues identified as good community contribution opportunities label Oct 9, 2019
@joaomoreno joaomoreno self-assigned this Oct 9, 2019
@rugglcon
Copy link

This doesn't work on MacOS Catalina, the UI doesn't prompt for passphrase.

@bendwyer
Copy link

This doesn't work on MacOS Catalina, the UI doesn't prompt for passphrase.

@rugglcon, the following fixed it for me:

brew install pinentry-mac
echo "pinentry-program /usr/local/bin/pinentry-mac" >> ~/.gnupg/gpg-agent.conf
killall gpg-agent

Now upon your first commit with VS Code, you should be prompted. Granted it's not a native VS Code prompt, but it makes everything work.

Source: https://stackoverflow.com/a/40066889

@rugglcon
Copy link

@bendwyer what I ended up doing (should have came back and updated my comment) was installing the GPG Keychain application for Mac, and they cache your password until your next reboot. So I commit once outside of VSCode to enter my pass phrase, then the rest of my commits I can do from Code.

@sergeyshevch
Copy link

@noce2 Check that you have installed expect package on your WSL system.
@wdhongtw Thanks for the great extension. You solved my problem

@brunovieira97
Copy link

There's a huge gap on functionality that, from my perspective, could be fixed by Code supporting passphrase entry on consoles (and redirecting it to/from a modal in its own UI) for GPG.

Windows GPG has a default pinentry GUI that works just fine with VS Code today, but using that on SSH sessions is impossible on Windows, hanging because summoning a window through SSH is impossible.

I could just switch to pinentry-mode loopback, but doing so makes VS Code hang when trying to commit a file with signing set to true. If Code could just generate a modal input, all of those problems with Code Remote Development would be fixed and local development would work as well.

@viceice
Copy link

viceice commented Feb 3, 2021

My workaround is to add a shell wrapper for the gpg executable to front of PATH on wsl2

#!/bin/sh
exec /mnt/c/Users/kriese/scoop/apps/gpg/current/bin/gpg.exe "$@"

@nv6
Copy link

nv6 commented Mar 1, 2021

Hi @sangeeth96 , I have the same idea, and I just wrote an extension to send passphrase to the gpg-agent.

If you don't mind 3rd party solution, you can give it a try. :D

Works perfectly, thanks 👌🏽

@argtus
Copy link

argtus commented Apr 28, 2021

This doesn't work on MacOS Catalina, the UI doesn't prompt for passphrase.

@rugglcon, the following fixed it for me:

brew install pinentry-mac
echo "pinentry-program /usr/local/bin/pinentry-mac" >> ~/.gnupg/gpg-agent.conf
killall gpg-agent

Now upon your first commit with VS Code, you should be prompted. Granted it's not a native VS Code prompt, but it makes everything work.

Source: https://stackoverflow.com/a/40066889

Thanks, this solution worked. To streamline it a bit and to avoid some copy paste errors you can also do:

echo "pinentry-program $(which pinentry-mac)" >> ~/.gnupg/gpg-agent.conf

@SuperSecureHuman
Copy link

SuperSecureHuman commented Feb 4, 2022

I have the same problem on VS code linux (v1.64)

image

Currently I commit via integrated terminal, and push it via the gui.

Any solutions/workarounds yet?

Thanks!

@telometto
Copy link

I have the same problem on VS code linux (v1.64)

image

Currently I commit via integrated terminal, and push it via the gui.

Any solutions/workarounds yet?

Thanks!

In three days this issue will be four years old; let's celebrate and see if we can get it to at least 10 years!

@deeprobin
Copy link
Author

I have the same problem on VS code linux (v1.64)
image
Currently I commit via integrated terminal, and push it via the gui.
Any solutions/workarounds yet?
Thanks!

In three days this issue will be four years old; let's celebrate and see if we can get it to at least 10 years!

🎉 🎉 🎉

@deeprobin
Copy link
Author

deeprobin commented Feb 13, 2022

Unfortunately, we only find workarounds. And I think you can see that enough people find this issue quite important.

Pushing this issue into the backlog is not good imo. GPG Signing is an essential feature of Git. Even if I am a CLI user, I think this would be especially important for repositories that require GPG signed commits.

Even if it might be cool to let this issue get 10 years old, I hope not.

Maybe someone might look into this and create a pull request that solves this problem (Shouldn't be witchcraft imo - other editors and IDEs get this right).

@joaomoreno I guess this is not realistic with the February 2022 Milestone, but would it be possible to push this issue into the March 2022 Milestone?

@telometto
Copy link

@deeprobin True. My comment was meant as a tongue-in-cheek. As you mentioned, it is pretty essential as a feature to get this working and sort of ridiculous that it hasn't been implemented yet. I don't know how busy the project is, but I'm guessing that it is very busy; especially in regards to it being the most used editor.
That being said, I don't think Microsoft neither lacks the money, nor the manpower, to get this working. I think many people would like to use this as a flatpak if it were fully functioning; I know I would, at least.

@deeprobin
Copy link
Author

@telometto
Exactly. And there are certainly people who are interested who haven't commented under this issue or given it a thumbs up.

At the company I work for, for example, I've noticed that many people don't have a GitHub account because they don't do much programming in their private lives.

@SuperSecureHuman
Copy link

Now I think
How hard is it to implement, when an another 3rd party extension does it perfectly 🤷

https://marketplace.visualstudio.com/items?itemName=wdhongtw.gpg-indicator

Like, is it possible to do something like

if git config says sign commit
invoke what ever that extension does

@deeprobin
Copy link
Author

deeprobin commented Feb 14, 2022

Now I think How hard is it to implement, when an another 3rd party extension does it perfectly 🤷

https://marketplace.visualstudio.com/items?itemName=wdhongtw.gpg-indicator

Like, is it possible to do something like

if git config says sign commit invoke what ever that extension does

Yes I think there is the magic:
https://github.com/wdhongtw/vscode-gpg-indicator/blob/a400f5179420cf16980e7cdb6bb44e44172fcae1/src/indicator/gpg.ts#L76-L93

@wdhongtw Since you created the extension, maybe you feel like creating a pull request?

Maybe using the GPGME Library via FFI interop would be more performant (and generally better) instead of invoking the binary directly 1.
But I think (currently) this is not so bad, since quite a lot of built-in extensions call binaries.

Footnotes

  1. Issue regarding the direct call of binaries

@wdhongtw
Copy link

wdhongtw commented Feb 22, 2022

@deeprobin , would you like to review the PR for my extension wdhongtw/vscode-gpg-indicator#27 ?
I thought this PR is the first step, before that the extension can be robust enough to be merged into VS Code someday.


Althought beening the author of the extension, I thought there are some other possibilities to this issue:

Solution 1: Handle the GPG agnet forwarding for some environment

I create the extension since I found no way to forward GPG agent from Windows to Remove Linux environment (AFAIK).
So I put the GPG key directly in the remote machine, and create a extension to provide passphrase throught the VS Code UI.

But if the agent-forwarding did work at first place, there is no need for the VS Code to handle the passphrase stuffs by itself.

Solution 2: Inject another pinentry program for the VS Code.

For other usecases that the signing key does exist at the remote machine, the only problem is that there is no way (except pinentry-curses, which require GPG_TTY to works properly) for GPG agent to query the passphrase from user.

If the VS Code can inject a special pinentry program for GPG agent, then when the signing process is triggered, the GPG agent can then require VS Code to prompt user for the passphrase. And provides better UX for the commit signing process. (Comparing to my extension, which requres the user to unlock the key before the commit action.)

@deeprobin
Copy link
Author

Now I think How hard is it to implement, when an another 3rd party extension does it perfectly 🤷
https://marketplace.visualstudio.com/items?itemName=wdhongtw.gpg-indicator
Like, is it possible to do something like
if git config says sign commit invoke what ever that extension does

Yes I think there is the magic: https://github.com/wdhongtw/vscode-gpg-indicator/blob/a400f5179420cf16980e7cdb6bb44e44172fcae1/src/indicator/gpg.ts#L76-L93

@wdhongtw Since you created the extension, maybe you feel like creating a pull request?

Maybe using the GPGME Library via FFI interop would be more performant (and generally better) instead of invoking the binary directly 1. But I think (currently) this is not so bad, since quite a lot of built-in extensions call binaries.

Footnotes

1. [Issue regarding the direct call of binaries](https://github.com/microsoft/vscode/issues/142976) [↩](#user-content-fnref-1-82c1147346a49d8e1d50515dbd3905ae)

Pinging some maintainers: @lszomoru @eamodio

@deeprobin
Copy link
Author

@deeprobin , would you like to review the PR for my extension wdhongtw/vscode-gpg-indicator#27 ? I thought this PR is the first step, before that the extension can be robust enough to be merged into VS Code someday.

@wdhongtw

I've added a few comments to your PR. But I must say that I am not an experienced extension developer. I deal more with the underground of Node: V8, ...

@SuperSecureHuman
Copy link

It magically works now. IDK what has changed. Now when I try to commit, I get a popup (Its a kde pop-up thing) that asks my password. Note that I am on i3 window manager, and I am not sure which change I made to the system in past month did this.

@JasonGantner
Copy link

The GPG Indicator Extensio sure is nice but having to unlock the key rather than being prompted the password at each commit kinda defeats the purpose of having it encrypted in the first place.

VSCode already injects an "askpass.sh" program for git password prompting (it's a wrapper for a node.js script). I guess it could be used as a starting point for a pinentry-vscode that would work out-of-the-box for both local and remote gpg signing.

A nice improvement would be a GPG wrapper to get signing to be handled through vscode (be it local or remote) rather than gpg being called directly by git. This would avoid reconfiguring git everywhere or copying sensitive keys to a bunch of locations.

@SuperSecureHuman
Copy link

It magically works now. IDK what has changed. Now when I try to commit, I get a popup (Its a kde pop-up thing) that asks my password. Note that I am on i3 window manager, and I am not sure which change I made to the system in past month did this.

Update:

image

Hope this image explains something :)

@SuperSecureHuman
Copy link

Another update:

I think I found it

image

Installing gtk2 in my arch system, allowed it to have the gui fronted to enter my password.

Hope this helps someone

@SuperSecureHuman
Copy link

Complete steps which I think might solve this issue:

  1. Install one of these packages (https://archlinux.org/packages/core/x86_64/pinentry/)

image

  1. Add this into your bash/zsh/shell rc file

export GPG_TTY=$(tty)

I had to do this to get it working. If I comment, it fails.

  1. Type pin and use tab completion to see the options you have. In my case its

image

  1. I choose to use pinentry-gnome3 from my options. Now type which pinentry-gnome3 to find the binary path.

  2. Create/Edit ~/.gnupg/gpg-agent.conf and add this

pinentry-program /usr/bin/pinentry-gnome3

The /usr/bin path thingy is the one from ur previous step.

image

@ShamoX
Copy link

ShamoX commented Apr 3, 2023

This doesn't work on MacOS Catalina, the UI doesn't prompt for passphrase.

@rugglcon, the following fixed it for me:

brew install pinentry-mac
echo "pinentry-program /usr/local/bin/pinentry-mac" >> ~/.gnupg/gpg-agent.conf
killall gpg-agent

Now upon your first commit with VS Code, you should be prompted. Granted it's not a native VS Code prompt, but it makes everything work.

Source: https://stackoverflow.com/a/40066889

Almost perfect for me.

I have a recent mac, and so pinentry-mac's path was incorrect and there is a better way to restart gpg-agent:

brew install pinentry-mac
brew link --overwrite gnupg # just in case
echo "pinentry-program $(which pinentry-mac)" >> ~/.gnupg/gpg-agent.conf
gpgconf --kill gpg-agent

Source: https://superuser.com/questions/1628782/gpg-signing-failed-no-pinentry

@nboynick
Copy link

I recently came across this issue myself, and while the pinentry-mac solution works for me, I was wondering if it is safe to rely on pinentry-mac considering that the GitHub repository has been archived and the last commit was nine years ago. I do not know how to evaluate such a security risk myself, so I was hoping someone else might be able to chime in.

@ShamoX
Copy link

ShamoX commented Feb 16, 2024

I recently came across this issue myself, and while the pinentry-mac solution works for me, I was wondering if it is safe to rely on pinentry-mac considering that the GitHub repository has been archived and the last commit was nine years ago. I do not know how to evaluate such a security risk myself, so I was hoping someone else might be able to chime in.

Hello,

The pinentry-mac project has been deprecated because macOS interface has been integrated into the main pinentry project.

As you can see in the pinentry-mac formula (line 7), the GitHub used is the one of GPGTools/pinentry.

I guess we can use it safely.

@arijoon
Copy link

arijoon commented Mar 27, 2024

For anyone using WSL Ubuntu the following worked for me:

Install pinentry gtk2: sudo apt-get install pinentry-gtk2
Set it as the pinentry program in ~/.gnupg/gpg-agent.conf

pinentry-program /usr/bin/pinentry-gtk-2

This will result in a graphical pinentry prompt from both vscode and terminal. The downside here is that unfortunately terminal also follows the same pattern. If anyone knows whether its possible to override the pinentry-program option with an env var, let me know please as that would allow us to create a wrapper to switch depending on whether a tty is attached or not. I don't really like this solution (graphic prompt from terminal) but its the most stable solution at the moment for me (on WSL)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality git GIT issues help wanted Issues identified as good community contribution opportunities
Projects
None yet
Development

No branches or pull requests