-
Notifications
You must be signed in to change notification settings - Fork 619
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #377 from fabiolb/issue-369-do-not-run-as-root
Issue #369: Do not allow to run fabio as root
- Loading branch information
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 | ||
} |