os.StartProcess() not allowing for sudo commands in golang

Viewed 262

I am trying to start a new process from within a rootless golang program, give that process root privileges, and execute a command using sudo. However, I am getting the following output:

sudo: /etc/sudo.conf is owned by uid 65534, should be 0
sudo: /etc/sudo.conf is owned by uid 65534, should be 0
sudo: error in /etc/sudo.conf, line 0 while loading plugin "sudoers_policy"
sudo: /usr/libexec/sudo/sudoers.so must be owned by uid 0
sudo: fatal error, unable to load plugins
exit status 1

Which I am assuming means I need to chown some files temporarily in order to have sudo access. Is this process possible? here is my StartProcess code currently

cred := &syscall.Credential{0, 0, []uint32{}, false}
sys := &syscall.SysProcAttr{Credential: cred, Noctty: false}
attr := os.ProcAttr{Env: os.Environ(), Files: []*os.File{os.Stdin, os.Stdout, os.Stderr}, Sys: sys}
proc, err := os.StartProcess("/bin/sudo", []string{"/bin/podman", "image", "load", "--input=" + scpOpts.Save.Output}, &attr)
if err != nil {
    return err
}

state, err := proc.Wait()
if err != nil {
    return err
}

fmt.Println(state.String())
1 Answers

Check first the ownership on your /etc folder: setting it back to root (as in here) should help.

You had a similar podman issue which illustrates the importance of user ownership.

The OP cbd123 confirms in the comments:

My issue was that I was not gid or uid mapping properly.

I got it to work except for hte fact that syscall.CLONE_NEWUSER has some issues where it triggers an invalid argument error due to the max_user_namespace file.

Related