Add config CLI command and encrypt/decrypt sub-commands (#77)

This commit is contained in:
Jeff Malnick authored and GitHub committed 2020-06-24 16:08:13 -04:00
1 parent 8de5371499
commit 8afcbd4c8e
12 files changed
+509 -49

No files matched your search

+21 -2
View File
@@ -8,6 +8,7 @@ import (
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-multierror"
"github.com/hashicorp/vault/internalshared/configutil"
"github.com/hashicorp/vault/sdk/helper/mlock"
"github.com/hashicorp/vault/sdk/helper/strutil"
"github.com/hashicorp/watchtower/globals"
@@ -36,6 +37,8 @@ type Command struct {
Config *config.Config
controller *controller.Controller
configKMS *configutil.KMS
flagConfig string
flagLogLevel string
flagLogFormat string
@@ -288,6 +291,22 @@ func (c *Command) ParseFlagsAndConfig(args []string) int {
return 1
}
// preload the KMS for encrypting/decrypting the config parameters
kmss, err := configutil.LoadConfigKMSes(c.flagConfig)
if err != nil {
c.UI.Error("error loading KMS config: " + err.Error())
return 1
}
for _, kms := range kmss {
for _, purpose := range kms.Purpose {
if purpose == "config" {
c.configKMS = kms
break
}
}
}
// Validation
if !c.flagDev {
switch {
@@ -301,7 +320,7 @@ func (c *Command) ParseFlagsAndConfig(args []string) int {
c.flagDevAdminPassword = ""
}
c.Config, err = config.LoadFile(c.flagConfig)
c.Config, err = config.LoadFile(c.flagConfig, c.configKMS)
if err != nil {
c.UI.Error("Error parsing config: " + err.Error())
return 1
@@ -410,7 +429,7 @@ func (c *Command) WaitForInterrupt() int {
goto RUNRELOADFUNCS
}
newConf, err = config.LoadFile(c.flagConfig)
newConf, err = config.LoadFile(c.flagConfig, c.configKMS)
if err != nil {
c.Logger.Error("could not reload config", "path", c.flagConfig, "error", err)
goto RUNRELOADFUNCS