Skip to content

Commit

Permalink
Issue #369: Do not allow to run fabio as root
Browse files Browse the repository at this point in the history
Fabio 1.6 will add recurring warning if fabio is run as root (UID == 0)
on UNIX operating systems. It will also add an '-insecure' flag as an
override.

As of version 1.7 fabio will refuse to start as root without the
'-insecure' flag.

Fixes #369
  • Loading branch information
magiconair committed Oct 23, 2017
1 parent ce979fe commit abefccc
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 0 deletions.
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Config struct {
Runtime Runtime
ProfileMode string
ProfilePath string
Insecure bool
}

type CertSource struct {
Expand Down
1 change: 1 addition & 0 deletions config/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ func load(cmdline, environ, envprefix []string, props *properties.Properties) (c
var readTimeout, writeTimeout time.Duration
var gzipContentTypesValue string

f.BoolVar(&cfg.Insecure, "insecure", defaultConfig.Insecure, "allow fabio to run as root when set to true")
f.IntVar(&cfg.Proxy.MaxConn, "proxy.maxconn", defaultConfig.Proxy.MaxConn, "maximum number of cached connections")
f.StringVar(&cfg.Proxy.Strategy, "proxy.strategy", defaultConfig.Proxy.Strategy, "load balancing strategy")
f.StringVar(&cfg.Proxy.Matcher, "proxy.matcher", defaultConfig.Proxy.Matcher, "path matching algorithm")
Expand Down
7 changes: 7 additions & 0 deletions config/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ func TestLoad(t *testing.T) {
desc: "default config",
cfg: func(cfg *Config) *Config { return cfg },
},
{
args: []string{"-insecure=true"},
cfg: func(cfg *Config) *Config {
cfg.Insecure = true
return cfg
},
},
{
args: []string{"-profile.mode", "foo"},
cfg: func(cfg *Config) *Config {
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ func main() {
log.Printf("[INFO] Version %s starting", version)
log.Printf("[INFO] Go runtime is %s", runtime.Version())

WarnIfRunAsRoot(cfg.Insecure)

// setup profiling if enabled
var prof interface {
Stop()
Expand Down
50 changes: 50 additions & 0 deletions rootwarn_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// +build !windows

package main

import (
"log"
"os"
"time"
)

const interval = time.Hour

const warnInsecure = `
************************************************************
You are running fabio as root with the '-insecure' flag
Please check the fabio wiki for alternatives
************************************************************
`

const warn17behavior = `
************************************************************
You are running fabio as root without the '-insecure' flag
This will stop working with fabio 1.7!
************************************************************
`

func WarnIfRunAsRoot(allowRoot bool) {

isRoot := os.Getuid() == 0
if !isRoot {
return
}

warn := warnInsecure
if !allowRoot {
warn = warn17behavior
}

go func() {
for {
log.Printf("[INFO] Running fabio as UID=%d EUID=%d GID=%d", os.Getuid(), os.Geteuid(), os.Getgid())
log.Print("[WARN] ", warn)
time.Sleep(interval)
}
}()
}
7 changes: 7 additions & 0 deletions rootwarn_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// +build windows

package main

func CheckInsecure(allowRoot bool) {
// windows not supported
}

0 comments on commit abefccc

Please sign in to comment.