Skip to content

Commit

Permalink
Merge pull request #21280 from openshift-cherrypick-robot/cherry-pick…
Browse files Browse the repository at this point in the history
…-21266-to-v4.9

[v4.9] Set up podman machine remote user correctly
  • Loading branch information
openshift-merge-bot[bot] authored Jan 17, 2024
2 parents 0c9a007 + e679245 commit c638722
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 16 deletions.
2 changes: 1 addition & 1 deletion pkg/machine/applehv/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ func (m *MacMachine) setupAPIForwarding(cmd gvproxy.GvproxyCommand) (gvproxy.Gvp
}

destSock := fmt.Sprintf("/run/user/%d/podman/podman.sock", m.UID)
forwardUser := "core"
forwardUser := m.RemoteUsername

if m.Rootful {
destSock = "/run/podman/podman.sock"
Expand Down
2 changes: 1 addition & 1 deletion pkg/machine/hyperv/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ func (m *HyperVMachine) setupAPIForwarding(cmd gvproxy.GvproxyCommand) (gvproxy.
}

destSock := fmt.Sprintf("/run/user/%d/podman/podman.sock", m.UID)
forwardUser := "core"
forwardUser := m.RemoteUsername

if m.Rootful {
destSock = "/run/podman/podman.sock"
Expand Down
58 changes: 46 additions & 12 deletions pkg/machine/ignition.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,51 @@ func (ign *DynamicIgnition) Write() error {
return os.WriteFile(ign.WritePath, b, 0644)
}

func (ign *DynamicIgnition) getUsers() []PasswdUser {
var (
users []PasswdUser
)

isCoreUser := ign.Name == DefaultIgnitionUserName

// if we are not using the 'core' user, we need to tell ignition to
// not add it
if !isCoreUser {
coreUser := PasswdUser{
Name: DefaultIgnitionUserName,
ShouldExist: BoolToPtr(false),
}
users = append(users, coreUser)
}

// Adding the user
user := PasswdUser{
Name: ign.Name,
SSHAuthorizedKeys: []SSHAuthorizedKey{SSHAuthorizedKey(ign.Key)},
UID: IntToPtr(ign.UID),
}

// If we are not using the core user, we need to make the user part
// of the following groups
if !isCoreUser {
user.Groups = []Group{
Group("sudo"),
Group("adm"),
Group("wheel"),
Group("systemd-journal")}
}

// set root SSH key
root := PasswdUser{
Name: "root",
SSHAuthorizedKeys: []SSHAuthorizedKey{SSHAuthorizedKey(ign.Key)},
}
// add them all in
users = append(users, user, root)

return users
}

// GenerateIgnitionConfig
func (ign *DynamicIgnition) GenerateIgnitionConfig() error {
if len(ign.Name) < 1 {
Expand All @@ -84,18 +129,7 @@ func (ign *DynamicIgnition) GenerateIgnitionConfig() error {
Version: "3.2.0",
}
ignPassword := Passwd{
Users: []PasswdUser{
{
Name: ign.Name,
SSHAuthorizedKeys: []SSHAuthorizedKey{SSHAuthorizedKey(ign.Key)},
// Set the UID of the core user inside the machine
UID: IntToPtr(ign.UID),
},
{
Name: "root",
SSHAuthorizedKeys: []SSHAuthorizedKey{SSHAuthorizedKey(ign.Key)},
},
},
Users: ign.getUsers(),
}

ignStorage := Storage{
Expand Down
5 changes: 3 additions & 2 deletions pkg/machine/qemu/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -1265,8 +1265,8 @@ func (v *MachineVM) startHostNetworking() (string, machine.APIForwardingState, e
cmd.Debug = true
logrus.Debug(cmd)
}

c := cmd.Cmd(binary)
logrus.Debugf("gvproxy args: %v", c.Args)
if err := c.Start(); err != nil {
return "", 0, fmt.Errorf("unable to execute: %q: %w", cmd.ToCmdline(), err)
}
Expand All @@ -1281,7 +1281,8 @@ func (v *MachineVM) setupAPIForwarding(cmd gvproxy.GvproxyCommand) (gvproxy.Gvpr
}

destSock := fmt.Sprintf("/run/user/%d/podman/podman.sock", v.UID)
forwardUser := "core"

forwardUser := v.RemoteUsername

if v.Rootful {
destSock = "/run/podman/podman.sock"
Expand Down

0 comments on commit c638722

Please sign in to comment.