Skip to content

Expose docker API to host#3002

Merged
praveenkumar merged 5 commits intocrc-org:devfrom
praveenkumar:expose_docker_unix
Feb 17, 2022
Merged

Expose docker API to host#3002
praveenkumar merged 5 commits intocrc-org:devfrom
praveenkumar:expose_docker_unix

Conversation

@praveenkumar
Copy link
Copy Markdown
Member

This is only tested on the mac. I will test it on the Linux also but we need someone who can test this windows. I think on windows unix:/// doesn't work, we do need to check if named pipe can be used.

Some of the commits can be removed once the forked repo not needed.

return filepath.Join(MachineInstanceDir, DefaultName, "id_ecdsa")
}

func GetDockerSockOnHost() string {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

maybe GetHostDockerSocketPath?

go.mod Outdated
k8s.io/kubectl => github.com/openshift/kubernetes-kubectl v0.0.0-20210730111826-9c6734b9d97d
)

replace github.com/containers/gvisor-tap-vsock => github.com/protosam/gvisor-tap-vsock v0.3.1-0.20220114153937-6d76545f46e2
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd prefer that we delay this PR a bit until this lands upstream instead of relying on a forked repository we have no control over.

@praveenkumar
Copy link
Copy Markdown
Member Author

/hold

#3002 (comment)

@praveenkumar
Copy link
Copy Markdown
Member Author

/unhold

Copy link
Copy Markdown
Contributor

@cfergeau cfergeau left a comment

Choose a reason for hiding this comment

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

Looks good, still one pending comment, I suspect Windows support will be more work.

@cfergeau
Copy link
Copy Markdown
Contributor

Let's address crc-org/snc#506 (comment) before merging this could cause changes in this PR.

Protocol: "unix",
Local: constants.GetHostDockerSocketPath(),
Remote: fmt.Sprintf("ssh-tunnel://core@%s:%d/run/podman/podman.sock?key=%s", virtualMachineIP, internalSSHPort, constants.GetPrivateKeyPath()),
Remote: fmt.Sprintf("ssh-tunnel://core@%s:%s/run/podman/podman.sock?key=%s", virtualMachineIP, internalSSHPort, constants.GetPrivateKeyPath()),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should be using net.JoinHostPort as well

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I believe you're right. I would also recommend constructing a https://pkg.go.dev/net/url#URL and setting its fields as necessary then stringifying at API boundaries. It'll handle all the weird edge cases.

@praveenkumar praveenkumar force-pushed the expose_docker_unix branch 2 times, most recently from bb435a3 to dd99f84 Compare February 16, 2022 07:35
@praveenkumar praveenkumar added the has-to-be-in-release This PR need to go in coming release. label Feb 16, 2022
Host: net.JoinHostPort(virtualMachineIP, internalSSHPort),
Path: "/run/podman/podman.sock",
ForceQuery: false,
RawQuery: fmt.Sprintf("key=%s", constants.GetPrivateKeyPath()),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

better to run this through https://pkg.go.dev/net/url#QueryEscape, hopefully gvisor-tap-vsock accepts this.
A bit odd to introduce the fmt.Sprintf() in one commit, to change it to using url.URL in a commit which is not really related to this.

We are dropping our fork of mdlayher/vsock since it has the API we need in the version, we
are switching to.

Fixes crc-org#3001
Since now gvisor-tap-vsock have the different protocol implementation
like `unixTotcp`, `unixTounix`, `tcpTotcp` so those details need to
be part of protocol type so that when check for the open port happen it
should match with expose request type.
With this now following will happen automatic
```
✗ curl --unix-socket ~/.crc/crc-http.sock http:/unix/network/services/forwarder/all | jq .
[
  {
    "local": "/tmp/docker.sock",
    "remote": "ssh-tunnel://core@192.168.127.2:22/run/podman/podman.sock?key=/Users/prkumar/.crc/machines/crc/id_ecdsa",
    "protocol": "unix"
  }
]
```
ForceQuery: false,
RawQuery: fmt.Sprintf("key=%s", constants.GetPrivateKeyPath()),
}
return url.QueryEscape(u.String())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

