Commit Graph

859 Commits

Author SHA1 Message Date
Brent Baude 5283f956a5 Disallow mounting to certain destination /dir paths
When certain directories, like /tmp, get mounted over, FCOS/Linux can
act in unexpected ways.  Added a sanity check for a list of directories
think might be impacted by this.  Also, moved the volume parsing earlier
in the init process so we can catch problems before the expensive
decompression of machine images.

The following destinations are forbidden for volumes:

`/bin`, `/boot`, `/dev`, `/etc`, `/home`, `/proc`, `/root`, `/run`, `/sbin`, `/sys`, `/tmp`, `/usr`, and `/var`. Subdirectories

Fixes: #18230

Signed-off-by: Brent Baude <bbaude@redhat.com>
2025-03-07 09:54:01 -06:00
Miloslav Trmač b2d08f5b8f Use UnparsedInstance.Manifest instead of ImageSource.GetManifest
... to validate that the manifests match expected digests, if any.

Do this everywhere, even where we read local storage which is
mostly trusted, because it is cheap enough and being consistent
makes it less likely for the code to be copied into other
contexts shere the sources are not trusted.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2025-02-28 20:14:11 +01:00
Jake Correnti 42fb942a6f
Introduce `podman machine cp` command
Add a new `podman machine cp` subcommand to allow users to copy files or
directories between a running Podman Machine and their host.

Tests cover the following cases:
- Copy a file from the host machine to the VM
- Copy a directory from the host machine to the VM
- Copy a file from the VM to the host machine
- Copy a directory from the VM to the host machine
- Copy a file to a directory
- Copy a directory to a file

Signed-off-by: Jake Correnti <jakecorrenti+github@proton.me>
2025-02-28 09:56:46 -05:00
Paul Holzinger 78717e6ae9
fix new usetesting lint issue
Using t.Setenv() is much better is automatically takes care of the env
cleanup after the test.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2025-02-12 11:32:17 +01:00
Jake Correnti 297e8a3476 Add `machine init --playbook`
Allow the user to provide an Ansible playbook file on init which will
then be run on boot.

Signed-off-by: Jake Correnti <jakecorrenti+github@proton.me>
Signed-off-by: Brent Baude <bbaude@redhat.com>
2025-02-03 16:43:04 -05:00
Mario Loriedo dae1541529 Force use of iptables on Windows WSL
This is a workaround for #25201 and helps with
upgrading the WSL image to Fedora 41.

Signed-off-by: Mario Loriedo <mario.loriedo@gmail.com>
2025-02-03 14:39:47 +01:00
openshift-merge-bot[bot] 48f8742278
Merge pull request #25155 from baude/movedetect
Move detection of libkrun and intel
2025-01-30 15:37:07 +00:00
Brent Baude 398377fd97 Move detection of libkrun and intel
A review comment post merge suggested I move the detection of libkrun and intel into the provider.Get()

Signed-off-by: Brent Baude <bbaude@redhat.com>
2025-01-29 13:26:45 -06:00
Brent Baude 4eeaedfe13 Prevent two podman machines running on darwin
As issue #25112 points out, it was possible to start a machine on one of the darwin providers and then switch providers and start another one with a different name.  This PR firstly prevents that use which is a forbidden use case.

Secondarily, performed some minor cleanup on the error messages being used so that the error would be specific to this condition.

This bug fix is for darwin only.  In the case of Windows, we probably need to answer the question I raised in #24067 first, which is whether we want to stop allowing WSL to run multiple machines.

Fixes #25112

Signed-off-by: Brent Baude <bbaude@redhat.com>
2025-01-29 13:24:18 -06:00
Brent Baude c0aab0a85a Remove usused Kind() function
The Kind() exported function is unused in our code; moreover, the function cannot be accurate because in the case of darwin, applehv and libkrun use the same config in the struct and therefore, we cannot identify the provider via that method.

Signed-off-by: Brent Baude <bbaude@redhat.com>
2025-01-29 12:12:17 -06:00
openshift-merge-bot[bot] c285c7220f
Merge pull request #25151 from l0rd/fix-evalsymlink-windows-option3
Safer use of `filepath.EvalSymlinks()` on Windows
2025-01-29 14:36:53 +00:00
Mario Loriedo 513b4aaceb Safer use of `filepath.EvalSymlinks()` on Windows
The behavior of function `path/filepath.EvalSymlinks()` has
changed in Go v1.23:

