mirror of https://github.com/status-im/consul.git
command: Data directory permission error message
* Check for invalid data directory permissions * Display appropriate permissions error message * Add command test for bad data directory permissions
This commit is contained in:
parent
140cde6f42
commit
f201b4b565
|
@ -204,6 +204,12 @@ func (c *Command) readConfig() *Config {
|
|||
if config.Server {
|
||||
mdbPath := filepath.Join(config.DataDir, "mdb")
|
||||
if _, err := os.Stat(mdbPath); !os.IsNotExist(err) {
|
||||
if os.IsPermission(err) {
|
||||
c.Ui.Error(fmt.Sprintf("CRITICAL: Permission denied for data folder at %q!", mdbPath))
|
||||
c.Ui.Error("Consul will refuse to boot without access to this directory.")
|
||||
c.Ui.Error("Please correct permissions and try starting again.")
|
||||
return nil
|
||||
}
|
||||
c.Ui.Error(fmt.Sprintf("CRITICAL: Deprecated data folder found at %q!", mdbPath))
|
||||
c.Ui.Error("Consul will refuse to boot with this directory present.")
|
||||
c.Ui.Error("See https://www.consul.io/docs/upgrade-specific.html for more information.")
|
||||
|
|
|
@ -403,3 +403,29 @@ func TestProtectDataDir(t *testing.T) {
|
|||
t.Fatalf("expected mdb dir error, got: %s", out)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBadDataDirPermissions(t *testing.T) {
|
||||
dir, err := ioutil.TempDir("", "consul")
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
dataDir := filepath.Join(dir, "mdb")
|
||||
if err := os.MkdirAll(dataDir, 0400); err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(dataDir)
|
||||
|
||||
ui := new(cli.MockUi)
|
||||
cmd := &Command{
|
||||
Ui: ui,
|
||||
args: []string{"-data-dir=" + dataDir, "-server=true"},
|
||||
}
|
||||
if conf := cmd.readConfig(); conf != nil {
|
||||
t.Fatalf("Should fail with bad data directory permissions")
|
||||
}
|
||||
if out := ui.ErrorWriter.String(); !strings.Contains(out, "Permission denied") {
|
||||
t.Fatalf("expected permission denied error, got: %s", out)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue