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

Attempting to add a remote to podman results in key mismatch #23575

Closed
sprig opened this issue Aug 12, 2024 · 17 comments · Fixed by #24340
Closed

Attempting to add a remote to podman results in key mismatch #23575

sprig opened this issue Aug 12, 2024 · 17 comments · Fixed by #24340
Assignees
Labels
jira kind/bug Categorizes issue or PR as related to a bug. macos MacOS (OSX) related remote Problem is in podman-remote

Comments

@sprig
Copy link

sprig commented Aug 12, 2024

Issue Description

Running on macos 14.6:

$ podman --log-level=trace system connection add host ssh://user@host
INFO[0000] podman filtering at log level trace
DEBU[0000] Found SSH_AUTH_SOCK "/private/tmp/com.apple.launchd.LtDz5CJvJ7/Listeners", ssh-agent signer enabled
DEBU[0000] SSH Agent Key SHA256:<key-id> ssh-rsa
DEBU[0000] SSH Agent Key SHA256:<another-id> [email protected]
WARN[0000] ssh host key mismatch for host host:22, got key SHA256:<third-id> of type ecdsa-sha2-nistp256
Error: failed to connect: ssh: handshake failed: knownhosts: key mismatch

whereas

$ ssh host
user@host ~ $

Steps to reproduce the issue

See above.

Describe the results you received

See above.

Describe the results you expected

I expect the connection to be established.
I expect to see where podman looks for host keys in the debug log so that I can confirm/remedy.
In case of another problem (not ssh related) I expect to be notified of this appropriately

podman info output

Macos 14.6


$ podman info
OS: darwin/arm64
provider: applehv
version: 5.1.2

Cannot connect to Podman. Please verify your connection to the Linux system using `podman system connection list`, or try `podman machine init` and `podman machine start` to manage a new Linux VM
Error: unable to connect to Podman socket: Get "http://d/v5.1.2/libpod/_ping": dial unix /var/folders/vx/wq1n25gs5t54v4sp3_6yj3c00000gn/T/storage-run-501/podman/podman.sock: connect: no such file or directory

(note - I intentionally did not start the VM)



### Podman in a container

No

### Privileged Or Rootless

Rootless

### Upstream Latest Release

Yes

### Additional environment details

Additional environment details

### Additional information

Additional information like issue happens only occasionally or issue happens with a particular architecture or on a particular setting

[EDIT]

I just checked the releases and saw 5.2.0 was available. Upgraded. Exactly the same results.
@sprig sprig added the kind/bug Categorizes issue or PR as related to a bug. label Aug 12, 2024
@Luap99 Luap99 added remote Problem is in podman-remote macos MacOS (OSX) related labels Aug 12, 2024
Copy link

A friendly reminder that this issue had no activity for 30 days.

@sprig
Copy link
Author

sprig commented Sep 12, 2024

Nothing stale about this issue, it's just being ignored.

@rhatdan
Copy link
Member

rhatdan commented Sep 12, 2024

You could always attempt to fix it and open a PR.

The contributors to this project are working on hundreds/thousands of issues and features. Whether or not an issue becomes a priority to one is tough to gauge.

@sprig
Copy link
Author

sprig commented Sep 12, 2024

If I knew how to fix this, I would. Unfortunately it is not even clear where to look other than spraying the code with print statements.

Unfortunately most of the documentation for podman that I found is not very technical and is more of a tutorial level - particularly on Red Hat's site - and, e.g. searching the source for "host key mismatch" does not reveal much either.

I did not come here with demands for anyone's time. And yet, calling an issue "stale" when it has not received the slightest drop of attention, e.g. pointing a layman where to dig further, is disingenuous at best.

And, from a distinguished container engineer working at the company developing this technology for profit - read, not volunteer - I would have appreciated the vaguest hint at what to look for much much more than this "intro into how open source works".

@rhatdan
Copy link
Member

rhatdan commented Sep 12, 2024

This is no longer my primary job and I don't work on Mac and Windows side of the operations.