- https://go-review.googlesource.com/c/go/+/565136
- https://go.dev/doc/go1.23#minor_library_changes
- https://tip.golang.org/doc/godebug

As a consequences, starting with Podman 5.3.0, when installing
on Windows (WSL) using scoop, Podman fails to start because it
fails to find helper binaries. Scoop copies Podman binaries in
a folder of type Junction and `EvalSymlinks` returns an error.
The problem is described in #24557.

To address this problem we are checking if a path is a `Symlink`
before calling `EvalSymlinks` and, if it's not (hardlinks, mount
points or canonical files), we are calling `path/filepath.Clean`
for consistency. In fact `path/filepath.EvalSymlinks`, after
evaluating a symlink target, calls `Clean` too.

Signed-off-by: Mario Loriedo <mario.loriedo@gmail.com>
2025-01-29 13:15:53 +01:00
Brent Baude 357f76daae error with libkrun on intel-based machines
libkrun is not supported on Intel.  We should error.

Signed-off-by: Brent Baude <bbaude@redhat.com>
2025-01-28 14:12:44 -06:00
Paul Holzinger bdc195d641
pkg/machine/e2e: improve podman.exe match
The regex match would return a horrible error message and is way more
complicated then it should be. Simply check that .exe is not part of the
output.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2025-01-20 19:50:14 +01:00
Paul Holzinger dc3a7e56be
pkg/machine/e2e: improve "list machine from all providers"
The test pulls a big disk image every time which is slow. I see no good
way around that. Let's try to use /dev/null as image as we do not have
to run the VM at all and just can pass a NOP file to make the init
command happy.

That pull of that image seems to take over 2m so we safe quite a lot.
Also update the matcher for the slice. BeTrue() produces horrible
errors.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2025-01-20 19:50:07 +01:00
openshift-merge-bot[bot] d4fce5178f
Merge pull request #24974 from rhatdan/quadlet
Switch all calls of assert.Nil to assert.NoError
2025-01-20 14:34:13 +00:00
Daniel J Walsh 3fb37c588d
Switch all calls of assert.Nil to assert.NoError
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2025-01-15 07:08:27 -05:00
Leo Liu a91aa36367 Remove `.exe` suffix if any
Signed-off-by: Leo Liu <silver886@users.noreply.github.com>

Add comment

In shell completion, there is `.exe` suffix on Windows and this does not provide same experience across platforms, #16499

Signed-off-by: Leo Liu <silver886@users.noreply.github.com>

Create unit test for `.exe` suffix removal

Signed-off-by: Leo Liu <11664880+silver886@users.noreply.github.com>

Update comments

Signed-off-by: Leo Liu <11664880+silver886@users.noreply.github.com>
2025-01-14 11:53:19 -08:00
Paul Holzinger e9fb805522
update golangci/golangci-lint to v1.63.4
Fix new issues found by usetesting, mainly we should use t.TempDir() in
test which makes the code better as this will be removed on test end
automatically so no need for defer or any error checking.
Also fix issues reported by exptostd, these mainly show where we can
switch the imports to the std maps/slices packages instead of the
golang.org/x/exp/... packages.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2025-01-07 15:48:53 +01:00
openshift-merge-bot[bot] 7b35f4fb53
Merge pull request #24694 from arixmkii/update-qemu-files
RFC: Fix compilation issues in QEMU machine files (Windows platform)
2024-12-04 13:26:01 +00:00
openshift-merge-bot[bot] 50a042962b
Merge pull request #23827 from arixmkii/compose-url-fix
Improve platform specific URL handling in `podman compose` for machines
2024-12-04 13:23:15 +00:00
Arthur Sengileyev ededb4c3c4 Improve platform specific URL handling in `podman compose` for machines
Use filepath utility instead of generic string replace to convert path
on Windows. This also separates OS specific implementations to separate
compilation sources and removes redundant check for virtualization
provider on Windows platform.

