Skip to content

GPG Sign Commit when running in DevContainer #72

Closed

Description

  • VSCode Version: 1.34.0-insider
  • Local OS Version: Win 10 1903 64bit
  • Remote OS Version: 4.9.125-linuxkit [python:3.6 base image]
  • Remote Extension/Connection Type: Docker

Steps to Reproduce:

  1. Configure git to gpg sign commits [global .gitconfig locally]
[commit]
	gpgsign = true
  1. Start project in dev container, try to commit
root@953bed01abcd:/workspaces/my-project# git commit -m dockerize
error: gpg failed to sign the data
fatal: failed to write commit object

Does this issue occur when you try this locally?: No
Does this issue occur when you try this locally and all extensions are disabled?: No

Activity

  1. added
    containers
    feature-request
    on May 3, 2019
  2. jrobsonchase commented on May 4, 2019

    @jrobsonchase

    I've managed to get this to work by using -v to map my local gpg agent socket into the container, likewise with the ssh agent:

    "-v", "${env:HOME}/.gnupg/pubring.kbx:/root/.gnupg/pubring.kbx",
    "-v", "${env:HOME}/.gnupg/trustdb.gpg:/root/.gnupg/trustdb.gpg",
    // You'll probably have to change this to point to your gpg-agent socket.
    // Not sure where Mac/Windows put it.
    "-v", "${env:XDG_RUNTIME_DIR}/gnupg/S.gpg-agent:/root/.gnupg/S.gpg-agent",
    "-v", "${env:SSH_AUTH_SOCK}:${env:SSH_AUTH_SOCK}",
    "-e", "SSH_AUTH_SOCK=${env:SSH_AUTH_SOCK}"

    Not ideal, but it's a decent workaround and allows for signing commits in the container and fetching dependencies in private git repositories via ssh.

  3. smiller171 commented on Jun 5, 2019

    @smiller171

    Josh Robson Chase (@jrobsonchase) unfortunately there are numerous problems with this if you're running on a Mac or Windows host.

    I think it makes sense to allow git operations to run locally when using remote containers to avoid this issue, possibly hidden behind a flag.

  4. heberleh commented on Jun 8, 2019

    @heberleh

    I have similar or same problem. I am using git on code-insiders bash with WSL as remote. What is strange is that sometimes it is working, and it stops working, or it is not working and then after some minutes it works.

    I noticed that restarting code-insiders seems to make it work, but not always. I have no idea how to solve, I have tried the normal solutions for the messages "error: gpg failed to sign the data
    fatal: failed to write commit object" that I found on the web. Nothing seems to work permanently.

  5. silenceisgolden commented on Jun 14, 2019

    @silenceisgolden

    Same issue if using Ubuntu WSL. I found a workaround using this repository but there is not a published, peer-reviewed package since the issue is fairly new.

    https://github.com/diablodale/pinentry-wsl-ps1

  6. jletey commented on Jul 22, 2019

    @jletey

    I'm not quite sure if this is the right place to ask this, but what's the best way to use your GPG key from your computer on your Raspberry Pi to sign commits. Do you transfer the key? Do you create a new one?

  7. LaysDragon commented on Sep 13, 2019

    @LaysDragon

    I've managed to get this to work by using -v to map my local gpg agent socket into the container, likewise with the ssh agent:

    "-v", "${env:HOME}/.gnupg/pubring.kbx:/root/.gnupg/pubring.kbx",
    "-v", "${env:HOME}/.gnupg/trustdb.gpg:/root/.gnupg/trustdb.gpg",
    // You'll probably have to change this to point to your gpg-agent socket.
    // Not sure where Mac/Windows put it.
    "-v", "${env:XDG_RUNTIME_DIR}/gnupg/S.gpg-agent:/root/.gnupg/S.gpg-agent",
    "-v", "${env:SSH_AUTH_SOCK}:${env:SSH_AUTH_SOCK}",
    "-e", "SSH_AUTH_SOCK=${env:SSH_AUTH_SOCK}"

    Not ideal, but it's a decent workaround and allows for signing commits in the container and fetching dependencies in private git repositories via ssh.

    For windows host, according to https://zhuanlan.zhihu.com/p/31802760 (Chinese)
    Gpg4win implement a tcp socket to simulation the behavior of Unix Socket.
    We can use socat to forward the tcp connection to unix socket.
    Based on this tutorial, I tried to make scripts and config for Dev Container Version and it working.

    {
    	"name":"...",
    	"dockerFile":"...", 
    	"appPort": ["..."],
    	"runArgs": [
    		"-v", "${env:APPDATA}/gnupg/pubring.kbx:/home/vscode/.gnupg/pubring.kbx",
    		"-v", "${env:APPDATA}/gnupg/trustdb.gpg:/home/vscode/.gnupg/trustdb.gpg",
    		"-v", "${env:APPDATA}/gnupg/S.gpg-agent.extra:/home/vscode/.gnupg-localhost/S.gpg-agent.extra:ro"
    	]
    
    }

    Then add script into .bashrc to launch the forwarding socat in background.

    export GPG_TTY=$(tty)
    if [ -f "$HOME/.gnupg-localhost/S.gpg-agent.extra" ] && [ ! -S "$HOME/.gnupg/S.gpg-agent" ];then
    	GPG_AGENT="$HOME/.gnupg-localhost/S.gpg-agent.extra"
    	PREPEND_FILE="/tmp/gpg_agent_prepend"
    	WINDOWS_GPG_AGENT_PORT=$(head -n1 "$GPG_AGENT")
    	tail -n+2 "$GPG_AGENT" > "$PREPEND_FILE"
    	mkdir -p "$HOME/.gnupg/"
    	socat "UNIX-LISTEN:$HOME/.gnupg/S.gpg-agent,fork" "SYSTEM:cat \"$PREPEND_FILE\" - <&3 | socat STDIO \"TCP\:host.docker.internal\:$WINDOWS_GPG_AGENT_PORT\" >&4,fdin=3,fdout=4" &
    fi
    

    For me I launch a script in postCreateCommand to insert it automatic.

    # https://github.com/keybase/keybase-issues/issues/2798 fix gpg Inappropriate ioctl for device problem
    echo "export GPG_TTY=\$(tty)" >> ~/.bashrc
    cat >> ~/.bashrc <<EOL
    if [ -f "\$HOME/.gnupg-localhost/S.gpg-agent.extra" ] && [ ! -S "\$HOME/.gnupg/S.gpg-agent" ];then
    	GPG_AGENT="\$HOME/.gnupg-localhost/S.gpg-agent.extra"
    	PREPEND_FILE="/tmp/gpg_agent_prepend"
    	WINDOWS_GPG_AGENT_PORT=\$(head -n1 "\$GPG_AGENT")
    	tail -n+2 "\$GPG_AGENT" > "\$PREPEND_FILE"
    	mkdir -p "\$HOME/.gnupg/"
    	socat "UNIX-LISTEN:\$HOME/.gnupg/S.gpg-agent,fork" "SYSTEM:cat \"\$PREPEND_FILE\" - <&3 | socat STDIO \"TCP\:host.docker.internal\:\$WINDOWS_GPG_AGENT_PORT\" >&4,fdin=3,fdout=4" &
    fi
    EOL
    

    But I don't why nohup & won't working properly in .bashrc,while I press multitime ctrl+c or simply exit the terminal .the socat background process will exit too. But if I run it manually it won't behavior like this. I need to find a better way to let a socat run in background while container startup.

    vscode@2274dfd714b1:/$ 
    vscode@2274dfd714b1:/$ 
    vscode@2274dfd714b1:/$ 
    vscode@2274dfd714b1:/$ ^C
    vscode@2274dfd714b1:/$ ^C
    [1]+  Exit 130                nohup socat "UNIX-LISTEN:$HOME/.gnupg/S.gpg-agent,fork" "SYSTEM:cat \"$PREPEND_FILE\" - <&3 | socat STDIO \"TCP\:host.docker.internal\:$WINDOWS_GPG_AGENT_PORT\" >&4,fdin=3,fdout=4"  (wd: /workspaces/virtual-patient-room-amazing)
    (wd now: /)
    vscode@2274dfd714b1:/$ ^C
    vscode@2274dfd714b1:/$ 
    
  8. vovimayhem commented on Apr 23, 2020

    @vovimayhem

    I'm really interested on any updates on this.

    Does anyone has been successful in signing Git commits within the dev container?

  9. added
    plan-item
    and removed
    feature-request
    on May 12, 2020
  10. chrmarti commented on May 18, 2020

    @chrmarti
    Contributor

    Got it implemented by copying pubring.kbx and trustdb.gpg into the container and then forwarding the agent socket in the container to the extra ('remote') socket on the local machine. This will need some testing in the wild to confirm it works as expected.

  11. ItalyPaleAle commented on May 18, 2020

    @ItalyPaleAle

    Christof Marti (@chrmarti) Do you mind sharing a code sample? Also, rather than copying the keyring (which is a manual operation), could we mount the GPG folder in the container instead?

  12. airtonix commented on May 19, 2020

    @airtonix

    Got it implemented by copying pubring.kbx and trustdb.gpg into the container and then forwarding the agent socket in the container to the extra ('remote') socket on the local machine. This will need some testing in the wild to confirm it works as expected.

    Prove it.

    show us a gif of it working on windows using docker-desktop for windows and vscode-remote connecting to a linux container.

    until then this isn't solved.

  13. chrmarti commented on May 19, 2020

    @chrmarti
    Contributor

    Alessandro (Ale) Segala (@ItalyPaleAle) You can still mount the GPG folder (or the individual files) if you prefer. The implementation checks if the files exist before writing them.

    Zeno Jiricek (@airtonix) This will be in the next version of the Remote-Containers extension. I have closed this issue for my own book-keeping.

  14. ItalyPaleAle commented on May 19, 2020

    @ItalyPaleAle

    Christof Marti (@chrmarti) Apologies, but I'm a bit confused... Did you fix this already? Does it work on the current version, or do we need to wait for the next version? Will there be some docs explaining how to do this?

  15. chrmarti commented on May 19, 2020

    @chrmarti
    Contributor

    Alessandro (Ale) Segala (@ItalyPaleAle) It will be available with the next version. It should work out-of-the-box and we will add documentation as needed.

  16. LaysDragon commented on May 20, 2020

    @LaysDragon

    It really tricky to setup to forward agent connection especially between windows and container myself,I almost forget how I done this before...Even though it can work but it still not that convenience ,and I give up to use container develop at the end years ago.
    But I'm still excited to know that this feature is going to become build-in feature :D

  17. chrmarti commented on May 26, 2020

    @chrmarti
    Contributor

    This is available in the latest version of Remote-Containers (0.118.0). You will need VS Code Insiders to get that version at the moment. Make sure to have gpg installed locally and in the container (update the Dockerfile if needed).

    Let me know if it works and open bug reports if it does not! 👍

  18. changed the title [-]Unable to GPG Sign Commit when running in Dev Container[/-] [+]GPG Sign Commit when running in Dev Container[/+] on May 26, 2020
  19. changed the title [-]GPG Sign Commit when running in Dev Container[/-] [+]GPG Sign Commit when running in DevContainer[/+] on May 26, 2020
  20. jtokoph commented on May 26, 2020

    @jtokoph

    Was super excited to try this out today Christof Marti (@chrmarti)! Currently seeing an issue with older versions of gpg2. Opened an issue here: #3048. In the meantime I'm working on getting my dev container setup with the latest gpg2.

  21. airtonix commented on May 28, 2020

    @airtonix

    It should work out-of-the-box and we will add documentation as needed.

    It doesn't. Documentation required.

    Christof Marti (@chrmarti) I think you've implmented something that assumes we want this feature turned on all the time...

    so now this explodes our local docker environments.

  22. chrmarti commented on Jun 2, 2020

    @chrmarti
    Contributor

    Zeno Jiricek (@airtonix) Let's try to make it work first. Could you open a new issue with details on what is not working?

  23. locked and limited conversation to collaborators on Jul 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

containersplan-item

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions