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

Fix SSH port binding #53

Merged
merged 1 commit into from
Sep 11, 2021
Merged

Fix SSH port binding #53

merged 1 commit into from
Sep 11, 2021

Conversation

treydock
Copy link
Contributor

Fixes #52

From what I can gather the key lookup of PortBinding in network settings is wrong, but rather than assume it never exists, I kept behavior but if Ports exists, which is used in unit tests and what my Docker daemon exposes, then use that instead.

So unit tests look like what I see on my Docker daemon:

        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "5b3ed04c8e2e65b854bd9a05cf2053e0ae4e932e3e43811197a10255e646ad40",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {
                "22/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "4584"
                    }
                ]
            },
            "SandboxKey": "/var/run/docker/netns/5b3ed04c8e2e",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "ee4961d5a4a1b37548b6c24b3b1be1ee0473a4d9057b0502c6ebe4ebf2129d1c",
            "Gateway": "172.17.0.1",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "172.17.0.6",
            "IPPrefixLen": 16,
            "IPv6Gateway": "",
            "MacAddress": "02:42:ac:11:00:06",
            "Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "c8a38b79ba988bf1d1301ca810fdceae30636924d57466403047607d14466dce",
                    "EndpointID": "ee4961d5a4a1b37548b6c24b3b1be1ee0473a4d9057b0502c6ebe4ebf2129d1c",
                    "Gateway": "172.17.0.1",
                    "IPAddress": "172.17.0.6",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:11:00:06",
                    "DriverOpts": null
                }
            }
        }
    }

I also updated unit tests to test using 0.0.0.0 since that's what the code sets when setting up the SSH port binding.

@codecov
Copy link

codecov bot commented Aug 13, 2021

Codecov Report

Merging #53 (93c3c2f) into master (b47d868) will decrease coverage by 1.26%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #53      +/-   ##
==========================================
- Coverage   84.82%   83.56%   -1.27%     
==========================================
  Files           1        1              
  Lines         290      292       +2     
==========================================
- Hits          246      244       -2     
- Misses         44       48       +4     
Impacted Files Coverage Δ
lib/beaker/hypervisor/docker.rb 83.56% <100.00%> (-1.27%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b47d868...93c3c2f. Read the comment docs.

@treydock
Copy link
Contributor Author

I think the coverage went down because fewer of the conditions got hit since now the first port binding check is getting used. The actual tests all pass though.

@treydock
Copy link
Contributor Author

@bastelfreak @trevor-vaughan Let me know if this looks good. I've tested this locally on my Mac and it works as expected with Docker.

@russellshackleford
Copy link

Adding my 2¢, this also fixed my problem.
Without this change:

Attempting ssh connection to 172.17.0.2, user: root, opts: {:password=>"root", :port=>22, :forward_agent=>false, :auth_methods=>["password", "publickey", "hostbased", "keyboard-interactive"]}
  Warning: Try 1 -- Host 172.17.0.2 unreachable: Errno::ECONNREFUSED - Connection refused - connect(2) for 172.17.0.2:22

With this change:

Attempting ssh connection to 127.0.0.1, user: root, opts: {:password=>"root", :port=>"179", :forward_agent=>false, :auth_methods=>["password", "publickey", "hostbased", "keyboard-interactive"]}

@trevor-vaughan
Copy link
Contributor

Verifying against podman and WSL docker (that should prod any edge cases)

@trevor-vaughan trevor-vaughan merged commit 6967654 into voxpupuli:master Sep 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Regression with 1.0.0 WRT SSH port usage
4 participants