If you were a paying customer and running on RHEL you should have opened an issue with Red Hat and they would have raised the priority. As this is a community project the contributors like me do our best to keep up, but sometimes issues get lost in the cracks. If you look at any very active projects you will find thousands of unanswered issues.

@l0rd PTAL

@sprig
Copy link
Author

sprig commented Sep 12, 2024

I'm not a paying customer and I did not expect support much less in any given timeframe, yet having the issue autoclosed as "stale" simply because it did not get any response is somewhat frustrating.

That being said, my apologies for the snark - it was pointless and unwarranted. Thank you for your reasonable comments.

@rhatdan
Copy link
Member

rhatdan commented Sep 12, 2024

Stale is not closing issues. we leave issue open indefinitely unless the reporter disappears. I usually only look at issues which go stale, since they ping my email.

@sprig
Copy link
Author

sprig commented Sep 15, 2024

I understand, thanks for the explanation.

@l0rd
Copy link
Member

l0rd commented Sep 16, 2024

@sprig I am able to reproduce your problem on my Mac. I will try to figure out if there is a workaround (i.e. cleaning up the keyring where podman finds the other key) and the problem's root cause.

@sprig
Copy link
Author

sprig commented Sep 16, 2024

Thanks!

@l0rd
Copy link
Member

l0rd commented Sep 18, 2024

@sprig can you check if in your ~/.ssh/known_hosts you have a line for the host you are trying to connect to?

In my case, after removing that particular line in the ~/.ssh/known_hosts, I stopped getting the key mismatch error.
I suspect that podman compares SSH keys of different types (Ed25519 and ECDSA in my case). And of course they don't match and the handshake is aborted. Whereas running the command line SSH client works just fine.

@sprig
Copy link
Author

sprig commented Sep 22, 2024

@l0rd Looks like this was this issue! I did not even suspect. Thanks!

I do get a different error now, but it's a bit less cryptic and I can try to debug that but if you have any pointers that would be welcome;

$ podman --log-level=trace ps
INFO[0000] podman filtering at log level trace
DEBU[0000] Called ps.PersistentPreRunE(podman --log-level=trace ps)
DEBU[0000] Found SSH_AUTH_SOCK "/private/tmp/com.apple.launchd.xr9IR7FkPS/Listeners", ssh-agent signer enabled
DEBU[0000] SSH Agent Key SHA256:XXX ssh-rsa
DEBU[0000] SSH Agent Key SHA256:YYY [email protected]
DEBU[0001] DoRequest Method: GET URI: http://d/v5.2.0/libpod/_ping
Cannot connect to Podman. Please verify your connection to the Linux system using `podman system connection list`, or try `podman machine init` and `podman machine start` to manage a new Linux VM
Error: unable to connect to Podman socket: Get "http://d/v5.2.0/libpod/_ping": ssh: rejected: connect failed (open failed)
DEBU[0002] Shutting down engines

$ podman --log-level=trace system connection list
INFO[0000] podman filtering at log level trace
Name        URI                                                         Identity    Default     ReadWrite
host        ssh://user@host:22/tmp/podman-run-1000/podman/podman.sock              true        true
DEBU[0000] Shutting down engines

I suspect this is because I use added a connection to user@host where podman is running rootless and so there isn't a socket to connect to since there is no daemon running (there's also a root instance but it does not expose a socket either currently). I see that /tmp/podman-run-1000 exists on the host but not the socket (unless it is supposed to be dynamically created somehow? which I presume is not the case).

Anyway, the original issue is solved. Thank you! I wish the error messages were clearer regarding what is going on (although fetching the correct key would be more ideal :-). I'll see if I can find where the key fetching takes place and whether it is possible to make it compare the correct one.

Feel free to close the issue - I will leave it open for now in the hope you have something to say regarding the second problem.

@l0rd
Copy link
Member

l0rd commented Sep 23, 2024

Hi @sprig, I had a look at the original issue, and that's a problem with the Golang x/crypto/ssh package. I built a working version of podman using this library. I am considering opening a PR to discuss it with the rest of the maintainers. We need to decide if we want to wait for this proposal implementation and, for the time being, improve the error message as you have suggested. I think we should keep this issue open for now.

