Use authenticate and Auth Method repo functions (#242)

This commit is contained in:
Todd Knight authored and GitHub committed 2020-08-07 10:18:40 -07:00
1 parent 908a299ea3
commit f84991c0f1
17 files changed
+324 -184

No files matched your search

+31 -9
View File
@@ -12,6 +12,7 @@ import (
"github.com/hashicorp/vault/sdk/helper/mlock"
"github.com/hashicorp/vault/sdk/helper/strutil"
"github.com/hashicorp/watchtower/globals"
"github.com/hashicorp/watchtower/internal/auth/password"
"github.com/hashicorp/watchtower/internal/cmd/base"
"github.com/hashicorp/watchtower/internal/cmd/config"
"github.com/hashicorp/watchtower/internal/servers/controller"
@@ -44,7 +45,8 @@ type Command struct {
flagLogFormat string
flagCombineLogs bool
flagDev bool
flagDevAdminPassword string
flagDevUsername string
flagDevPassword string
flagDevControllerAPIListenAddr string
flagDevControllerClusterListenAddr string
flagDevOrgId string
@@ -129,13 +131,21 @@ func (c *Command) Flags() *base.FlagSets {
})
f.StringVar(&base.StringVar{
Name: "dev-admin-password",
Target: &c.flagDevAdminPassword,
EnvVar: "WATCHTWER_DEV_ADMIN_PASSWORD",
Name: "dev-password",
Target: &c.flagDevPassword,
EnvVar: "WATCHTWER_DEV_PASSWORD",
Usage: "Initial admin password. This only applies when running in \"dev\" " +
"mode.",
})
f.StringVar(&base.StringVar{
Name: "dev-username",
Target: &c.flagDevUsername,
EnvVar: "WATCHTWER_DEV_USERNAME",
Usage: "Initial admin username. This only applies when running in \"dev\" " +
"mode.",
})
f.StringVar(&base.StringVar{
Name: "dev-api-listen-address",
Target: &c.flagDevControllerAPIListenAddr,
@@ -322,11 +332,16 @@ func (c *Command) ParseFlagsAndConfig(args []string) int {
case len(c.flagConfig) == 0:
c.UI.Error("Must specify a config file using -config")
return 1
case c.flagDevAdminPassword != "":
case c.flagDevPassword != "":
c.UI.Warn(base.WrapAtLength(
"You cannot specify a custom admin password outside of \"dev\" mode. " +
"Your request has been ignored."))
c.flagDevAdminPassword = ""
c.flagDevPassword = ""
case c.flagDevUsername != "":
c.UI.Warn(base.WrapAtLength(
"You cannot specify a custom admin username outside of \"dev\" mode. " +
"Your request has been ignored."))
c.flagDevUsername = ""
}
c.Config, err = config.LoadFile(c.flagConfig, c.configKMS)
@@ -346,16 +361,23 @@ func (c *Command) ParseFlagsAndConfig(args []string) int {
c.Config.DefaultOrgId = c.flagDevOrgId
}
if c.flagDevAuthMethodId != "" {
if !strings.HasPrefix(c.flagDevAuthMethodId, "am_") {
c.UI.Error(fmt.Sprintf("Invalid dev auth method ID, must start with %q", "am_"))
prefix := password.AuthMethodPrefix + "_"
if !strings.HasPrefix(c.flagDevAuthMethodId, prefix) {
c.UI.Error(fmt.Sprintf("Invalid dev auth method ID, must start with %q", prefix))
return 1
}
if len(c.flagDevAuthMethodId) != 13 {
c.UI.Error(fmt.Sprintf("Invalid dev auth method ID, must be 10 base62 characters after %q", "am_"))
c.UI.Error(fmt.Sprintf("Invalid dev auth method ID, must be 10 base62 characters after %q", prefix))
return 1
}
c.DevAuthMethodId = c.flagDevAuthMethodId
}
if c.flagDevUsername != "" {
c.DevUsername = c.flagDevUsername
}
if c.flagDevPassword != "" {
c.DevPassword = c.flagDevPassword
}
c.Config.PassthroughDirectory = c.flagDevPassthroughDirectory