From 7bd5dd42c92e4271421de99f58c8fcb4a586592e Mon Sep 17 00:00:00 2001 From: Jake Correnti Date: Thu, 11 Jan 2024 07:08:10 -0500 Subject: [PATCH] Fix `podman machine set --rootful` for applehv Fixes a bug where a user would be unable to change a rootless machine to rootful. Also makes sure that the podman/docker socket service is updated if the UID or Rootful status of the host user has been updated. [NO NEW TESTS NEEDED] Fixes: #21195 Signed-off-by: Jake Correnti --- pkg/machine/applehv/machine.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/pkg/machine/applehv/machine.go b/pkg/machine/applehv/machine.go index 2ca843c83e..91b9064390 100644 --- a/pkg/machine/applehv/machine.go +++ b/pkg/machine/applehv/machine.go @@ -405,6 +405,15 @@ func (m *MacMachine) writeConfig() error { return os.WriteFile(m.ConfigPath.Path, b, 0644) } +func (m *MacMachine) setRootful(rootful bool) error { + if err := machine.SetRootful(rootful, m.Name, m.Name+"-root"); err != nil { + return err + } + + m.HostUser.Modified = true + return nil +} + func (m *MacMachine) Set(name string, opts machine.SetOptions) ([]error, error) { var setErrors []error @@ -438,6 +447,14 @@ func (m *MacMachine) Set(name string, opts machine.SetOptions) ([]error, error) setErrors = append(setErrors, errors.New("changing USBs not supported for applehv machines")) } + if opts.Rootful != nil && m.Rootful != *opts.Rootful { + if err := m.setRootful(*opts.Rootful); err != nil { + setErrors = append(setErrors, fmt.Errorf("failed to set rootful option: %w", err)) + } else { + m.Rootful = *opts.Rootful + } + } + // Write the machine config to the filesystem err = m.writeConfig() setErrors = append(setErrors, err) @@ -697,6 +714,17 @@ func (m *MacMachine) Start(name string, opts machine.StartOptions) error { m.isIncompatible(), m.Rootful, ) + + // update the podman/docker socket service if the host user has been modified at all (UID or Rootful) + if m.HostUser.Modified { + if machine.UpdatePodmanDockerSockService(m, name, m.UID, m.Rootful) == nil { + // Reset modification state if there are no errors, otherwise ignore errors + // which are already logged + m.HostUser.Modified = false + _ = m.writeConfig() + } + } + return nil }