Add a helper functions for checking unix root

This commit is contained in:
Mahmood Ali 2018-11-07 11:53:11 -08:00
parent 21d126cd68
commit 032f86bc78
3 changed files with 13 additions and 2 deletions

View File

@ -22,7 +22,6 @@ import (
"github.com/hashicorp/nomad/plugins/shared/hclspec"
"github.com/hashicorp/nomad/plugins/shared/loader"
"golang.org/x/net/context"
"golang.org/x/sys/unix"
)
const (
@ -207,7 +206,7 @@ func (d *Driver) buildFingerprint() *drivers.Fingerprint {
return fp
}
if unix.Geteuid() != 0 {
if !utils.IsUnixRoot() {
fp.Health = drivers.HealthStateUnhealthy
fp.HealthDescription = "exec driver must run as root"
return fp

View File

@ -5,6 +5,8 @@ package utils
import (
"os/exec"
"syscall"
"golang.org/x/sys/unix"
)
// isolateCommand sets the setsid flag in exec.Cmd to true so that the process
@ -16,3 +18,8 @@ func isolateCommand(cmd *exec.Cmd) {
}
cmd.SysProcAttr.Setsid = true
}
// IsUnixRoot returns true if system is unix and user running is effectively root
func IsUnixRoot() bool {
return unix.Geteuid() == 0
}

View File

@ -6,3 +6,8 @@ import (
// TODO Figure out if this is needed in Windows
func isolateCommand(cmd *exec.Cmd) {}
// IsUnixRoot returns true if system is a unix system and the effective uid of user is root
func IsUnixRoot() bool {
return false
}