@jtognazzi
Copy link

I'm on Windows, and I confirm that deleting the existing known keys from the known_hosts file is a valid workaround.

This is the entry added by the windows ssh program:

silverblue ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILLL65WroYP9RR9Zp8V+0me+fTwwhxcmy+RctAUDQ0Ig

and this is the entry added by podman (version 5.2.0)

silverblue ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBFYFjxg0up06m12Hir3gz4M3MCLqieJBonhmNuW8zRjc8QBdXOk4nhMrVrnmJx5PvS7Pbm7J+nt+1jriq67Fqh8=

@sprig
Copy link
Author

sprig commented Oct 13, 2024

I can also confirm that deleting existing keys works.

@l0rd l0rd added the jira label Oct 14, 2024
@l0rd l0rd self-assigned this Oct 22, 2024
l0rd added a commit to l0rd/containers-common that referenced this issue Oct 22, 2024
golang.org/x/crypto/ssh/knownhosts has an issue when
the SSH server key in the `known_hosts` file doesn't
match the first key returned by the SSH server (but
should be still considered valid because it matches
one of the other keys of the SSH server).
See golang/go#29286 and
containers/podman#23575.

Signed-off-by: Mario Loriedo <[email protected]>
l0rd added a commit to l0rd/containers-common that referenced this issue Oct 22, 2024
Package [golang.org/x/crypto/ssh/knownhosts](https://pkg.go.dev/golang.org/x/crypto/ssh/knownhosts)
has an issue when an SSH server has many public keys (i.e. supports multiple crypto algorithms).

For instance, if the local `known_hosts` file entries don't match the first SSH server key but match
other keys of the SSH server, the handshake fails with a key mismatch error.

See golang/go#29286 and containers/podman#23575.

Package [github.com/skeema/knownhosts](https://github.com/skeema/knownhosts) is a wrapper of
`x/crypto/ssh/knownhosts` that addresses this issue.

This commit replaces the usage of `x/crypto/ssh/knownhosts` in containers/common with
`github.com/skeema/knownhosts`.

Signed-off-by: Mario Loriedo <[email protected]>
l0rd added a commit to l0rd/podman that referenced this issue Oct 22, 2024
The e2e test introduced by this PR verifies that
the command `system connection add` against an
SSH server parses and updates correctly the local
`known_hosts` file.

Depends on containers/common#2212
Fixes containers#23575

Signed-off-by: Mario Loriedo <[email protected]>
l0rd added a commit to l0rd/containers-common that referenced this issue Oct 23, 2024
Package [golang.org/x/crypto/ssh/knownhosts](https://pkg.go.dev/golang.org/x/crypto/ssh/knownhosts)
has an issue when an SSH server has many public keys (i.e. supports multiple crypto algorithms).

For instance, if the local `known_hosts` file entries don't match the first SSH server key but match
other keys of the SSH server, the handshake fails with a key mismatch error.

See golang/go#29286 and containers/podman#23575.

Package [github.com/skeema/knownhosts](https://github.com/skeema/knownhosts) is a wrapper of
`x/crypto/ssh/knownhosts` that addresses this issue.

This commit replaces the usage of `x/crypto/ssh/knownhosts` in containers/common with
`github.com/skeema/knownhosts`.

Signed-off-by: Mario Loriedo <[email protected]>
l0rd added a commit to l0rd/containers-common that referenced this issue Oct 23, 2024
Package [golang.org/x/crypto/ssh/knownhosts](https://pkg.go.dev/golang.org/x/crypto/ssh/knownhosts)
has an issue when an SSH server has many public keys (i.e. supports multiple crypto algorithms).

For instance, if the local `known_hosts` file entries don't match the first SSH server key but match
other keys of the SSH server, the handshake fails with a key mismatch error.

See golang/go#29286 and containers/podman#23575.

Package [github.com/skeema/knownhosts](https://github.com/skeema/knownhosts) is a wrapper of
`x/crypto/ssh/knownhosts` that addresses this issue.

This commit replaces the usage of `x/crypto/ssh/knownhosts` in containers/common with
`github.com/skeema/knownhosts`.

Signed-off-by: Mario Loriedo <[email protected]>
l0rd added a commit to l0rd/podman that referenced this issue Oct 23, 2024
The e2e test introduced by this PR verifies that
the command `system connection add` against an
SSH server parses and updates correctly the local
`known_hosts` file.

Depends on containers/common#2212
Fixes containers#23575

Signed-off-by: Mario Loriedo <[email protected]>
l0rd added a commit to l0rd/podman that referenced this issue Oct 24, 2024
The e2e test introduced by this PR verifies that
the command `system connection add`, run against an
SSH server, parses and updates correctly the local
`known_hosts` file.

Depends on containers/common#2212
Fixes containers#23575

Signed-off-by: Mario Loriedo <[email protected]>
l0rd added a commit to l0rd/podman that referenced this issue Oct 24, 2024
The e2e test introduced by this PR verifies that
the command `system connection add`, run against an
SSH server, parses and updates correctly the local
`known_hosts` file.

Depends on containers/common#2212
Fixes containers#23575

Signed-off-by: Mario Loriedo <[email protected]>
l0rd added a commit to l0rd/podman that referenced this issue Oct 24, 2024
The e2e test introduced by this PR verifies that
the command `system connection add`, run against an
SSH server, parses and updates correctly the local
`known_hosts` file.

Depends on containers/common#2212
Fixes containers#23575

Signed-off-by: Mario Loriedo <[email protected]>
l0rd added a commit to l0rd/podman that referenced this issue Oct 24, 2024
The e2e test introduced by this PR verifies that
the command `system connection add`, run against an
SSH server, parses and updates correctly the local
`known_hosts` file.

Depends on containers/common#2212
Fixes containers#23575

Signed-off-by: Mario Loriedo <[email protected]>
l0rd added a commit to l0rd/podman that referenced this issue Oct 24, 2024
The e2e test introduced by this PR verifies that
the command `system connection add`, run against an
SSH server, parses and updates correctly the local
`known_hosts` file.

Depends on containers/common#2212
Fixes containers#23575

Signed-off-by: Mario Loriedo <[email protected]>
l0rd added a commit to l0rd/podman that referenced this issue Oct 25, 2024
These tests verify that podman successfully adds (or
fails to add) a connection to an SSH server based on
the entries in the `~/.ssh/known_hosts` file.

In particular `system connection add` should succeed if:
- there is no `know_hosts` file
- `known_hosts` has an entry that matches the first protocol/key returned
  by the SSH server
- `known_hosts` has an entry that matches the first protocol/key returned
  by the SSH server
- `known_hosts` has an entry for another SSH server, not for the target server

It should fail if the `known_host` file has an entry for
the target server that matches the protocol but not the key.

Depends on containers/common#2212
Fixes containers#23575

Signed-off-by: Mario Loriedo <[email protected]>
l0rd added a commit to l0rd/podman that referenced this issue Oct 25, 2024
These tests verify that podman successfully adds (or
fails to add) a connection to an SSH server based on
the entries in the `~/.ssh/known_hosts` file.

In particular `system connection add` should succeed if:
- there is no `know_hosts` file
- `known_hosts` has an entry that matches the first protocol/key returned
  by the SSH server
- `known_hosts` has an entry that matches the first protocol/key returned
  by the SSH server
- `known_hosts` has an entry for another SSH server, not for the target server

It should fail if the `known_host` file has an entry for
the target server that matches the protocol but not the key.

Depends on containers/common#2212
Fixes containers#23575

Signed-off-by: Mario Loriedo <[email protected]>
l0rd added a commit to l0rd/containers-common that referenced this issue Oct 25, 2024
Package [golang.org/x/crypto/ssh/knownhosts](https://pkg.go.dev/golang.org/x/crypto/ssh/knownhosts)
has an issue when an SSH server has many public keys (i.e. supports multiple crypto algorithms).

For instance, if the local `known_hosts` file entries don't match the first SSH server key but match
other keys of the SSH server, the handshake fails with a key mismatch error.

See golang/go#29286 and containers/podman#23575.

Package [github.com/skeema/knownhosts](https://github.com/skeema/knownhosts) is a wrapper of
`x/crypto/ssh/knownhosts` that addresses this issue.

This commit replaces the usage of `x/crypto/ssh/knownhosts` in containers/common with
`github.com/skeema/knownhosts`.

Signed-off-by: Mario Loriedo <[email protected]>
l0rd added a commit to l0rd/podman that referenced this issue Oct 25, 2024
These tests verify that podman successfully adds (or
fails to add) a connection to an SSH server based on
the entries in the `~/.ssh/known_hosts` file.

In particular `system connection add` should succeed if:
- there is no `know_hosts` file
- `known_hosts` has an entry that matches the first protocol/key returned
  by the SSH server
- `known_hosts` has an entry that matches the first protocol/key returned
  by the SSH server
- `known_hosts` has an entry for another SSH server, not for the target server

It should fail if the `known_host` file has an entry for
the target server that matches the protocol but not the key.

Depends on containers/common#2212
Fixes containers#23575

Signed-off-by: Mario Loriedo <[email protected]>
l0rd added a commit to l0rd/containers-common that referenced this issue Oct 28, 2024
Package [golang.org/x/crypto/ssh/knownhosts](https://pkg.go.dev/golang.org/x/crypto/ssh/knownhosts)
has an issue when an SSH server has many public keys (i.e. supports multiple crypto algorithms).

For instance, if the local `known_hosts` file entries don't match the first SSH server key but match
other keys of the SSH server, the handshake fails with a key mismatch error.

See golang/go#29286 and containers/podman#23575.

Package [github.com/skeema/knownhosts](https://github.com/skeema/knownhosts) is a wrapper of
`x/crypto/ssh/knownhosts` that addresses this issue.

This commit replaces the usage of `x/crypto/ssh/knownhosts` in containers/common with
`github.com/skeema/knownhosts`.

Signed-off-by: Mario Loriedo <[email protected]>
l0rd added a commit to l0rd/podman that referenced this issue Oct 28, 2024
These tests verify that podman successfully adds (or
fails to add) a connection to an SSH server based on
the entries in the `~/.ssh/known_hosts` file.

In particular `system connection add` should succeed if:
- there is no `know_hosts` file
- `known_hosts` has an entry that matches the first protocol/key returned
  by the SSH server
- `known_hosts` has an entry that matches the first protocol/key returned
  by the SSH server
- `known_hosts` has an entry for another SSH server, not for the target server

It should fail if the `known_host` file has an entry for
the target server that matches the protocol but not the key.

Depends on containers/common#2212
Fixes containers#23575

Signed-off-by: Mario Loriedo <[email protected]>
l0rd added a commit to l0rd/podman that referenced this issue Oct 28, 2024
These tests verify that podman successfully adds (or
fails to add) a connection to an SSH server based on
the entries in the `~/.ssh/known_hosts` file.

In particular `system connection add` should succeed if:
- there is no `know_hosts` file
- `known_hosts` has an entry that matches the first protocol/key returned
  by the SSH server
- `known_hosts` has an entry that matches the first protocol/key returned
  by the SSH server
- `known_hosts` has an entry for another SSH server, not for the target server

It should fail if the `known_host` file has an entry for
the target server that matches the protocol but not the key.

Depends on containers/common#2212
Fixes containers#23575

Signed-off-by: Mario Loriedo <[email protected]>
l0rd added a commit to l0rd/podman that referenced this issue Oct 28, 2024
These tests verify that podman successfully adds (or
fails to add) a connection to an SSH server based on
the entries in the `~/.ssh/known_hosts` file.

In particular `system connection add` should succeed if:
- there is no `know_hosts` file
- `known_hosts` has an entry that matches the first protocol/key returned
  by the SSH server
- `known_hosts` has an entry that matches the first protocol/key returned
  by the SSH server
- `known_hosts` has an entry for another SSH server, not for the target server

It should fail if the `known_host` file has an entry for
the target server that matches the protocol but not the key.

Depends on containers/common#2212
Fixes containers#23575

Signed-off-by: Mario Loriedo <[email protected]>
@rsenna
Copy link

rsenna commented Nov 3, 2024

Having the same issue on macOS and Linux.
I managed to get it working at some point, by removing the keys from .ssh/known_hosts as mentioned here, but even that stopped working after some time in my case...
Forcing podman to use the required key also doesn't work:

$ podman --identity ~/.ssh/id_ed25519 ps

WARN[0000] ssh host key mismatch for host some-host-ip:22, got key SHA256:... of type ecdsa-sha2-nistp256
Cannot connect to Podman. Please verify your connection to the Linux system using `podman system connection list`, or try `podman machine init` and `podman machine start` to manage a new Linux VM
Error: unable to connect to Podman socket: failed to connect: ssh: handshake failed: knownhosts: key mismatch

l0rd added a commit to l0rd/podman that referenced this issue Nov 4, 2024
These tests verify that podman successfully adds (or
fails to add) a connection to an SSH server based on
the entries in the `~/.ssh/known_hosts` file.

In particular `system connection add` should succeed if:
- there is no `know_hosts` file
- `known_hosts` has an entry that matches the first protocol/key returned
  by the SSH server
- `known_hosts` has an entry that matches the first protocol/key returned
  by the SSH server
- `known_hosts` has an entry for another SSH server, not for the target server

It should fail if the `known_host` file has an entry for
the target server that matches the protocol but not the key.

Depends on containers/common#2212
Fixes containers#23575

Signed-off-by: Mario Loriedo <[email protected]>
@l0rd
Copy link
Member

l0rd commented Nov 4, 2024

I have opened a PR that should address this issue. In this commit message, I describe the podman scenarios I have tested. To be able to merge it, though, I am waiting to see all CI tests green and reviews.

l0rd added a commit to l0rd/podman that referenced this issue Nov 4, 2024
These tests verify that podman successfully adds (or
fails to add) a connection to an SSH server based on
the entries in the `~/.ssh/known_hosts` file.

In particular `system connection add` should succeed if:
- there is no `know_hosts` file
- `known_hosts` has an entry that matches the first protocol/key returned
  by the SSH server
- `known_hosts` has an entry that matches the first protocol/key returned
  by the SSH server
- `known_hosts` has an entry for another SSH server, not for the target server

It should fail if the `known_host` file has an entry for
the target server that matches the protocol but not the key.

Depends on containers/common#2212
Fixes containers#23575

Signed-off-by: Mario Loriedo <[email protected]>
l0rd added a commit to l0rd/podman that referenced this issue Nov 4, 2024
These tests verify that podman successfully adds (or
fails to add) a connection to an SSH server based on
the entries in the `~/.ssh/known_hosts` file.

In particular `system connection add` should succeed if:
- there is no `know_hosts` file
- `known_hosts` has an entry that matches the first protocol/key returned
  by the SSH server
- `known_hosts` has an entry that matches the first protocol/key returned
  by the SSH server
- `known_hosts` has an entry for another SSH server, not for the target server

It should fail if the `known_host` file has an entry for
the target server that matches the protocol but not the key.

Depends on containers/common#2212
Fixes containers#23575

Signed-off-by: Mario Loriedo <[email protected]>
l0rd added a commit to l0rd/podman that referenced this issue Nov 7, 2024
These tests verify that podman successfully adds (or
fails to add) a connection to an SSH server based on
the entries in the `~/.ssh/known_hosts` file.

In particular `system connection add` should succeed if:
- there is no `know_hosts` file
- `known_hosts` has an entry that matches the first protocol/key returned
  by the SSH server
- `known_hosts` has an entry that matches the first protocol/key returned
  by the SSH server
- `known_hosts` has an entry for another SSH server, not for the target server

It should fail if the `known_host` file has an entry for
the target server that matches the protocol but not the key.

Depends on containers/common#2212
Fixes containers#23575

Signed-off-by: Mario Loriedo <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
jira kind/bug Categorizes issue or PR as related to a bug. macos MacOS (OSX) related remote Problem is in podman-remote
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants