Commit Graph

110 Commits

Author SHA1 Message Date
Miloslav Trmač 265ca77276 Be explicit about ssh configs suitable only for localhost
... and warn loudly against generalization.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2025-05-15 23:04:49 +02:00
Mario Loriedo 8e6ecb97c9 Fix running machines with volumes containing spaces
Machines configured to mount local paths containing
spaces failed to start on Hyper-V and silently failed
to mount the folder on macOS/Linux.

On Windows/hyperv, where local paths are mounted
running a 9p client inside the VM, the local host
path needs to be surrounding with quotation marks
before using in a `podman machine ssh ...` command.

A similar behavior happened on Linux/QEMU where the
path was used in a SSH command to mount the folder
using virtiofs. Quoting the path when buidling the
command arguments fixed the problem.

On macOS/libkit,applehv the path was written as is
in a systemd unit name to instruct how to mount it.
Escaping space chars so that they are are parsed
successfully fixed this:
```diff
-- enable path with spaces.mount
++ enable path\x20with\x20spaces.mount
```

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

Signed-off-by: Mario Loriedo <mario.loriedo@gmail.com>
2025-04-30 08:54:42 +02:00
Mario Loriedo 2588b96993 Fix logging podman machine server9 output
Command `podman machine init` for Hyper-V machines invokes the command
`podman machine server9` and redirects it's output to a file. But the
file descriptor was closed before beeing used and the output file was
always empty.

Signed-off-by: Mario Loriedo <mario.loriedo@gmail.com>
2025-04-28 15:42:43 +00:00
Kir Kolyshkin a776c1d82a pkg/machine/vmconfigs: simplify IsFirstBoot
This is faster and, to my best knowledge, is equivalent to the old code.

Remove the error return (as we don't guarantee stable API here), and
simplify callers.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2025-03-28 17:55:53 -07: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
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
Shion Tanaka fe7cc67ef4 Add Rosetta support for Apple Silicon mac
Signed-off-by: Shion Tanaka <shtanaka@redhat.com>
2024-05-17 17:53:28 +09:00
openshift-merge-bot[bot] 5c39ddca5d
Merge pull request #22140 from baude/hypervrmf
hyperv: fix machine rm -r
2024-03-26 14:03:24 +00:00
Jason T. Greene 11415b3e74 Use built-in ssh impl for all non-pty operations
Windows is not guaranteed to have the SSH feature installed, so prefer the use
of the built-in ssh client for all operations other than podman machine ssh,
which requires terminal pty logic. This restores previous behavior in 4.x.

Signed-off-by: Jason T. Greene <jason.greene@redhat.com>
2024-03-24 21:25:22 -05:00
Brent Baude a6ffb5656f hyperv: fix machine rm -r
this pr fixes two hyperv bugs.  previous podman 5 versions of hyperv
failed to actually remove the vm from hyperv when machine rm -f was
called.

also fixes an annoying bug where removal of the hyperv ignition entries
were failing because this can only be done (with the current api) when
the vm is running.  new api in latest libhvee fixes this.

Signed-off-by: Brent Baude <bbaude@redhat.com>
2024-03-22 11:09:17 -05:00
Paul Holzinger 4d2fc293c0
machine: make more use of strongunits
To make it very clear in the code what unit the uint represents.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-03-06 16:14:30 +01:00
Jason T. Greene 6272abbbb8 Resurrect auto-port reassignment, but for all providers
- Updates common to pull in new locked edit

[NO NEW TESTS NEEDED]

Signed-off-by: Jason T. Greene <jason.greene@redhat.com>
2024-03-04 23:55:36 -06:00
Jason T. Greene ef7727238a Refactor env dir and port functions into new leaf pkgs
[NO NEW TESTS NEEDED]

Signed-off-by: Jason T. Greene <jason.greene@redhat.com>
2024-03-04 23:54:31 -06:00
Ashley Cui 35133c8424 Move locks to shim layer
Previously, the locks were on the provider layer, which doesn't make a vm operation with a config file update atomic. Move them up a layer, so the entire function locks while doing provider and config operations.

This adds a Remove and a Set function to the shim layer.

[NO NEW TESTS NEEDED] Unsure how to test this

Signed-off-by: Ashley Cui <acui@redhat.com>
2024-02-29 00:12:04 -05:00
openshift-merge-bot[bot] c93ed35b09
Merge pull request #21848 from baude/machinestartcleanup
Clean up gvproxy if machine start fails
2024-02-28 12:08:21 +00:00
Matt Heon 26ec570c65 Ensure HyperV 9p mounts work when a dir doesn't exist
Before, we required that the mount target exist and be a
directory for the 9p mount to successfully complete, which is not
how things are supposed to work - the user should be able to
mount anywhere. This should just be a simple mkdir, but with FCOS
the root directory is immutable so we need to undo that before we
can mkdir, and unfortunately we don't have a library that can do
chattr (and I didn't want to drag in a new dependency just for
that), so let's be gross and add it to the SSH command. I
aggressively dislike this but it does work.

[NO NEW TESTS NEEDED] Can worry about getting a more generic
mount test together for Machine later.

Signed-off-by: Matt Heon <mheon@redhat.com>
2024-02-27 14:33:53 -05:00
Brent Baude dfae51a4b8 Clean up gvproxy if machine start fails
Matt found a bug where if a machine start did not run to completion, a
gvproxy was left around running.  This gvproxy then subsequently stopped
the next attempt to start.

Signed-off-by: Brent Baude <bbaude@redhat.com>

[NO NEW TESTS NEEDED]
2024-02-27 13:33:43 -06:00
Jason T. Greene b68d3c7a0e Fix race conditions in hyperv readiness checking
- Listen before starting the vm
- Fix a device race caused by lazy hv_vsock init by waiting on network manager

[NO NEW TESTS NEEDED]

Signed-off-by: Jason T. Greene <jason.greene@redhat.com>
2024-02-24 01:43:28 -06:00
Matt Heon ec68f07c04 Fix Lint on Windows and enable the job
[NO NEW TESTS NEEDED] Purely refactoring

Signed-off-by: Matt Heon <mheon@redhat.com>
2024-02-20 08:06:18 -05:00
openshift-merge-bot[bot] bed619ca3d
Merge pull request #21664 from n1hility/wsl-fix-conflict
Fixes VM name conflict checking with WSL
2024-02-15 20:24:22 +00:00
Jason T. Greene d23dd35dc1 Correct VM existance check on WSL
Replaces GetHyperVisorVMs() with Exists() to better abstract the underlying
use-case and slightly imrpove efficiency.

Signed-off-by: Jason T. Greene <jason.greene@redhat.com>
2024-02-14 15:27:56 -06:00
Jake Correnti 0e9d867555 machine: `machine set` only when machine's stopped
Requires that the specified machine's state is `define.Stopped` in order
to set settings.

Signed-off-by: Jake Correnti <jakecorrenti+github@proton.me>
2024-02-13 16:50:22 -05:00
Jason T. Greene 487219d809 Complete WSL implementation, refactor a few areas
Also addresses a number of issues:
- StopHostNetworking isn't plumbed, win-sshproxy leaks on hyperv
- Wait api and print output doesn't work properly on Windows
- API forwarding doesn't work on WSL
- Terminal corruption with after start/stop on Windows
- Gvproxy is forcefully killed vs gracefully quit
- Switching rootful/rootless does not update /var/run/docker.sock on the guest
- File already closed error on init
- HyperV backend is publishing Unix sockets when it should be named pipes
- User-mode networking doesn't always work
- Stop state outside of lock boundaries
- WSL blocks parallel machined (should be supported)

[NO NEW TESTS NEEDED]

Signed-off-by: Jason T. Greene <jason.greene@redhat.com>
2024-02-11 12:58:11 -06:00
Brent Baude d7cb66492b wsl - wip
Signed-off-by: Brent Baude <bbaude@redhat.com>
2024-02-11 12:58:11 -06:00
Brent Baude 2a61998f07 Fail if vm exists in hyperv already
Fix a bug where if a vm exists, created by some other process/user, and
you attempt to make a podman machine with the same name.

Signed-off-by: Brent Baude <bbaude@redhat.com>
2024-02-10 14:49:34 -06:00
Jake Correnti 7be6cd4b09 machine: USB passthrough
Sets up USB passthrough for machine. Additionally moves `SetOptions` out
from `pkg/machine/config.go` to its own file in
`pkg/machine/define/setopts.go`.

[NO NEW TESTS NEEDED]

Signed-off-by: Jake Correnti <jakecorrenti+github@proton.me>
2024-02-08 20:30:43 -05:00
Matt Heon 72f1617fac Bump Go module to v5
Moving from Go module v4 to v5 prepares us for public releases.

Move done using gomove [1] as with the v3 and v4 moves.

[1] https://github.com/KSubedi/gomove

Signed-off-by: Matt Heon <mheon@redhat.com>
2024-02-08 09:35:39 -05:00
Jake Correnti 90c938737a Add functionality for `podman machine set --rootful`
Adds the functionality for `podman machine set --rootful` for AppleHV,
QEMU, and HyperV. Abstracts the functionality out to a method of
`MachineConfig`. WSL currently uses a function `SetRootful` that is
provided by the `machine` package, which will eventually get changed
when WSL moves to the refactored structure.

Re-enables the "set rootful with docker sock change" test.

[NO NEW TESTS NEEDED]

Signed-off-by: Jake Correnti <jakecorrenti+github@proton.me>
Signed-off-by: Brent Baude <bbaude@redhat.com>
2024-02-07 13:24:18 -06:00
Brent Baude b1ce6ef9a8 podman machine 5 - hyperv
this pr represents the podman 5 maching refactoring for HyperV.  with
the exception of already skipped tests, all local tests pass.

Signed-off-by: Brent Baude <bbaude@redhat.com>
2024-02-07 09:18:51 -06:00
Brent Baude 9bb191df51 [CI:MACHINE]Podman5 QEMU refactor
The following PR is the leading PR for refactoring podman machine with
the following goals:

* less duplication/more re-use
* common configuration file between providers
* more consistentency in how machines are handled by providers

The goal of this PR is the rough refactor.  There are still rough spots
for sure, specifically around the podman socket and pipe.  This
implemention is only for Linux. All other providers are still present
but will not compile or work.  This is why tests for them have been
temporarily suspended.

The ready socket code is another area that needs to be smoothed over.
Right now, the ready socket code is still in QEMU.  Preferably it would
be moved to a generic spot where all three approaches to readiness
socket use can be defined.

It should also be noted:

* all machine related tests pass.
* make validate for Linux passes
* Apple QEMU was largely removed
* More code pruning is possible; will become clearer when other
  providers are complete.

the dir pkg/machine/p5 is not permanent.  i had to seperate this from
machine initially due to circular import problems.  i think when all
providers are done (or nearly done), it can be placed and named
properly.

Signed-off-by: Brent Baude <bbaude@redhat.com>
2024-02-07 09:18:36 -06:00
Brent Baude b9bcfa4749 podman5 machine reconfig 1
this is a logical place to get changes upstream before they grow out of
control.  this pr is the first in an effort to deduplicate machine code
and streamline code flow.

a lot of code is simply moved to eliminate circular imports.  names and
specific paths can ultimately be changed.  i dont like some of the
descriptive interface names, etc.  ultimately, i think once we have the
"old" code sanitized, we can re-use some of those.

clearly some of what is in here is temporary and will either be deleted,
changed, or moved again as this effort comes to a close.

right now, the machine code does not use any of the "new" code.  you
will see in `init` and `rm` some commented out code that hooks it. i'm
afraid things will get worse before they get better (way worse).

[NO NEW TESTS NEEDED]

Signed-off-by: Brent Baude <bbaude@redhat.com>
2024-02-07 08:17:43 -06:00
Paul Holzinger 46fe7ef3bb
use pkg/strongunits from c/common
The code has been moved to c/common so it can be shared with libhvee.

[NO NEW TESTS NEEDED]

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-02-06 16:39:16 +01:00
Brent Baude 1964dbd406 Set up podman machine remote user correctly
The remote user functionality was not quite correct.  This PR breaks out
the accumulation of user descriptions into a separate function.  One
odditiy is ignition must be told to NOT create the core user (or it will
by default) by "adding" the core user with a set bool.

[NO NEW TESTS NEEDED]

Signed-off-by: Brent Baude <bbaude@redhat.com>
2024-01-17 08:57:46 -06:00
openshift-merge-bot[bot] 3b18c77712
Merge pull request #20878 from ashley-cui/winapiforwarding
Add API forwarding support for HyperV
2024-01-08 20:07:23 +00:00
openshift-merge-bot[bot] 1697a8bfcf
Merge pull request #21175 from baude/consolidateIgnitionReadySocket
consolidate ignition ready socket unit
2024-01-06 11:18:57 +00:00
Ashley Cui e3f167f770 Add API forwarding support for HyperV
Provides Docker API client access, allowing compose to work by default
for HyperV. Basically the HyperV equiv of the work done here by #12916.

[NO NEW TESTS NEEDED]

Signed-off-by: Ashley Cui <acui@redhat.com>
2024-01-05 11:45:28 -05:00
Brent Baude a0a541351d consolidate ignition ready socket unit
consolidated ignition ready unit file content into one function.

[NO NEW TESTS NEEDED]

Signed-off-by: Brent Baude <bbaude@redhat.com>
2024-01-05 10:11:43 -06:00
Colin Walters 06064150ea machine: use GlobalDataDir helper
We shouldn't hardcode `~/.local` - we should use the internal
config helper APIs which honor the XDG_DATA_DIR etc. standard
environment variables.

Signed-off-by: Colin Walters <walters@verbum.org>
2024-01-05 10:29:36 -05:00
Jake Correnti 3bfdd79150 Fix init teardown on bad ignition path
Fixes a bug where if a machine failed during init due to a bad ignition path, it would not be properly torn down.

Signed-off-by: Jake Correnti <jakecorrenti+github@proton.me>
2024-01-04 23:47:59 -05:00
Jake Correnti b01a330d37 Use single persistent ssh key for all machines
Changes SSH key behavior such that there is a single persisted key for all
machines across all providers. If there is no key that is located at
`.local/share/containers/podman/machine/` then it is created. The keys are
not deleted when the last machine on the host is removed.

The main motivation for this change is it leads to fewer files created on the
host as a result of vm configuration. Having `n` machines on your system doesn't
result in `2n` machine-related files in `.ssh` on your system anymore.

As a result of ssh keys being persisted by default, the `--save-keys` flag
on `podman machine rm` will no longer be supported.

Signed-off-by: Jake Correnti <jakecorrenti+github@proton.me>
2024-01-04 23:47:49 -05:00
Jake Correnti 98f332d482 Use parser.UnitFile
Uses the systemd unit file parser to build unit files instead of having
them be just blocks of hard-coded strings.

Signed-off-by: Jake Correnti <jakecorrenti+github@proton.me>
2024-01-04 08:51:35 -05:00
Jake Correnti c728eeb39e Create `pkg/machine/ignition` package
Moves all of the ignitionfiles out of the `machine` package and into
its own called `ignition`. This required `VMType` to get moved out of
the `machine` package and into the `define` package in order to prevent
a circular dependency.

Signed-off-by: Jake Correnti <jakecorrenti+github@proton.me>
2024-01-04 08:51:35 -05:00
Oleksandr Redko 2a2d0b0e18 chore: delete obsolete // +build lines
Signed-off-by: Oleksandr Redko <Oleksandr_Redko@epam.com>
2024-01-04 11:53:38 +02:00
Matt Heon 5cc5b43473 Error on HyperV VM start when gvproxy has failed to start
After the VM has successfully started, check that gvproxy is
still running. If it is not, throw an error and refuse to
complete machine start.

[NO NEW TESTS NEEDED] I don't think we can deliberately trigger a
bad gvproxy start without a bad Podman binary. We could try and
kill gvproxy after it starts but before the machine is booted but
that's very prone to races.

Slightly restructure code so that starting shares happens later
and has its own configuration write - so the VM is still recorded
as running if starting shares fails.

Signed-off-by: Matt Heon <mheon@redhat.com>
2023-12-14 13:31:37 -05:00
Brent Baude 3a842027af CheckExclusiveArch should use local JSON too
When performing CheckExclusiveArch, we should get a list of VMs that
exist on disk (JSON).  We should then iterate those and checking if they
are running in HyperV.

[NO NEW TESTS NEEDED]

Signed-off-by: Brent Baude <bbaude@redhat.com>
2023-12-13 14:41:29 -06:00
Brent Baude e5a4f00b7d Podman 5 machine config file - Step 1
The following PR is the very first step in what will a series of steps
to apply a "common" machine configuration file to all providers.
Function names, method names, struct names, and field names are all up
for debate.  The purpose of this PR is to offer a glimpse at the
direction we intend to take.

This PR also contains temporary structs (i.e. aThing) that are not
exported.  These are merely placeholders.

The configuration work in this PR is also unused of yet.  But the code
is compiled.  Once merged, we can begin the next step of development.

[NO NEW TESTS NEEDED]

Signed-off-by: Brent Baude <bbaude@redhat.com>
2023-12-11 16:26:15 -06:00
Christophe Fergeau 6c2a0196a9 machine: usb: Fix 'passtrough' typo
[NO NEW TESTS NEEDED]

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
2023-12-08 12:24:39 +01:00
openshift-merge-bot[bot] 7dd33b307d
Merge pull request #20540 from victortoso/usb-host-passthrough
qemu: add usb host passthrough
2023-11-13 16:03:30 +00:00
openshift-merge-bot[bot] 79eec47f5f
Merge pull request #20626 from jakecorrenti/ignition-builder
Refactor Ignition configuration for virt providers
2023-11-09 19:54:00 +00:00
Jake Correnti 39d647a2f6 Fix socket mapping socket mapping nits
Fixes nits that were suggested in #20420. The caller of
`ListenAndWaitOnSocket` did not use the value returned by the conn
channel, therefore it was better to just close the conn in the
`ListenAndWaitOnSocket` function instead.

[NO NEW TESTS NEEDED]

Signed-off-by: Jake Correnti <jakecorrenti+github@proton.me>
2023-11-09 10:41:50 -05:00