Skip to content

Conversation

@anshulsharma-hashicorp
Copy link
Contributor

@anshulsharma-hashicorp anshulsharma-hashicorp commented Mar 22, 2025

Issue: hashicorp/packer#3670

I am adding the changes to handle the ssh-agent forwarding in windows, before this changes the packer code would always go and check the SSH_AUTH_SOCK environment variable for socket file, which is the behavior in linux but in windows a named static files gets used for this purpose, so have added changes for the same.

This was reported by multiple users for reference i have added the github issue link above.

Tests:
Have added the Unit Test cases for the new changes.

Closes hashicorp/packer#3670

@anshulsharma-hashicorp anshulsharma-hashicorp requested a review from a team as a code owner March 22, 2025 09:58
@hashicorp-cla-app
Copy link

hashicorp-cla-app bot commented Mar 22, 2025

CLA assistant check
All committers have signed the CLA.

@hashicorp-cla-app
Copy link

CLA assistant check

Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement

Learn more about why HashiCorp requires a CLA and what the CLA includes

Have you signed the CLA already but the status is still pending? Recheck it.

Copy link
Contributor

@JenGoldstrich JenGoldstrich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this change @anshulsharma-hashicorp, I think it's looking good, although I do wonder if handling the inclusion of this logic using a go:build directive is best, I would defer to @lbajolet-hashicorp's opinions for code style there though.

Can you provide me some more context on where that Windows pipe path comes from, and can you also sign the CLA agreement

)

func GetSSHAgentConnection() (net.Conn, error) {
pipePath := "\\\\.\\pipe\\openssh-ssh-agent"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does this pipe path come from?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a static named pipe in windows, which holds the ssh private key for ssh-agent forwarding.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we declare this pipe name as constant on top of the file? It would give that some context as to a magic string.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, it gives me a bit of pause that this is jsut a magic string, Lucas and I did some digging in docs and couldn't find any direct reference to this, only like stack overflow pages, so I worry that someone else reading this code in the future wouldn't have any context on what this is, I think making it a constant + adding a comment would be wise here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion i have done this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kp2099
Copy link
Contributor

kp2099 commented Mar 28, 2025

The change looks harmless to me, although i don't have enough expertise on windows named pipes.

Copy link
Contributor

@anurag5sh anurag5sh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good to me. Additionally we could add any reference to the named pipe path in windows if any.

JenGoldstrich
JenGoldstrich previously approved these changes Apr 17, 2025
Copy link
Contributor

@JenGoldstrich JenGoldstrich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you for this contribution @anshulsharma-hashicorp I know you've put a lot of work into this, you did a good job understanding the full SSH stack here, and helping improve my knowledge. 🚀 Ship it!

@lbajolet-hashicorp lbajolet-hashicorp dismissed stale reviews from JenGoldstrich and themself via f5e4d4c April 17, 2025 14:39
@lbajolet-hashicorp lbajolet-hashicorp merged commit 6c61dc4 into main Apr 17, 2025
17 checks passed
@lbajolet-hashicorp lbajolet-hashicorp deleted the win-sshagent-fwd branch April 17, 2025 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SSH agent forwarding not working on Windows

5 participants