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

Issue #369: Do not allow to run fabio as root #377

Merged
merged 1 commit into from
Feb 2, 2018
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
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
8 changes: 8 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ func main() {
log.Printf("[INFO] Version %s starting", version)
log.Printf("[INFO] Go runtime is %s", runtime.Version())

// warn once so that it is at the beginning of the log
// this will also start the reminder go routine if necessary.
WarnIfRunAsRoot(cfg.Insecure)

// setup profiling if enabled
var prof interface {
Stop()
Expand Down Expand Up @@ -125,6 +129,10 @@ func main() {

// create proxies after metrics since they use the metrics registry.
startServers(cfg)

// warn again so that it is visible in the terminal
WarnIfRunAsRoot(cfg.Insecure)

exit.Wait()
log.Print("[INFO] Down")
}
Expand Down
58 changes: 58 additions & 0 deletions rootwarn_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// +build !windows

package main

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

const interval = time.Hour

const warnInsecure = `

************************************************************
You are running fabio as root with the '-insecure' flag
Please check https://fabiolb.net/faq/binding-to-low-ports/
for alternatives.
************************************************************

`

const warn17behavior = `

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

`

var once sync.Once

func WarnIfRunAsRoot(allowRoot bool) {
isRoot := os.Getuid() == 0
if !isRoot {
return
}
doWarn(allowRoot)
once.Do(func() { go remind(allowRoot) })
}

func doWarn(allowRoot bool) {
warn := warnInsecure
if !allowRoot {
warn = warn17behavior
}
log.Printf("[INFO] Running fabio as UID=%d EUID=%d GID=%d", os.Getuid(), os.Geteuid(), os.Getgid())
log.Print("[WARN] ", warn)
}

func remind(allowRoot bool) {
for {
doWarn(allowRoot)
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
}