no, you want RawQuery: url.QueryEscape(fmt.Sprintf("key=%s, ...)), and then return url.String(). Or is it RawQuery: fmt.Sprintf("key=%s", url.QueryEscape(constants.GetPrivateKeyPath())?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ah my bad I misread QueryEscape escapes the string so it can be safely placed inside a URL query. this one :(

@anjannath
Copy link
Copy Markdown
Member

Tried it on windows, currently it fails during crc start with the following error:

failed to expose port C:\Users\anath\.crc\machines\crc\docker.sock -> ssh-tunnel://core@192.168.127.2:22/run/podman/podman.sock?key%3DC%3A%5CUsers%5Canath%5C.crc%5Cmachines%5Ccrc%5Cid_ecdsa: key not provided for unix-ssh connection

Daemon logs:

PS C:\Users\anath\redhat\crc> crc daemon
INFO Checking if running in a shell with administrator rights
INFO Checking Windows 10 release
INFO Checking Windows edition
[...]
INFO listening vsock://00000400-FACB-11E6-BD58-64006A7986D3
INFO listening \\.\pipe\crc-http
\\.\pipe\crc-http - - [17/Feb/2022:11:40:01 +0530] "GET /api/version HTTP/1.1" 200 74
\\.\pipe\crc-http - - [17/Feb/2022:11:40:20 +0530] "GET /network/services/forwarder/all HTTP/1.1" 200 3
\\.\pipe\crc-http - - [17/Feb/2022:11:40:20 +0530] "POST /network/services/forwarder/expose HTTP/1.1" 200 0
\\.\pipe\crc-http - - [17/Feb/2022:11:40:20 +0530] "POST /network/services/forwarder/expose HTTP/1.1" 200 0
\\.\pipe\crc-http - - [17/Feb/2022:11:40:20 +0530] "POST /network/services/forwarder/expose HTTP/1.1" 500 41

Copy link
Copy Markdown
Contributor

@cfergeau cfergeau left a comment

Choose a reason for hiding this comment

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

Looks good to me, maybe wait for more feedback from Anjan on Windows?

@openshift-ci
Copy link
Copy Markdown

openshift-ci bot commented Feb 17, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cfergeau, praveenkumar

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:
  • OWNERS [cfergeau,praveenkumar]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@gbraad
Copy link
Copy Markdown
Contributor

gbraad commented Feb 17, 2022

@cfergeau Anjan already mentioned it failed due to the SSH key location. is that resolved @praveenkumar ? If so, @anjannath can test again.

@cfergeau
Copy link
Copy Markdown
Contributor

@cfergeau Anjan already mentioned it failed due to the SSH key location. is that resolved @praveenkumar ? If so, @anjannath can test again.

Anjan tested, reported it's not working, Praveen force-pushed a change which could help with what Anjan was seeing, so I was asking if Anjan can test again.

@praveenkumar
Copy link
Copy Markdown
Member Author

@cfergeau Anjan already mentioned it failed due to the SSH key location. is that resolved @praveenkumar ? If so, @anjannath can test again.

Anjan tested, reported it's not working, Praveen force-pushed a change which could help with what Anjan was seeing, so I was asking if Anjan can test again.

Me and @anjannath tested this PR and in windows also it does able to map the socket but this socket docker client can't consume since it only support named pipe so we need to proxy namedpipe <=> docker sock somehow.

For windows I created a new tracking issue and from this PR disable the DOCKER_HOST from podman-env command on windows.

With this patch following is possible for mac and linux. For windows
we need to use named pipe and that needs bit more effort.
```
✗ ./crc podman-env
export PATH="/Users/prkumar/.crc/bin/oc:$PATH"
export CONTAINER_SSHKEY="/Users/prkumar/.crc/machines/crc/id_ecdsa"
export CONTAINER_HOST="ssh://core@127.0.0.1:2222/run/user/1000/podman/podman.sock"
export DOCKER_HOST="unix:///Users/prkumar/.crc/machines/crc/docker.sock"

x eval $(./crc podman-env)

✗ docker images
REPOSITORY                        TAG                                        IMAGE ID       CREATED        SIZE
quay.io/crcont/gvisor-tap-vsock   3231aba53905468c22e394493a0debc1a6cc6392   f42b05e6b25e   5 months ago   6.65MB
httpd                             2.4                                        a8ea074f4566   2 weeks ago    148MB
```
It also support ipv6 if in future we need support.
@openshift-ci
Copy link
Copy Markdown

openshift-ci bot commented Feb 17, 2022

New changes are detected. LGTM label has been removed.

@praveenkumar
Copy link
Copy Markdown
Member Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved has-to-be-in-release This PR need to go in coming release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants