-
Notifications
You must be signed in to change notification settings - Fork 621
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #369: Do not allow to run fabio as root
Fabio 1.5.7 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
1 parent
8360436
commit 90a9d1c
Showing
6 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |