-
Notifications
You must be signed in to change notification settings - Fork 0
/
rootwarn_unix.go
60 lines (47 loc) · 1.27 KB
/
rootwarn_unix.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// +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) {
// todo(fs): should we emit the same warning when running inside a container?
// todo(fs): check for existence of `/.dockerenv` to determine Docker environment.
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)
}
}