SSH_AUTH_SOCK environment variable not available to Rex
Nobody has claimed this yet.
- Dominant language
- Perl
- Stars
- 737
- Forks
- 214
- PR merge metrics
- No merged PRs in 30d
Description
Describe the bug
I ran into a bug where SSH ForwardAgent was enabled for a server, and I could run from the command-line
ssh -A server "cd /dir && git pull origin main"
but when running that git command in Rex (including using the SCM checkout function) did not work, and received a "Permission denied (public key)" error. See https://groups.google.com/g/rex-users/c/5FavxuXgeb0
The problem was caused by the .ssh/config having a Hostname parameter for the server that specified the IP address. Removing the Hostname fixed the issue.
Upon further investigation, I created a Rex task
task "PrintEnv" => sub {
my $out = run "printenv";
say $out if $out;
}
and compared using rex -H server PrintEnv with ssh -A server printenv
A notable difference is that the SSH_AUTH_SOCK environment variable was not set when run through Rex.
When removing the Hostname and re-running the Rex task, SSH_AUTH_SOCK was present. (This seems to have nothing to do with the .ssh/known_hosts although removing it the first time prompts SSH to accept the host fingerprint.)
Expected behavior
Git and other tools being run through Rex would have had their authentication forwarded.
How to reproduce it
For a .ssh/config of a particular server
- Include a
Hostnamewith the IP address of the server - Ensure
ForwardAgentis "yes" for the server - Run a Rex command on the server that requires forwarded authentication, e.g.
git pull
Code example
No response
Additional context
No response
Rex version
1.14.3
Perl version
5.34.0
Operating system running rex
Linux (Ubuntu 22.04.1)
Operating system managed by rex
Linux (Ubuntu 18.04.6, Debian 6.1.85-1)
How rex was installed?
cpan client
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue with an SSH config entry that sets Hostname to the server IP and ForwardAgent to yes, then compare rex -H server PrintEnv with ssh -A server printenv. Trace Rex's SSH connection and remote environment handling; done means SSH_AUTH_SOCK is available through Rex and a remote git pull succeeds with forwarded authentication.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- git, perl
- Domain
- devops, infrastructure
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100