Skip to content

Commit

Permalink
Disp: Do not allow running as root
Browse files Browse the repository at this point in the history
Modify also BR/SIG to avoid package shadowing

Fixes scionproto#3067
  • Loading branch information
karampok committed Sep 2, 2019
1 parent 5276b4c commit 394f566
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
4 changes: 2 additions & 2 deletions go/border/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ func setup() error {
}

func checkPerms() error {
user, err := user.Current()
u, err := user.Current()
if err != nil {
return common.NewBasicError("Error retrieving user", err)
}
if user.Uid == "0" {
if u.Uid == "0" {
return common.NewBasicError("Running as root is not allowed for security reasons", nil)
}
return nil
Expand Down
1 change: 1 addition & 0 deletions go/godispatcher/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ go_library(
"//go/godispatcher/internal/config:go_default_library",
"//go/godispatcher/internal/metrics:go_default_library",
"//go/godispatcher/network:go_default_library",
"//go/lib/common:go_default_library",
"//go/lib/env:go_default_library",
"//go/lib/fatal:go_default_library",
"//go/lib/log:go_default_library",
Expand Down
18 changes: 18 additions & 0 deletions go/godispatcher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ import (
"net/http"
_ "net/http/pprof"
"os"
"os/user"

"github.com/BurntSushi/toml"

"github.com/scionproto/scion/go/godispatcher/internal/config"
"github.com/scionproto/scion/go/godispatcher/internal/metrics"
"github.com/scionproto/scion/go/godispatcher/network"
"github.com/scionproto/scion/go/lib/common"
"github.com/scionproto/scion/go/lib/env"
"github.com/scionproto/scion/go/lib/fatal"
"github.com/scionproto/scion/go/lib/log"
Expand Down Expand Up @@ -60,6 +62,11 @@ func realMain() int {
return 1
}

if err := checkPerms(); err != nil {
log.Crit("Permissions checks failed", "err", err)
return 1
}

if err := util.CreateParentDirs(cfg.Dispatcher.ApplicationSocket); err != nil {
log.Crit("Unable to create directory tree for socket", "err", err)
return 1
Expand Down Expand Up @@ -154,3 +161,14 @@ func waitForTeardown() int {
return 1
}
}

func checkPerms() error {
u, err := user.Current()
if err != nil {
return common.NewBasicError("Error retrieving user", err)
}
if u.Uid == "0" {
return common.NewBasicError("Running as root is not allowed for security reasons", nil)
}
return nil
}
4 changes: 2 additions & 2 deletions go/sig/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,11 @@ func setupIngress(tunIO io.ReadWriteCloser) {
}

func checkPerms() error {
user, err := user.Current()
u, err := user.Current()
if err != nil {
return common.NewBasicError("Error retrieving user", err)
}
if user.Uid == "0" {
if u.Uid == "0" {
return common.NewBasicError("Running as root is not allowed for security reasons", nil)
}
caps, err := capability.NewPid(0)
Expand Down

0 comments on commit 394f566

Please sign in to comment.