Signed-off-by: Arthur Sengileyev <arthur.sengileyev@gmail.com>
2024-12-02 20:46:51 +02:00
Arthur Sengileyev 5bbfed2dc1 Cover Unix socket in inpect test on Windows platform
Signed-off-by: Arthur Sengileyev <arthur.sengileyev@gmail.com>
2024-11-29 18:01:38 +02:00
Arthur Sengileyev 7f6a203558 Fix compilation issues in QEMU machine files (Windows platform)
Signed-off-by: Arthur Sengileyev <arthur.sengileyev@gmail.com>
2024-11-27 17:23:08 +02:00
Paul Holzinger a7120b50b1
ssh_config: do not overwrite values from config file
When we alreadty get a full URL with user, port and identity then we
should not read the config file just to overwrite them with wrong
values. This is a bad regression for user using * wildcard in their
ssh_config as it makes podman machine unusable.

Fixes: #24567
Fixes: e523734ab6 ("Add support for ssh_config for connection")

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-11-14 18:26:33 +01:00
openshift-merge-bot[bot] 5dbb567db6
Merge pull request #24321 from gaufde/main
Fix for podman machine init not creating necessary JSON file when an ignition-path is passed
2024-11-14 11:25:16 +00:00
Graceson Aufderheide 34a15ae300 fix podman machine init --ignition-path
Fix the issue where podman machine init does not create
all the necessary machine files when ignition-path is used. Fixes: #23544

Signed-off-by: Graceson Aufderheide <gracesonphoto@gmail.com>
2024-11-12 17:56:43 -07:00
Paul Holzinger 9eca92d625
update golangci-lint to v1.62.0
- fix issues found by recvcheck
- skip k8s files from recvcheck
- remove two removed linters gomnd and execinquery

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-11-11 14:21:17 +01:00
Paul Holzinger 40534d352e
pkg/machine/e2e: remove dead code
This function is not used, we pull actual container images for testing
now. This allows us to remove github.com/coreos/stream-metadata-go.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-11-08 12:02:37 +01:00
Gunjan Vyas 4e8d2dd726 wsl-e2e: Add a test to ensure port 2222 is free with usermode networking
Signed-off-by: Gunjan Vyas <vyasgun20@gmail.com>
2024-11-06 18:40:25 +05:30
Gunjan Vyas 9cb80d1856 gvproxy: Disable port-forwarding on WSL
This commit disables ssh port forwarding on WSL by passing -1 to the -ssh-port flag of gvproxy. Port forwarding is not required on WSL and disabling it prevents port conflict with CRC.

Fixes: https://github.com/containers/podman/issues/20327

Signed-off-by: Gunjan Vyas <vyasgun20@gmail.com>
2024-11-06 15:44:13 +05:30
Paul Holzinger ce24ab0683
pkg/machine/e2e: remove debug
Nobody is looking into this anyway and it just clutters the logs and
will cause confusion for readers. If some day someone wants to fix the
macos IO bugs they can add this back.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-10-29 13:50:05 +01:00
ThaddeusTreloar 1227f19393 Added escaping to invoked powershell command for hyperv stubber.
Signed-off-by: ThaddeusTreloar <thaddeus.treloar@protonmail.com>
2024-10-16 13:16:39 +11:00
Eric Curtin 94dcf76eb2 Make error messages more descriptive
Recently was trying to start podman machine with krunkit and got:

Error: krunkit exited unexpectedly with exit code 1

which isn't very descriptive. Although this doesn't solve the
issue, it increases the debugability of this error.

Signed-off-by: Eric Curtin <ecurtin@redhat.com>
2024-10-14 13:59:38 +01:00
openshift-merge-bot[bot] f311979ec0
Merge pull request #23409 from arixmkii/unix-api-socket
Implement publishing API UNIX socket on Windows platforms
2024-10-11 10:23:14 +00:00
Sergio Lopez 3cedd0c2b5 CI: remove skips for libkrun
Remove the skips introduced to work around #23296

Signed-off-by: Sergio Lopez <slp@redhat.com>
2024-10-07 19:41:20 +02:00
openshift-merge-bot[bot] adbb735958
Merge pull request #23945 from jakecorrenti/default-conn
Handle default system connection transfer properly on machine removal
2024-09-27 13:55:08 +00:00
Jake Correnti e9b8564690 Modify machine "Remove machine" test
Modifies the "Remove machine" test to verify the system connections are
handled properly on removal.

