mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 14:46:42 +00:00
cmd/utils: warn about dangerous configs, abort if unsecure file
This commit is contained in:
parent
20ab9ff430
commit
25f4ffd6aa
1 changed files with 57 additions and 8 deletions
|
|
@ -419,6 +419,14 @@ var (
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// dangerousFlags is a set of flags considered dangerous that the user is warned
|
||||||
|
// about if they are contained within the config file.
|
||||||
|
var dangerousFlags = map[string]string{
|
||||||
|
RPCListenAddrFlag.Name: "May allow ousiders to access your node",
|
||||||
|
WSListenAddrFlag.Name: "May allow ousiders to access your node",
|
||||||
|
IPCPathFlag.Name: "May allow other users/programs to access your node",
|
||||||
|
}
|
||||||
|
|
||||||
// OverrideDefaults parses a config .ini file if one was specified as a CLI flag
|
// OverrideDefaults parses a config .ini file if one was specified as a CLI flag
|
||||||
// and overrides any non-manually set config values.
|
// and overrides any non-manually set config values.
|
||||||
func OverrideDefaults(ctx *cli.Context) {
|
func OverrideDefaults(ctx *cli.Context) {
|
||||||
|
|
@ -438,6 +446,8 @@ func OverrideDefaults(ctx *cli.Context) {
|
||||||
Fatalf("Failed to load initial configurations: %v", err)
|
Fatalf("Failed to load initial configurations: %v", err)
|
||||||
}
|
}
|
||||||
overrides := make(map[string]string)
|
overrides := make(map[string]string)
|
||||||
|
dangerous := make(map[string]string)
|
||||||
|
|
||||||
for _, sec := range cfg.Sections() {
|
for _, sec := range cfg.Sections() {
|
||||||
for _, key := range sec.Keys() {
|
for _, key := range sec.Keys() {
|
||||||
name := key.Name()
|
name := key.Name()
|
||||||
|
|
@ -448,18 +458,57 @@ func OverrideDefaults(ctx *cli.Context) {
|
||||||
overrides[name] = key.Value()
|
overrides[name] = key.Value()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if dangerousFlags[name] != "" {
|
||||||
|
dangerous[name] = key.Value()
|
||||||
|
}
|
||||||
ctx.GlobalSet(name, key.Value())
|
ctx.GlobalSet(name, key.Value())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If config file values were overridden, warn the user
|
// If dangerous flags were specified from a publicly writeable file, abort
|
||||||
if len(overrides) > 0 {
|
if len(dangerous) > 0 {
|
||||||
fmt.Println("Config file values overridden via the CLI:")
|
// Ensure the file itself can only be written by the current user
|
||||||
for key, val := range overrides {
|
info, err := os.Stat(config)
|
||||||
fmt.Printf(" - %s:\n", key)
|
if err != nil {
|
||||||
fmt.Printf(" - Config: %v\n", val)
|
Fatalf("Failed to retrieve config file stats: %v", err)
|
||||||
fmt.Printf(" - Manual: %v\n", ctx.GlobalString(key))
|
|
||||||
}
|
}
|
||||||
fmt.Println()
|
if perms := info.Mode().Perm(); perms&0022 > 0 {
|
||||||
|
Fatalf("Config file contains dangerous flags and is publicly (or group) writeable!")
|
||||||
|
}
|
||||||
|
// Ensure the folder containing the config can only be written by the user
|
||||||
|
info, err = os.Stat(filepath.Dir(config))
|
||||||
|
if err != nil {
|
||||||
|
Fatalf("Failed to retrieve config file parent folder stats: %v", err)
|
||||||
|
}
|
||||||
|
if perms := info.Mode().Perm(); perms&0022 > 0 {
|
||||||
|
Fatalf("Config file contains dangerous flags and containing folder is publicly (or group) writeable!")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Warn the user in case of some weird configuration combos
|
||||||
|
if len(overrides) > 0 || len(dangerous) > 0 {
|
||||||
|
fmt.Println("-----------------------------------------------------------------")
|
||||||
|
|
||||||
|
// If config file values were overridden, warn the user
|
||||||
|
if len(overrides) > 0 {
|
||||||
|
fmt.Println("Config file values overridden via the CLI:")
|
||||||
|
for key, val := range overrides {
|
||||||
|
fmt.Printf(" - %s:\n", key)
|
||||||
|
fmt.Printf(" - Config: %s\n", val)
|
||||||
|
fmt.Printf(" - Manual: %v\n", ctx.GlobalString(key))
|
||||||
|
}
|
||||||
|
fmt.Println()
|
||||||
|
}
|
||||||
|
// If config file contains dangerous flags, warn the user
|
||||||
|
if len(dangerous) > 0 {
|
||||||
|
fmt.Println("Config file contains dangerous flags:")
|
||||||
|
for key, val := range dangerous {
|
||||||
|
fmt.Printf(" - %s:\n", key)
|
||||||
|
fmt.Printf(" - Config: %s\n", val)
|
||||||
|
fmt.Printf(" - Danger: %s\n", dangerousFlags[key])
|
||||||
|
}
|
||||||
|
fmt.Println()
|
||||||
|
fmt.Println("If you don't know what the above flags do, terminate immediately!")
|
||||||
|
}
|
||||||
|
fmt.Println("-----------------------------------------------------------------")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue