Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not set attributes when spawning the getter child #16791

Merged
merged 3 commits into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/16791.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
client: Remove setting attributes when spawning the getter child
```
7 changes: 1 addition & 6 deletions client/allocrunner/taskrunner/getter/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,19 @@ func TestSandbox(t *testing.T) *Sandbox {
}

// SetupDir creates a directory suitable for testing artifact - i.e. it is
// owned by the nobody user as would be the case in a normal client operation.
// owned by the user under which nomad runs.
//
// returns alloc_dir, task_dir
func SetupDir(t *testing.T) (string, string) {
uid, gid := credentials()

allocDir := t.TempDir()
taskDir := filepath.Join(allocDir, "local")
topDir := filepath.Dir(allocDir)

must.NoError(t, os.Chown(topDir, int(uid), int(gid)))
must.NoError(t, os.Chmod(topDir, 0o755))

must.NoError(t, os.Chown(allocDir, int(uid), int(gid)))
must.NoError(t, os.Chmod(allocDir, 0o755))

must.NoError(t, os.Mkdir(taskDir, 0o755))
must.NoError(t, os.Chown(taskDir, int(uid), int(gid)))
must.NoError(t, os.Chmod(taskDir, 0o755))
return allocDir, taskDir
}
1 change: 0 additions & 1 deletion client/allocrunner/taskrunner/getter/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ func (s *Sandbox) runCmd(env *parameters) error {
cmd.Stdin = env.reader()
cmd.Stdout = output
cmd.Stderr = output
cmd.SysProcAttr = attributes()

// start & wait for the subprocess to terminate
if err := cmd.Run(); err != nil {
Expand Down
11 changes: 0 additions & 11 deletions client/allocrunner/taskrunner/getter/util_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,8 @@ package getter

import (
"path/filepath"
"syscall"
)

// attributes is not implemented by default
func attributes() *syscall.SysProcAttr {
return nil
}

// credentials is not implemented by default
func credentials() (uint32, uint32) {
return 0, 0
}

// lockdown is not implemented by default
func lockdown(string, string) error {
return nil
Expand Down
33 changes: 0 additions & 33 deletions client/allocrunner/taskrunner/getter/util_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,12 @@ package getter
import (
"os"
"path/filepath"
"syscall"

"github.com/mitchellh/go-homedir"
"github.com/shoenig/go-landlock"
"golang.org/x/sys/unix"
)

var (
// userUID is the current user's uid
userUID uint32

// userGID is the current user's gid
userGID uint32
)

func init() {
userUID = uint32(syscall.Getuid())
userGID = uint32(syscall.Getgid())
}

// attributes returns the system process attributes to run
// the sandbox process with
func attributes() *syscall.SysProcAttr {
uid, gid := credentials()
return &syscall.SysProcAttr{
Credential: &syscall.Credential{
Uid: uid,
Gid: gid,
},
}
}

// credentials returns the UID and GID of the user the child process
// will run as - for now this is always the same user the Nomad agent is
// running as.
func credentials() (uint32, uint32) {
return userUID, userGID
}

// findHomeDir returns the home directory as provided by os.UserHomeDir. In case
// os.UserHomeDir returns an error, we return /root if the current process is being
// run by root, or /dev/null otherwise.
Expand Down
11 changes: 0 additions & 11 deletions client/allocrunner/taskrunner/getter/util_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,8 @@ package getter
import (
"os"
"path/filepath"
"syscall"
)

// attributes is not implemented on Windows
func attributes() *syscall.SysProcAttr {
return nil
}

// credentials is not implemented on Windows
func credentials() (uint32, uint32) {
return 0, 0
}

// lockdown is not implemented on Windows
func lockdown(string, string) error {
return nil
Expand Down