Signed-off-by: Jake Correnti <jakecorrenti+github@proton.me>
2024-09-25 10:28:54 -04:00
Jake Correnti 24deec835c Update connection on removal
Modify `RemoveConnections` to verify the new default system connection's
rootful state matches the rootful-ness of the podman machine it is associated
with.

Signed-off-by: Jake Correnti <jakecorrenti+github@proton.me>
2024-09-24 15:46:02 -04:00
Jake Correnti c709be3a29 Simplify `RemoveConnections`
Takes the code inside the closure in the function `RemoveConnections`
and makes it a separate function to increase readability.

Signed-off-by: Jake Correnti <jakecorrenti+github@proton.me>
2024-09-24 15:45:59 -04:00
Jake Correnti 9febd2c27a Move `DefaultMachineName` to `pkg/machine/define`
Moves the `DefaultMachineName` constant out of `pkg/machine` and into
`pkg/machine/define`.

Signed-off-by: Jake Correnti <jakecorrenti+github@proton.me>
2024-09-24 15:36:14 -04:00
openshift-merge-bot[bot] 47b85af635
Merge pull request #23948 from l0rd/build-with-volumes-on-windows
Convert windows paths in volume arg of the build command
2024-09-16 19:16:13 +00:00
openshift-merge-bot[bot] fbce6dc106
Merge pull request #23949 from l0rd/wsl-disk-oci-pull
Get WSL disk as an OCI artifact
2024-09-16 15:21:53 +00:00
Mario Loriedo b2e6d53265 Get WSL disk as an OCI artifact
[Since a few days][1] WSL disk releases are also pushed
to [quay.io/podman/machine-os-wsl][2]. This PR updates
`podman machine init` mechanism to download WSL disk
images. The WSL disk images are now pulled from quay.io
as for the rest of the providers.

Fixes [#22927][3] and [RUN-2177][4]

[1]: https://github.com/containers/podman-machine-wsl-os/pull/6
[2]: https://quay.io/repository/podman/machine-os-wsl?tab=tags
[3]: https://github.com/containers/podman/issues/22927
[4]: https://issues.redhat.com/browse/RUN-2177

Signed-off-by: Mario Loriedo <mario.loriedo@gmail.com>
2024-09-16 14:36:50 +02:00
Mario Loriedo 1857d7e50f Convert windows paths in volume arg of the build command
Signed-off-by: Mario Loriedo <mario.loriedo@gmail.com>
2024-09-13 17:24:06 +02:00
Nicola Sella d124d90e18 Improve error when starting multiple machines
Instead of ErrVMAlreadyRunning use a more appropriate error.
Also improve the message a little bit.

Fixes: https://github.com/containers/podman/issues/23436

Signed-off-by: Nicola Sella <nsella@redhat.com>
2024-09-13 15:51:27 +02:00
Jake Correnti e041f2a7b7 Remove `RemoveFilesAndConnections`
The `RemoveFilesAndConnections` function is not being used, so its safe
to remove it and not carry unnecessary code that we need to maintain.

Signed-off-by: Jake Correnti <jakecorrenti+github@proton.me>
2024-09-12 14:40:24 -04:00
Jake Correnti 54b71b637c Add `GetAllMachinesAndRootfulness`
Adds the function `GetAllMachinesAndRootfulness` which creates a map of
all podman machines, of any supported provider, on the system and
whether it is rootful or not.

Signed-off-by: Jake Correnti <jakecorrenti+github@proton.me>
2024-09-12 14:31:55 -04:00
Mikel Olasagasti Uranga e9a4534cb1 Update module github.com/shirou/gopsutil to v4
Signed-off-by: Mikel Olasagasti Uranga <mikel@olasagasti.info>
2024-09-03 18:20:12 +02:00
Paul Holzinger f93fcf7dee
bump go to 1.22
Many dependencies started using go 1.22 which means we have to follow in
order to update.

Disable the now depracted exportloopref linter as it was replaced by
copyloopvar as go fixed the loop copy problem in 1.22[1]

Another new chnage in go 1.22 is the for loop syntax over ints, the
intrange linter chacks for this but there a lot of loops that have to be
converted so I didn't do it here and disable th elinter for now, th eold
syntax is still fine.

[1] https://go.dev/blog/loopvar-preview

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-09-03 15:14:15 +02:00