Skip to content

fix(agent/agentssh): allow remote forwarding a socket multiple times #11631

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

Merged
merged 5 commits into from
Jan 16, 2024

Conversation

mafredri
Copy link
Member

@mafredri mafredri commented Jan 16, 2024

Fixes #11198
Fixes https://github.com/coder/customers/issues/407

For this PR, I implemented a new test in cli/ssh_test.go, however, in future, we should consider doing more extensive testing for forwarding within the agent/agentssh package.

@mafredri mafredri force-pushed the mafredri/fix-socket-re-forward branch from 5ce1baf to 96c0724 Compare January 16, 2024 10:03
@mafredri mafredri force-pushed the mafredri/fix-socket-re-forward branch from 96c0724 to dab6034 Compare January 16, 2024 10:06
@mafredri mafredri marked this pull request as ready for review January 16, 2024 10:14
// Ensure the SSH connection is ready by testing the shell
// input/output.
pty.WriteLine("echo ping' 'pong")
pty.ExpectMatchContext(ctx, "ping pong")
Copy link
Contributor

Choose a reason for hiding this comment

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

using the CLI to test the agent is awkward and this is an example. This test would be easier to write and easier to understand if were in agent_test.go and we could use the go ssh client.

Copy link
Member Author

Choose a reason for hiding this comment

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

I do somewhat agree, but I'm not sure agent_test.go is a much better place since the actual forwarding is implemented here, in cli/remoteforward.go. This test should ensure that the behavior we want works with the actual coder ssh client.

Copy link
Contributor

Choose a reason for hiding this comment

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

We already have tests for coder ssh in terms of making a unix socket remote forward and verifying it works. None of that behavior is changing in this PR.

What's changing is on the agent side of the connection. And it's not just coder ssh that talks to that SSH server: it could be OpenSSH or JetBrains Gateway or VSCode (via coder ssh --stdio), or even a custom SSH client written in go using codersdk. Therefore, we need to think about the required behavior in terms of what the SSH server is supposed to do, not just end-to-end with a specific client.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I'm not opposed tbh. I think the best place for most of this testing is within the agentssh package itself. I'll create an issue for this since if we go this route, there's some other restructuring that needs to be done as well. Like moving the forwarding logic from cli to agentssh, etc. Otherwise I think we'll end up with "many implementations of an SSH client".

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@spikecurtis spikecurtis left a comment

Choose a reason for hiding this comment

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

One thing to fixup; but I don't need to review again.

@mafredri mafredri merged commit 385d58c into main Jan 16, 2024
@mafredri mafredri deleted the mafredri/fix-socket-re-forward branch January 16, 2024 19:26
@github-actions github-actions bot locked and limited conversation to collaborators Jan 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow new RemoteForward to override existing RemoteForward in Coder Agent
2 participants