Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: Add SSH agent forwarding support to coder agent#1548

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
mafredri merged 11 commits intomainfrommafredri/ssh-agent-forwarding
May 25, 2022

Conversation

mafredri
Copy link
Member

@mafredrimafredri commentedMay 18, 2022
edited
Loading

This PR adds support for SSH agent forwarding.

This simple change can support SSH agent forwarding but requires extra steps:

As Kyle pointed out, this works fine with thecoder gitssh command so the extra steps are not necessary, we only need to make sure thesshForwardAgent setting is enabled:

coder config-sshssh -o ForwardAgent=yes coder.mydev# Inside workspace:git clone git@github.com:private/repo.git

Checklist

  • Add basic forward agent support
  • Add support for using the forwarded agent toGIT_SSH_COMMAND (i.e.coder gitssh)?
  • Add forward agent support tocoder ssh too

Fixes#1549.

kconley-sq reacted with thumbs up emoji
@mafredrimafredri self-assigned thisMay 18, 2022
@mafredri
Copy link
MemberAuthor

Wanted this to be DRAFT PR, can't seem to convert it after the fact.

@kylecarbs
Copy link
Member

I'm surprised it doesn'tjust work withgitssh. Since we're setting theSSH_AUTH_SOCK, I assumed it'd get passed through to thessh commandgitssh executes.

@mafredri
Copy link
MemberAuthor

I'm surprised it doesn'tjust work withgitssh. Since we're setting theSSH_AUTH_SOCK, I assumed it'd get passed through to thessh commandgitssh executes.

Oh you're absolutely right, silly me, I did not look closely at what the actual error output was.

run ssh command: exec: "ssh": executable file not found in $PATH

So yeah, withssh installed it works perfectly! 😄

@kylecarbs
Copy link
Member

Ahh, nice! Forwarding withcoder ssh shouldjust be forwardingSSH_AUTH_SOCK if any is set:

https://pkg.go.dev/golang.org/x/crypto/ssh/agent#ForwardToRemote

mafredri reacted with thumbs up emoji

@mafredrimafredriforce-pushed themafredri/ssh-agent-forwarding branch fromc0a7d75 to3df1a08CompareMay 24, 2022 10:10
@mafredrimafredri requested review fromkylecarbs anda teamMay 24, 2022 16:45
@mafredri
Copy link
MemberAuthor

I believe this is now ready for review. SSH agent forwarding has now been implemented for bothcoder ssh andssh.

Forcoder:

coder ssh --forward-agent<workspace>

For SSH:

coder config-ssh -o ForwardAgent=yes# orssh -o ForwardAgent=yes coder.<workspace>

Thanks@kylecarbs for the pointers, this was surprisingly easy to setup.

kylecarbs reacted with hooray emoji

@kylecarbs
Copy link
Member

@mafredri that'd be a good example for the usage ofconfig-ssh!

mafredri reacted with heart emoji

cli/ssh.go Outdated
_ = cmd.Flags().MarkHidden("shuffle")
cliflag.BoolVarP(cmd.Flags(), &forwardAgent, "forward-agent", "", "CODER_SSH_FORWARD_AGENT", false, "Specifies whether to forward the SSH agent specified in $SSH_AUTH_SOCK")
Copy link
Member

Choose a reason for hiding this comment

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

The shorthand flag for this should be-A to match openssh

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

A most excellent suggestion, thanks!

for {
fd, err := l.Accept()
if err != nil {
t.Logf("accept error: %v", err)
Copy link
Member

Choose a reason for hiding this comment

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

ignore closed errors

mafredri reacted with thumbs up emoji
@mafredri
Copy link
MemberAuthor

@kylecarbs great suggestion! Added.

Comment on lines +265 to 267
t.Cleanup(func() {
<-doneC
})
Copy link
Member

Choose a reason for hiding this comment

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

note: I wasn't sure of this so I had to remind myself -- reading from a closed channel will immediately return the zero value of the channel type, and not block.

https://go.dev/play/p/PIS5JU1Lbgz

So this is fine, this won't causet.Cleanup to hang or anything.

// And we're done.
pty.WriteLine("exit")
<-cmdDone
})
Copy link
Member

Choose a reason for hiding this comment

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

praise: This is such a cool test.

mafredri reacted with heart emojidwahler reacted with eyes emoji
//nolint:paralleltest // Disabled due to use of t.Setenv.
t.Run("ForwardAgent", func(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("Test not supported on windows")
Copy link
Member

Choose a reason for hiding this comment

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

remark, non-blocking: recent versions of Windows do include SSH (source) but it's probably a ghastly can of worms to open! So agreed, let's leave this non-Windows for now. 😅

mafredri reacted with laugh emoji
Co-authored-by: Cian Johnston <cian@coder.com>
@mafredrimafredri merged commit527f1f3 intomainMay 25, 2022
@mafredrimafredri deleted the mafredri/ssh-agent-forwarding branchMay 25, 2022 18:28
kylecarbs pushed a commit that referenced this pull requestJun 10, 2022
* feat: Add SSH agent forwarding support to coder agent* feat: Add forward agent flag to `coder ssh`* refactor: Share setup between SSH tests, sync goroutines* feat: Add test for `coder ssh --forward-agent`* fix: Fix test flakes and implement Deans suggestion for helpers* fix: Add example to config-ssh* fix: Allow forwarding agent via -ACo-authored-by: Cian Johnston <cian@coder.com>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@johnstcnjohnstcnjohnstcn approved these changes

@kylecarbskylecarbskylecarbs approved these changes

@deansheatherdeansheatherdeansheather approved these changes

Assignees

@mafredrimafredri

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Feat: Add support for SSH agent forwarding
4 participants
@mafredri@kylecarbs@johnstcn@deansheather

[8]ページ先頭

©2009-2025 Movatter.jp