You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
tty device used inside toolbox gets odd permissions on host causing pinentry/gpg-agent to not work #568
My setup includes running gpg-agent on my host and doing development (git commit, etc) inside my toolbox container. When I git-commit I sign the commits, which means the process talks to the agent that then runs a pinentry program to ask the user for the passphrase.
When running in the terminal I prefer for the passphrase to be asked to me in the terminal window and not in a popup. So I'll unset DISPLAY to force it to use the terminal window. This stopped working sometime in the past few months. I finally tracked down some more information on why.
When running inside toolbox the permissions on my tty device are as expected:
I would expect the owner of the tty to be the user who launched the toolbox container (1001). If I change the ownership to the expected UID then my pinentry program appropriately asks for the passphrase on the same terminal window (inside toolbox) where I am running git commit.
Indeed if I go back to an old machine I haven't updated in a while I can see that the permissions are what I would expect them to be. This out of date machine has:
Thanks for narrowing it down to those working and broken versions.
I wonder if this might be solved by using podman create ... --mount type=devpts,destination=/dev/pts as introduced in podman-container-tools/podman#7209
I don't think Toolbox itself does anything funky with the TTY devices, but it does bind mount the entire /dev from the host into the container. So I wonder if we can reproduce the same with podman run ... ?
Thanks for narrowing it down to those working and broken versions.
No problem :) - It's worth noting those were just two data points. I don't know exactly when the issue was introduced.
I wonder if this might be solved by using podman create ... --mount type=devpts,target=/dev/pts as introduced in containers/podman#7209
Can you recreate locally? I'm assuming pretty much anyone running latest toolbox/podman should see a weird owner when running ls -l on one of the tty devices used for a toolbox session. If you see the problem maybe you can try that in a development version of toolbox?
I don't think Toolbox itself does anything funky with the TTY devices, but it does bind mount the entire /dev from the host into the container. So I wonder if we can reproduce the same with podman run ... ?
Right, I suspect it was a change in podman that caused the regression, just wasn't sure so I reported here first.
Adding --mount type=devpts,destination=/dev/pts to podman create only changes the group ownership of the TTY device inside the container from nobody to tty:
$ ls -l $(tty)
crw--w----. 1 root tty 136, 0 Oct 14 20:07 /dev/pts/0
That seems to be a step in the right direction in terms of matching the TTY device's ownership to that on the host, but I don't know if it solves your problem.
I don't know if you figured it out already, but the strange ownership that you are seeing is related to the use of --userns=keep-id. The 100000 UID on the host is the UID of root inside the container's user namespace, the nobody GID inside the container is due to the host's tty group being absent inside the container.
Right, but what we need is for the owner of the tty device on the host to be the user who started toolbox. For example, to fix this problem right now for me I sudo chown dustymabe /dev/pts/14 on the host.
Before changing the ownership whenever I git commit it will fail because I have it configured to sign commits and pinentry from the gpg-agent running on the host can't access the tty toolbox is using. After correcting the ownership I can type my password in to the pinentry program that pops up in my terminal.
By the way, I submitted #581 for the --mount type=devpts,destination=/dev/pts change. @giuseppe had been asking me to do so for a while, so better late than never.
Right, but what we need is for the owner of the tty device on the host
to be the user who started toolbox. For example, to fix this problem right
now for me I sudo chown dustymabe /dev/pts/14 on the host.
Yes, I understand.
Right now I can think of a (crude?) way to fix this. /usr/bin/toolbox is the entry point of the containers. So, instead of merely sleeping, we can install an inotify watch on /dev/pts and have it do chown <user> every time a new file is created there.
I'm not sure if this can be done inside the container or if it needs to be done as part of container setup (i.e. podman). I can't do the sudo chown dustymabe /dev/pts/14 from inside the container (inside the container you get chown: changing ownership of '/dev/pts/14': Operation not permitted). It has to be from the host.
If you have a new devpts file system mounted on /dev/pts in the container (ie., --mount type=devpts,destination=/dev/pts), then I think you can. :)
Otherwise, the /dev/pts is shared with the host, and the nobody group owner (because the host's tty group is absent inside the container) blocks the chown inside the container.
Right, but what we need is for the owner of the tty device on the host
to be the user who started toolbox. For example, to fix this problem right
now for me I sudo chown dustymabe /dev/pts/14 on the host.
Yes, I understand.
Right now I can think of a (crude?) way to fix this. /usr/bin/toolbox is the
entry point of the containers. So, instead of merely sleeping, we can install
an inotify watch on /dev/pts and have it do chown <user> every time a
new file is created there.
Oh, I am sorry. I am an idiot. :)
You wanted the owner of the (nested pseudo) terminal device on the host to be the user who started toolbox, instead of something funky; and not the owner of the device inside the container, which is what I was rambling about.
Sorry about that.
Note that entering a container (ie., podman exec --tty) creates a nested pseudo-terminal device inside the container's mount and user namespaces, and there's another one that already exists on the host for the terminal tab or window. ie., there are two terminal devices at play.
I think that one consequence of using: podman create --mount type=devpts,destination=/dev/pts
... is that it separates the devices in /dev/pts on the host and the container.
The nested pseudo-terminal device inside the container gets created as root:tty. This isn't visible from the host, and so there's no device with 100000:tty on the host.
The other consequence of that change is that the nested pseudo-terminal device inside the container gets created as root:tty, not root:nobody, which is what's documented in the commit message.
@dustymabe Does this set-up help your gpg-agent and pinentry set-up?
I'm not sure if this can be done inside the container or if it needs to be done
as part of container setup (i.e. podman). I can't do the sudo chown dustymabe /dev/pts/14 from inside the container (inside the
container you get chown: changing ownership of '/dev/pts/14': Operation
not permitted). It has to be from the host.
If you have a new devpts file system mounted on /dev/pts in the container
(ie., --mount type=devpts,destination=/dev/pts), then I think you can. :)
Otherwise, the /dev/pts is shared with the host, and the nobody group
owner (because the host's tty group is absent inside the container) blocks
the chown inside the container.
Except, with a separate devpts file system inside the container, the container and the host can't see each other's devices. So, I don't know where this leaves you, @dustymabe :)
Note that #1016 is about changing the ownership of the nested pseudo-terminal device inside the container to $UID:tty, from the current root:tty.
I spent some time debugging gpg-agent and pinentry with @dustymabe -- it's still broken and the previous workaround of fixing the ownership of the terminal device on the host doesn't work anymore.
It seems to me that the gpg-agent and pinentry processes running on the host, really want access to the secondary end of the nested pseudo-terminal device inside the container's mount and user namespaces (ie., the output of tty(1) or the /dev/pts/N device inside the container). Note how the gpg-agent(1)manual says that the GPG_AGENT environment variable should always reflect the output of tty(1).
That doesn't work at the moment because commit 494007b6cadc5fe3 or #581 mounted a separate devpts file system inside the container's mount and user and namespaces. That made the /dev/pts/N devices inside the container different from those on the host.
Back when @dustymabe originally filed this issue, the containers didn't have their own devpts file system. So, the host could see the nested pseudo-terminal device inside the container's user namespace, but it was owned by a funky user ID. Correcting the ownership meant that gpg-agent and pinentry could use the device.
Now, the host can't even see the device, so there's no ownership to be corrected.
--mount type=devpts,destination=/dev/pts is causing issues in my environment. I suspect my environment is "bad" and should be "unsupported", but perhaps it's related to the problems you're seeing lately in this issue?
I don't have much to contribute here, but i wanted to offer a decent workaround for anyone who, like myself, just wants to sign git commits within a toolbox container, but always ends up hitting:
error: gpg failed to sign the data
fatal: failed to write commit object
Since signing works as long as the gpg-agent was started on the host machine outside of the toolbox, you can just run gpg-agent --daemon before toolbox enter. If you do this often enough, create an alias like: alias tbx='gpg-agent --daemon; toolbox enter [container name]' so you can just run tbx
@heyakyra, I'm not sure that's a sufficient workaround for the problem I experience. My gpg agent is always run from outside of toolbox. The problem I have is that when I'm not on my local system (i.e. I'm SSHing into it) I can't sign commits.
When I am on my local system (i.e. DISPLAY=:0) things are fine because a window popup asks me for my password (doesn't need the terminal tty). When I'm remote (SSH) I need the terminal tty and hit this issue.
ok i'm back here after a few years. Unfortunately I don't have a real solution for the underlying problem which I'll now characterize as:
host gpg-agent can't access tty devices in other devpts namespaces
I think in order to solve that problem the upstream gpg-agent software may need to be modified to understand namespaces such that we could also set GPG_TTY_NAMESPACE or something.
Absent of that solution existing I've come up with a workaround, which is to use the loopback pinentry mode. This just asks for the passphrase in the shell where the action was invoked. It's not fancy, but seems to work.
Unfortunately this can't be controlled by an environment variable, but we can use an alternate wrapper program for gpg and configure git to use that:
#!/usr/bin/bash
# Simply call `gpg` with the same options but with added
# --pinentry-mode loopback. This allows us to bypass the
# use of a pinentry program and just use the calling terminal
# for typing the passphrase. The reason for this is because the
# tty devices inside a toolbox container are under a different
# devpts namespace and the gpg-agent running on the host can't
# access those devices. This is the simplest way to workaround
# the problem. Pair this with gpg.program=/path/to/this/file
# to have git ask for the password in local terminal.
exec gpg --pinentry-mode loopback $@
Another solution that could work but I haven't tested is to use one of the pinentry-tmux alternatives (since I also use tmux):
Activity
debarshiray commentedon Oct 14, 2020
Thanks for narrowing it down to those working and broken versions.
I wonder if this might be solved by using
podman create ... --mount type=devpts,destination=/dev/ptsas introduced in podman-container-tools/podman#7209I don't think Toolbox itself does anything funky with the TTY devices, but it does bind mount the entire
/devfrom the host into the container. So I wonder if we can reproduce the same withpodman run ...?dustymabe commentedon Oct 14, 2020
No problem :) - It's worth noting those were just two data points. I don't know exactly when the issue was introduced.
Can you recreate locally? I'm assuming pretty much anyone running latest toolbox/podman should see a weird owner when running
ls -lon one of thettydevices used for a toolbox session. If you see the problem maybe you can try that in a development version of toolbox?Right, I suspect it was a change in
podmanthat caused the regression, just wasn't sure so I reported here first.debarshiray commentedon Oct 14, 2020
Adding
--mount type=devpts,destination=/dev/ptstopodman createonly changes the group ownership of the TTY device inside the container fromnobodytotty:That seems to be a step in the right direction in terms of matching the TTY device's ownership to that on the host, but I don't know if it solves your problem.
I don't know if you figured it out already, but the strange ownership that you are seeing is related to the use of
--userns=keep-id. The100000UID on the host is the UID ofrootinside the container's user namespace, thenobodyGID inside the container is due to the host'sttygroup being absent inside the container.dustymabe commentedon Oct 14, 2020
Right, but what we need is for the owner of the tty device on the host to be the user who started
toolbox. For example, to fix this problem right now for me Isudo chown dustymabe /dev/pts/14on the host.Before changing the ownership whenever I
git commitit will fail because I have it configured to sign commits and pinentry from the gpg-agent running on the host can't access the tty toolbox is using. After correcting the ownership I can type my password in to the pinentry program that pops up in my terminal.debarshiray commentedon Oct 14, 2020
By the way, I submitted #581 for the
--mount type=devpts,destination=/dev/ptschange. @giuseppe had been asking me to do so for a while, so better late than never.debarshiray commentedon Oct 14, 2020
Yes, I understand.
Right now I can think of a (crude?) way to fix this.
/usr/bin/toolboxis the entry point of the containers. So, instead of merely sleeping, we can install aninotifywatch on/dev/ptsand have it dochown <user>every time a new file is created there.dustymabe commentedon Oct 14, 2020
I'm not sure if this can be done inside the container or if it needs to be done as part of container setup (i.e.
podman). I can't do thesudo chown dustymabe /dev/pts/14from inside the container (inside the container you getchown: changing ownership of '/dev/pts/14': Operation not permitted). It has to be from the host.debarshiray commentedon Oct 14, 2020
If you have a new
devptsfile system mounted on/dev/ptsin the container (ie.,--mount type=devpts,destination=/dev/pts), then I think you can. :)Otherwise, the
/dev/ptsis shared with the host, and thenobodygroup owner (because the host'sttygroup is absent inside the container) blocks thechowninside the container.giuseppe commentedon Oct 27, 2021
what are the permissions in
/dev/pts/?Is the container running with
--mount type=devpts,destination=/dev/pts?giuseppe commentedon Oct 28, 2021
that seems correct. If I understand correctly though, you would like it to be owned by your ID?
I've opened a PR for Podman to allow passing down more options like uid= and gid=: podman-container-tools/podman#12124
so you'll be abe to do something like
--mount type=devpts,destination=/dev/pts,uid=$UID,gid=$UID1 remaining item
giuseppe commentedon Oct 28, 2021
/dev:/devwill bind mount/dev/ptsfrom the host as well, that could make a difference.I don't think it is correct though, could you give a try to the patch I've proposed for Podman?
volumes: allow more options for devpts
debarshiray commentedon Mar 2, 2023
Revisiting this one after a long time ...
Oh, I am sorry. I am an idiot. :)
You wanted the owner of the (nested pseudo) terminal device on the host to be the user who started
toolbox, instead of something funky; and not the owner of the device inside the container, which is what I was rambling about.Sorry about that.
Note that entering a container (ie.,
podman exec --tty) creates a nested pseudo-terminal device inside the container's mount and user namespaces, and there's another one that already exists on the host for the terminal tab or window. ie., there are two terminal devices at play.I think that one consequence of using:
podman create --mount type=devpts,destination=/dev/pts(which is commit 494007b6cadc5fe3 or #581)
... is that it separates the devices in
/dev/ptson the host and the container.The nested pseudo-terminal device inside the container gets created as
root:tty. This isn't visible from the host, and so there's no device with100000:ttyon the host.The other consequence of that change is that the nested pseudo-terminal device inside the container gets created as
root:tty, notroot:nobody, which is what's documented in the commit message.@dustymabe Does this set-up help your
gpg-agentandpinentryset-up?Except, with a separate
devptsfile system inside the container, the container and the host can't see each other's devices. So, I don't know where this leaves you, @dustymabe :)Note that #1016 is about changing the ownership of the nested pseudo-terminal device inside the container to
$UID:tty, from the currentroot:tty.debarshiray commentedon Mar 2, 2023
You can check if your container was created with:
... by looking at
CreateCommandin thepodman inspect --type container ...output.debarshiray commentedon Mar 6, 2023
I spent some time debugging
gpg-agentandpinentrywith @dustymabe -- it's still broken and the previous workaround of fixing the ownership of the terminal device on the host doesn't work anymore.It seems to me that the
gpg-agentandpinentryprocesses running on the host, really want access to the secondary end of the nested pseudo-terminal device inside the container's mount and user namespaces (ie., the output oftty(1)or the/dev/pts/Ndevice inside the container). Note how thegpg-agent(1)manual says that theGPG_AGENTenvironment variable should always reflect the output oftty(1).That doesn't work at the moment because commit 494007b6cadc5fe3 or #581 mounted a separate
devptsfile system inside the container's mount and user and namespaces. That made the/dev/pts/Ndevices inside the container different from those on the host.Back when @dustymabe originally filed this issue, the containers didn't have their own
devptsfile system. So, the host could see the nested pseudo-terminal device inside the container's user namespace, but it was owned by a funky user ID. Correcting the ownership meant thatgpg-agentandpinentrycould use the device.Now, the host can't even see the device, so there's no ownership to be corrected.
debarshiray commentedon Mar 6, 2023
I filed containers/crun#1158 for some clarifications and advice.
alexpdp7 commentedon Apr 4, 2023
Sorry to intrude, but this seems related to a problem I'm having running distrobox/containerbox nested inside an LXC container, see:
--mount type=devpts,destination=/dev/ptsis causing issues in my environment. I suspect my environment is "bad" and should be "unsupported", but perhaps it's related to the problems you're seeing lately in this issue?heyakyra commentedon Apr 18, 2023
I don't have much to contribute here, but i wanted to offer a decent workaround for anyone who, like myself, just wants to sign git commits within a
toolboxcontainer, but always ends up hitting:and having to run
gpgconf --kill gpg-agentand exiting the toolbox container to try again.Since signing works as long as the
gpg-agentwas started on the host machine outside of the toolbox, you can just rungpg-agent --daemonbeforetoolbox enter. If you do this often enough, create an alias like:alias tbx='gpg-agent --daemon; toolbox enter [container name]'so you can just runtbxdustymabe commentedon Apr 18, 2023
@heyakyra, I'm not sure that's a sufficient workaround for the problem I experience. My gpg agent is always run from outside of
toolbox. The problem I have is that when I'm not on my local system (i.e. I'm SSHing into it) I can't sign commits.When I am on my local system (i.e.
DISPLAY=:0) things are fine because a window popup asks me for my password (doesn't need the terminal tty). When I'm remote (SSH) I need the terminal tty and hit this issue.losuler commentedon Jun 14, 2023
I have no idea why this workaround works, but if you run this a few times in quick succession from within the toolbox (never works if just ran once):
Then for some reason the popup window in GNOME will start working, and I can put in my password for my GPG key I use to sign my git commits.
dustymabe commentedon Feb 13, 2026
ok i'm back here after a few years. Unfortunately I don't have a real solution for the underlying problem which I'll now characterize as:
I think in order to solve that problem the upstream
gpg-agentsoftware may need to be modified to understand namespaces such that we could also setGPG_TTY_NAMESPACEor something.Absent of that solution existing I've come up with a workaround, which is to use the
loopbackpinentry mode. This just asks for the passphrase in the shell where the action was invoked. It's not fancy, but seems to work.Unfortunately this can't be controlled by an environment variable, but we can use an alternate wrapper program for gpg and configure git to use that:
EDIT: credit for inspiration from https://betakuang.medium.com/using-command-line-passphrase-input-for-gpg-with-git-for-windows-f78ae2c7cd2e
Another solution that could work but I haven't tested is to use one of the pinentry-tmux alternatives (since I also use tmux):