Disable exec/java/qemu when non-root on non-windows OSes

This commit is contained in:
Alex Dadgar 2015-09-22 16:32:05 -07:00
parent 6ffdc6745f
commit dd0a76a9d7
3 changed files with 21 additions and 1 deletions

View file

@ -2,7 +2,9 @@ package driver
import (
"fmt"
"runtime"
"strings"
"syscall"
"time"
"github.com/hashicorp/nomad/client/config"
@ -30,7 +32,11 @@ func NewExecDriver(ctx *DriverContext) Driver {
}
func (d *ExecDriver) Fingerprint(cfg *config.Config, node *structs.Node) (bool, error) {
// We can always do a fork/exec
// Only enable if we are root when running on non-windows systems.
if runtime.GOOS != "windows" && syscall.Geteuid() != 0 {
return false, nil
}
node.Attributes["driver.exec"] = "1"
return true, nil
}

View file

@ -9,7 +9,9 @@ import (
"os/exec"
"path"
"path/filepath"
"runtime"
"strings"
"syscall"
"time"
"github.com/hashicorp/nomad/client/config"
@ -36,6 +38,11 @@ func NewJavaDriver(ctx *DriverContext) Driver {
}
func (d *JavaDriver) Fingerprint(cfg *config.Config, node *structs.Node) (bool, error) {
// Only enable if we are root when running on non-windows systems.
if runtime.GOOS != "windows" && syscall.Geteuid() != 0 {
return false, nil
}
// Find java version
var out bytes.Buffer
var erOut bytes.Buffer

View file

@ -13,7 +13,9 @@ import (
"os/exec"
"path/filepath"
"regexp"
"runtime"
"strings"
"syscall"
"time"
"github.com/hashicorp/nomad/client/config"
@ -52,6 +54,11 @@ func NewQemuDriver(ctx *DriverContext) Driver {
}
func (d *QemuDriver) Fingerprint(cfg *config.Config, node *structs.Node) (bool, error) {
// Only enable if we are root when running on non-windows systems.
if runtime.GOOS != "windows" && syscall.Geteuid() != 0 {
return false, nil
}
outBytes, err := exec.Command("qemu-system-x86_64", "-version").Output()
if err != nil {
return false, nil