-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Add support for ssh_config for connection #23847
Add support for ssh_config for connection #23847
Conversation
da20322
to
096a372
Compare
Ephemeral COPR build failed. @containers/packit-build please check. |
Added required files to the "vendor" directory (by using bloat approved
no new tests
BTW; There is no "tests" directory, but there is a "test" directory? The "secure" parameter doesn't seem to do anything anymore?
|
This will fix trying to nslookup the alias, but it will not add support for In order to support that, Podman needs to use more of containers/common SSHMode Like it said in the original PR #15094 (that added
The current workaround is to tunnel a temporary unix: socket with a |
110kb from a 1700 line diffstat, ouch. Bloat approved label added still. |
Few nits, looks fine overall. @baude PTAL when you get back. |
Not sure if there was any obvious culprit, it seemed to be evenly spread...
EDIT: I take that back, the use of "runtime" seems suspicious and bloated https://github.com/kevinburke/ssh_config/blob/v1.2.0/config.go#L312 if r := recover(); r != nil {
if _, ok := r.(runtime.Error); ok {
panic(r)
}
if e, ok := r.(error); ok && e == ErrDepthExceeded {
err = e
return
}
err = errors.New(r.(string))
} https://go.dev/wiki/CodeReviewComments#dont-panic So maybe the bloat checker was onto something anyway? |
8bea341
to
46bbf98
Compare
pkg/bindings/connection.go
Outdated
cfg := ssh_config.DefaultUserSettings | ||
if val := cfg.Get(alias, "User"); val != "" { | ||
userinfo = url.User(val) | ||
logrus.Debugf("User: %s", val) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These debug statements are not clear, they need to mention ssh config at least
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They could be removed altogether, they were mostly used during implementing...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is likely value in having them to see what the lib parsed in case of weird user configs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A compromise might be to log the new URL (once), once all the substitution (if any) is done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes logging the final url once sounds good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wasn't so easy to log the information since _url is not the only source of information used...
But changed it so that it only outputs something, if an alias was actually found in ssh_config.
pkg/bindings/connection.go
Outdated
if err := session.Run( | ||
"podman info --format '{{.Host.RemoteSocket.Path}}'"); err != nil { | ||
return nil, err | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a good idea for performance reasons, podman info is slow...
Also podman info has no actual knowledge of the actual API socket path and just guess the /run/podman/podman.sock or /run/user/xxx/podman/podman.sock as rootless so there is no reason to do that as you might as well guess on the client. Of course you would need to get the uid on the server to do this.
I mean alone the extra ssh connection is already slow but I think there is no need to avoid that if we need the uid on the server so maybe the podman info at this point is not to bad either?
Given that is is properly not a good idea to recommend leaving it the socket path if users care about performance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it was more about compatibility/simplicity, and less about performance?
There is already the "system connection", that should be the preferred option...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it can hardcode the /run/user/$UID
either, need to query for $XDG_RUNTIME_DIR.
Most systems with systemd will use the default, but other systems might use another directory...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I looked at this was like podman info isn't really great for this but thinking about this again given there is no way around opening an extra ssh connection for it so doing the podman info call should not be that big of a deal either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eventually it might use the containers/common functionality for this (the "SSHMode").
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/containers/common/tree/main/pkg/ssh (the "golang" vs "native")
Note that if providing a fully qualified URL, this will be a no-op (assuming an empty/small ~/.ssh/config)
It will only kick in, if there is an "alias" defined or if there are any parameters missing (like user or path) |
There is more talk about performance in the issue, beyond using a legacy --host=ssh:// How to reuse the same ssh connection (and path), and how to choose a faster encryption... For lima there is a "host agent" that sets up a persistent tunnel, and provides a unix socket |
186b0ab
to
fe5df7e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay, I have not forgotten this.
Also can you squash your commits please. |
fe5df7e
to
b174663
Compare
b174663
to
d529d42
Compare
Cockpit tests failed for commit b174663c2f1354c5b3f32c234f780303b177a2ac. @martinpitt, @jelly, @mvollmer please check. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, sorry for the late reply this time it fell of my list.
Can you rebase this please? If you don't have time I can also do that.
@mheon PTAL so we can merge once rebased.
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: afbjorklund, Luap99 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Signed-off-by: Anders F Björklund <[email protected]>
Signed-off-by: Anders F Björklund <[email protected]>
Signed-off-by: Anders F Björklund <[email protected]>
d529d42
to
b455f94
Compare
/lgtm |
Previously had to use
podman system connection
Normal
ssh://<alias>
would fail to work properlye.g. "default",
podman --host ssh://default --ssh native ps
Does this PR introduce a user-facing change?
Also adds support for default ssh user and path.
Tested manually with Lima. No unit tests found.
Uses https://github.com/kevinburke/ssh_config
Closes #23831
Fixes #17452