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

Changes to support external transport implementations #575

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mdarocha
Copy link

@mdarocha mdarocha commented Jul 19, 2022

Will help with #540

After discussion, this PR implements changes that will allow external packages to extend
DockerClientConfiguration and implement their own transport methods, including SSH.

@dnfadmin
Copy link

dnfadmin commented Jul 19, 2022

CLA assistant check
All CLA requirements met.

@WojciechNagorski
Copy link

Great work!
Are you going to create a PR to https://github.com/sshnet/SSH.NET with changes from your fork https://github.com/TrapTech/SSH.NET?

@mdarocha
Copy link
Author

Great work!
Are you going to create a PR to https://github.com/sshnet/SSH.NET with changes from your fork https://github.com/TrapTech/SSH.NET?

I dont think thats needed , since my fork just merges changes that already have a PR made there.

@WojciechNagorski
Copy link

Do you mean sshnet/SSH.NET#144 ? I didn't know about this PR. Maybe It should be updated because it stucks in the 2020 year.

@mdarocha
Copy link
Author

Do you mean sshnet/SSH.NET#144 ? I didn't know about this PR. Maybe It should be updated because it stucks in the 2020 year.

Yes, thats the one. Maybe I'll see about making a new PR

@WojciechNagorski
Copy link

@mdarocha any update?

@mdarocha
Copy link
Author

mdarocha commented Nov 24, 2022

@mdarocha any update?

Sorry, didn't have time to work on this.

I made sshnet/SSH.NET#1052, and will wait for a response. You can consider this PR dependant on that one.

Unless someone figures out some other way than SSH.NET to communicate over SSH.

For the time being, if anyone needs this functionality, you can use the forked TrapTech.Docker.DotNet nuget, which includes this.

@mdarocha
Copy link
Author

mdarocha commented Nov 24, 2022

Unless we refactor this PR to contain only the changes in the main Docker.DotNet project, and keep the Docker.DotNet.SSH out of this repo, as a completely separate, custom nuget? Then everybody could use the upstream library, and install SSH support as a separate nuget, not necessarily built from this repo.

I'm not sure however how to solve the assembly linking problems that can result from this, since currently all Docker.DotNet.* assemblies have to have the same version.

@HofmeisterAn
Copy link
Contributor

HofmeisterAn commented Nov 28, 2022

I'm not sure however how to solve the assembly linking problems that can result from this, since currently all Docker.DotNet.* assemblies have to have the same version.

Can't you use the version ranges to pin it to a specific version?

@galvesribeiro
Copy link
Member

Yeah, I agree. We should keep things separated...

@mdarocha
Copy link
Author

Ok, I've reverted the changes that add the SSH project and dependencies on the forked SSH library.

Now that remains in this PR is enough scaffolding for anyone to hook up with their own SSH library. I plan on publishing the code that was here as a separate nuget if we merge this PR.

There are some additional diffs in this PR due to some problems with line endings on the master branch.

@mdarocha
Copy link
Author

Does the PR look ok to merge in its current state?

@mdarocha mdarocha changed the title SSH communication Changes to support external transport implementations May 26, 2023
@mdarocha
Copy link
Author

@WojciechNagorski @HofmeisterAn I've done a bit of a refactor according to your suggestions

Copy link

@WojciechNagorski WojciechNagorski left a comment

Choose a reason for hiding this comment

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

LGTM. I have two questions but overall it looks great.

This PR also contains many whitespace changes in files that have not been changed in this PR. I always try to avoid this situation because it makes the reviewer's job more difficult and causes merge conflicts in other PRs. Some reviewers might reject such PR.

@mdarocha
Copy link
Author

mdarocha commented May 29, 2023

As per the diff: yeah, I normally avoid such situations, but it appears the master branch has some files checked in with CRLF line endings, which caused those problems.

Copy link

@WojciechNagorski WojciechNagorski left a comment

Choose a reason for hiding this comment

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

Looks even better 😄

@mdarocha
Copy link
Author

mdarocha commented Jun 14, 2023

Any updates? @HofmeisterAn is this ok to merge? Note that it no longer depends on the SSH.NET changes.

Copy link
Contributor

@HofmeisterAn HofmeisterAn left a comment

Choose a reason for hiding this comment

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

Any updates? @HofmeisterAn is this ok to merge? Note that it no longer depends on the SSH.NET changes.

In general, I am okay with the PR, but I cannot merge it. The repository's owner, @galvesribeiro, has the necessary permission to do so. One thing that has already been discussed are the white space changes. It would be helpful if we could remove them from the PR, as they make up the majority of the changes (and are unnecessary).

@galvesribeiro
Copy link
Member

Can you please remove all the spacing/formatting changes? It is kinda hard to see what are the actual changes.

One thing that I'm struggling to understand is the usefulness of this change and wether or not does it fit to the library. Perhaps after you clean up the space changes it will be easier to understand/review.

Please let me know when it is ready and I'll take a look.

@mdarocha
Copy link
Author

@galvesribeiro @HofmeisterAn ok, I think I managed to fix the whitespace changes.
This should really be fixed on the main branch, since it makes it a bit annoying to work on the repo :D

One thing that I'm struggling to understand is the usefulness of this change and wether or not does it fit to the library. Perhaps after you clean up the space changes it will be easier to understand/review.

Keep in mind that previously this PR was focused on implementing SSH transport support for this library (something that's needed, since it's the only non-deprecated way left for remote access), but since SSH.NET is missing the required functionality (sshnet/SSH.NET#1052) this PR has transformed into a way of allowing any external library to implement custom transports for the Docker api. This allows to ie. implement the SSH logic in a completely separate library (and if Docker introduces any future ways of connecting, they can be implemented without waiting for upstream Docker.DotNet to be updated).

@mdarocha mdarocha force-pushed the ssh-transport branch 2 times, most recently from eca00e0 to b72c10f Compare June 22, 2023 15:53
@galvesribeiro
Copy link
Member

Keep in mind that previously this PR was focused on implementing SSH transport support for this library

We can potentially implement this as a new NuGet package for sure.

(something that's needed, since it's the only non-deprecated way left for remote access)

@mdarocha, can you point me to any official docs that state that? I may have missed the notes on this.

@mdarocha
Copy link
Author

(something that's needed, since it's the only non-deprecated way left for remote access)

@mdarocha, can you point me to any official docs that state that? I may have missed the notes on this.

https://docs.docker.com/engine/security/protect-access/#use-tls-https-to-protect-the-docker-daemon-socket well guess I overshot it with the 'deprecated' claim, the docs just suggest that it's hard :D

@WojciechNagorski
Copy link

The new 2024.0.0 SSH.NET version support input stream.

Currently, we can send some string (data) via inputStream that can be open command.CreateInputStream():

var inputByteArray = Encoding.UTF8.GetBytes("Hello world!");

using (var command = _sshClient.CreateCommand("docker system dial-stdio"))
{
    var asyncResult = command.BeginExecute();

    var inputStream = command.CreateInputStream())
    {
        inputStream.Write(inputByteArray, 0, inputByteArray.Length);
    }

    command.EndExecute(asyncResult);
}

It should be possible to use JoinedReadWriteStream from the previous version of this PR.

var result = new JoinedReadWriteStream(cmd.OutputStream, inputStream);

@PascalSenn
Copy link

Is there any chance this Pull Request can be revived?

@PascalSenn
Copy link

This would be fantastic for libraries like https://github.com/SwissLife-OSS/squadron or https://github.com/testcontainers/testcontainers-dotnet because this would allow to run all containers in testing on a remote machine and keep the local device free of any pressure.

@galvesribeiro
Copy link
Member

Hello! We can get this in. Doing a wave of merges on older PRs with improvements/fixes before I start adding the new code.

@mdarocha do you mind rebasing on the latest main and solve the conflicts so we can merge it?

@mdarocha
Copy link
Author

Hello! We can get this in. Doing a wave of merges on older PRs with improvements/fixes before I start adding the new code.

@mdarocha do you mind rebasing on the latest main and solve the conflicts so we can merge it?

Sure, I'll try to do it over the weekend

@mdarocha
Copy link
Author

mdarocha commented Nov 1, 2024

Ok, updated.

Seems like SSH.NET has since added the missing library features, so SSH transport can now be implemented by overriding DockerClientConfiguration using the latest version of SSH.NET. I'm leaving this up to some other contributor, either as a new nuget in this repository, or a completely new project.

@@ -63,10 +67,87 @@ public void Dispose()
Credentials.Dispose();
}

public (Uri url, ManagedHandler handler) GetHandler()

Choose a reason for hiding this comment

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

Should this be virtual so others can override it?

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.

7 participants