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

Ssh-agent stops to work after a while. #862

Open
alekspickle opened this issue Nov 11, 2021 · 8 comments
Open

Ssh-agent stops to work after a while. #862

alekspickle opened this issue Nov 11, 2021 · 8 comments

Comments

@alekspickle
Copy link
Contributor

alekspickle commented Nov 11, 2021

Thank you for taking the time to file this issue! Please follow the instructions and fill in the missing parts below the instructions, if it is meaningful. Try to be brief and concise.
Basic information

zellij --version: zellij 0.20.0
tput lines: 58
tput cols: 123
uname -av or ver(Windows): Linux pickle 5.11.0-37-generic #41~20.04.2-Ubuntu SMP Fri Sep 24 09:06:38 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

List of programs you interact with as, PROGRAM --version: output cropped meaningful, for example:
cargo 1.56.0 (4ed5d137b 2021-10-04)
rustc 1.56.0 (09c42c458 2021-10-18)
git version 2.33.0
zsh 5.8 (x86_64-ubuntu-linux-gnu)

Further information
I tried to use zellijj on a remote server which is used with ssh agent forwarding.
ssh-add
zellij -s session_name options --disable-mouse-mode
Then go to my git repo and start working.
And after a random period of time the agent just stops to pass a key or something else happening, because I cannot reach a remote upstream in any way.

│❯ git push                                                                                                                 │
│fatal: The current branch main has no upstream branch.                                               │
│To push the current branch and set the remote as upstream, use                                                             │
│                                                                                                                           │
│    git push --set-upstream origin main                                                              │
│                                                                                                                           │
│ERROR: command 'git push' failed with the code 128. Retrying 15 time(s) in 3 sec...


Once I end zellij session, go to the repo and do something with remote(it works) and open new session it works again for some time.

@imsnif
Copy link
Member

imsnif commented Nov 11, 2021

Hrm - can you try with 0.20.1? We had some input issues that might be related.

@alekspickle
Copy link
Contributor Author

alekspickle commented Nov 11, 2021

Woah. The reason is very stupid from my side. 🤦‍♂️
If you have created a local branch lets say hummus and try to push it to upstream with git push it will show what I wrote above and stuck in retry loop. But if you specify -u origin hummus its will pass through.

This is more of a zsh issue, I switched it recently and don't know all yet...
Srry to bother!

@imsnif
Copy link
Member

imsnif commented Nov 11, 2021

wth - that's super weird! No worries at all :) I do recommend upgrading to 0.20.1 regardless. 0.20.0 is a little broken

@alekspickle
Copy link
Contributor Author

alekspickle commented Nov 16, 2021

Well, this is still happening but I'd rather do some research and gather some specifics and open new issue with all the details.
Maybe I could come up with a PR?..

@imsnif
Copy link
Member

imsnif commented Nov 16, 2021

Sure - this is super weird. I am not aware of Zellij doing anything that might be related to this... could it be an environment thing? Some shell stuff that happens on startup that somehow is skipped inside Zellij for you, or?

@alekspickle
Copy link
Contributor Author

well all I do is start run ssh-add after login and connect to a remote. There I attach to a zellij session.
If I just go to repo and pull it will pull because SSH-agent is forwarding key, but inside the session it prompts git permission warning

@ga289395
Copy link

Did some digging and this is happening because of the details of how ssh forwarding/ssh agent work. SSH forwarding uses the value of the $SSH_AUTH_SOCK environment variable which points to a unix domain socket which is created per SSH session to communicate with the ssh-agent. If you were kicked out of the session or you exited the ssh session yourself, re-attaching to a zellij session will cause errors in contacting your ssh-agent because the old value of $SSH_AUTH_SOCK is still being used inside of the session even though a new socket file was created for the session to contact the ssh-agent.

There is a solution which you can apply to fix this problem without changing anything on the zellij side:

On the remote, make the following modifications:
~/.ssh/rc

if test "$SSH_AUTH_SOCK"; then
	ln -sf $SSH_AUTH_SOCK ~/.ssh/ssh_auth_sock
fi

~/.bashrc (or the rc file for whatever is your default shell on the remote)

export SSH_AUTH_SOCK="$HOME/.ssh/ssh_auth_sock"

You can fix an existing session by running source ~/.bashrc inside each terminal pane you want to fix.

A better fix than hardcoding a value like that in your bashrc would require support from zellij. If zellij supported capturing the client environment variables at attach time and a mechanism to update the zellij environment on attach based on those values, you could keep zellij sessions up to date with env vars that change like that one (or even if you made .bashrc changes and you want to propagate that to a live session).

The tmux way of doing this would be:

set -g update-environment -r

in your tmux.conf file and that would update the env vars per attach.

@imsnif
Copy link
Member

imsnif commented Nov 23, 2021

Hey @ga289395 - thank you very much for the detailed investigation and for helping us find the root cause of this issue!

I think having these abilities in Zellij would make things much easier. So I'm going to re-open this issue and put a Help Wanted on it. Just to re-iterate what needs to be done (and please correct me if I'm wrong):

  1. We would provide a new flag on attach - something like the tmux update-environment that would override the existing environment variables in the Zellij sessions with the ones on the client
  2. Optionally, we should also provide this ability at run time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants