2015-04-02 00:09:11 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
2016-04-01 17:16:05 +00:00
|
|
|
|
2017-02-16 16:37:27 +00:00
|
|
|
"github.com/hashicorp/vault/api"
|
2017-09-05 03:59:39 +00:00
|
|
|
"github.com/mitchellh/cli"
|
2017-08-24 22:23:40 +00:00
|
|
|
"github.com/posener/complete"
|
2015-04-02 00:09:11 +00:00
|
|
|
)
|
|
|
|
|
2017-09-05 03:59:39 +00:00
|
|
|
// Ensure we are implementing the right interfaces.
|
|
|
|
var _ cli.Command = (*AuthEnableCommand)(nil)
|
|
|
|
var _ cli.CommandAutocomplete = (*AuthEnableCommand)(nil)
|
|
|
|
|
2015-04-02 00:09:11 +00:00
|
|
|
// AuthEnableCommand is a Command that enables a new endpoint.
|
|
|
|
type AuthEnableCommand struct {
|
2017-09-05 03:59:39 +00:00
|
|
|
*BaseCommand
|
|
|
|
|
|
|
|
flagDescription string
|
|
|
|
flagPath string
|
|
|
|
flagPluginName string
|
|
|
|
flagLocal bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *AuthEnableCommand) Synopsis() string {
|
|
|
|
return "Enables a new auth provider"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *AuthEnableCommand) Help() string {
|
|
|
|
helpText := `
|
|
|
|
Usage: vault auth-enable [options] TYPE
|
|
|
|
|
|
|
|
Enables a new authentication provider. An authentication provider is
|
|
|
|
responsible for authenticating users or machiens and assigning them
|
|
|
|
policies with which they can access Vault.
|
|
|
|
|
|
|
|
Enable the userpass auth provider at userpass/:
|
|
|
|
|
|
|
|
$ vault auth-enable userpass
|
|
|
|
|
|
|
|
Enable the LDAP auth provider at auth-prod/:
|
|
|
|
|
|
|
|
$ vault auth-enable -path=auth-prod ldap
|
|
|
|
|
|
|
|
Enable a custom auth plugin (after it is registered in the plugin registry):
|
|
|
|
|
|
|
|
$ vault auth-enable -path=my-auth -plugin-name=my-auth-plugin plugin
|
|
|
|
|
|
|
|
For a full list of examples, please see the documentation.
|
|
|
|
|
|
|
|
` + c.Flags().Help()
|
|
|
|
|
|
|
|
return strings.TrimSpace(helpText)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *AuthEnableCommand) Flags() *FlagSets {
|
|
|
|
set := c.flagSet(FlagSetHTTP)
|
|
|
|
|
|
|
|
f := set.NewFlagSet("Command Options")
|
|
|
|
|
|
|
|
f.StringVar(&StringVar{
|
|
|
|
Name: "description",
|
|
|
|
Target: &c.flagDescription,
|
|
|
|
Completion: complete.PredictAnything,
|
|
|
|
Usage: "Human-friendly description for the purpose of this " +
|
|
|
|
"authentication provider.",
|
|
|
|
})
|
|
|
|
|
|
|
|
f.StringVar(&StringVar{
|
|
|
|
Name: "path",
|
|
|
|
Target: &c.flagPath,
|
|
|
|
Default: "", // The default is complex, so we have to manually document
|
|
|
|
Completion: complete.PredictAnything,
|
|
|
|
Usage: "Place where the auth provider will be accessible. This must be " +
|
|
|
|
"unique across all auth providers. This defaults to the \"type\" of " +
|
|
|
|
"the mount. The auth provider will be accessible at \"/auth/<path>\".",
|
|
|
|
})
|
|
|
|
|
|
|
|
f.StringVar(&StringVar{
|
|
|
|
Name: "plugin-name",
|
|
|
|
Target: &c.flagPluginName,
|
|
|
|
Completion: complete.PredictAnything,
|
|
|
|
Usage: "Name of the auth provider plugin. This plugin name must already " +
|
|
|
|
"exist in the Vault server's plugin catalog.",
|
|
|
|
})
|
|
|
|
|
|
|
|
f.BoolVar(&BoolVar{
|
|
|
|
Name: "local",
|
|
|
|
Target: &c.flagLocal,
|
|
|
|
Default: false,
|
|
|
|
Usage: "Mark the auth provider as local-only. Local auth providers are " +
|
|
|
|
"not replicated nor removed by replication.",
|
|
|
|
})
|
|
|
|
|
|
|
|
return set
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *AuthEnableCommand) AutocompleteArgs() complete.Predictor {
|
|
|
|
return c.PredictVaultAvailableAuths()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *AuthEnableCommand) AutocompleteFlags() complete.Flags {
|
|
|
|
return c.Flags().Completions()
|
2015-04-02 00:09:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *AuthEnableCommand) Run(args []string) int {
|
2017-09-05 03:59:39 +00:00
|
|
|
f := c.Flags()
|
|
|
|
|
|
|
|
if err := f.Parse(args); err != nil {
|
|
|
|
c.UI.Error(err.Error())
|
2015-04-02 00:09:11 +00:00
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2017-09-05 03:59:39 +00:00
|
|
|
args = f.Args()
|
|
|
|
switch {
|
|
|
|
case len(args) < 1:
|
|
|
|
c.UI.Error(fmt.Sprintf("Not enough arguments (expected 1, got %d)", len(args)))
|
|
|
|
return 1
|
|
|
|
case len(args) > 1:
|
|
|
|
c.UI.Error(fmt.Sprintf("Too many arguments (expected 1, got %d)", len(args)))
|
2015-04-02 00:09:11 +00:00
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2017-09-05 03:59:39 +00:00
|
|
|
client, err := c.Client()
|
|
|
|
if err != nil {
|
|
|
|
c.UI.Error(err.Error())
|
|
|
|
return 2
|
|
|
|
}
|
|
|
|
|
|
|
|
authType := strings.TrimSpace(args[0])
|
2015-04-02 00:09:11 +00:00
|
|
|
|
|
|
|
// If no path is specified, we default the path to the backend type
|
Backend plugin system (#2874)
* Add backend plugin changes
* Fix totp backend plugin tests
* Fix logical/plugin InvalidateKey test
* Fix plugin catalog CRUD test, fix NoopBackend
* Clean up commented code block
* Fix system backend mount test
* Set plugin_name to omitempty, fix handleMountTable config parsing
* Clean up comments, keep shim connections alive until cleanup
* Include pluginClient, disallow LookupPlugin call from within a plugin
* Add wrapper around backendPluginClient for proper cleanup
* Add logger shim tests
* Add logger, storage, and system shim tests
* Use pointer receivers for system view shim
* Use plugin name if no path is provided on mount
* Enable plugins for auth backends
* Add backend type attribute, move builtin/plugin/package
* Fix merge conflict
* Fix missing plugin name in mount config
* Add integration tests on enabling auth backend plugins
* Remove dependency cycle on mock-plugin
* Add passthrough backend plugin, use logical.BackendType to determine lease generation
* Remove vault package dependency on passthrough package
* Add basic impl test for passthrough plugin
* Incorporate feedback; set b.backend after shims creation on backendPluginServer
* Fix totp plugin test
* Add plugin backends docs
* Fix tests
* Fix builtin/plugin tests
* Remove flatten from PluginRunner fields
* Move mock plugin to logical/plugin, remove totp and passthrough plugins
* Move pluginMap into newPluginClient
* Do not create storage RPC connection on HandleRequest and HandleExistenceCheck
* Change shim logger's Fatal to no-op
* Change BackendType to uint32, match UX backend types
* Change framework.Backend Setup signature
* Add Setup func to logical.Backend interface
* Move OptionallyEnableMlock call into plugin.Serve, update docs and comments
* Remove commented var in plugin package
* RegisterLicense on logical.Backend interface (#3017)
* Add RegisterLicense to logical.Backend interface
* Update RegisterLicense to use callback func on framework.Backend
* Refactor framework.Backend.RegisterLicense
* plugin: Prevent plugin.SystemViewClient.ResponseWrapData from getting JWTs
* plugin: Revert BackendType to remove TypePassthrough and related references
* Fix typo in plugin backends docs
2017-07-20 17:28:40 +00:00
|
|
|
// or use the plugin name if it's a plugin backend
|
2017-09-05 03:59:39 +00:00
|
|
|
authPath := c.flagPath
|
|
|
|
if authPath == "" {
|
Backend plugin system (#2874)
* Add backend plugin changes
* Fix totp backend plugin tests
* Fix logical/plugin InvalidateKey test
* Fix plugin catalog CRUD test, fix NoopBackend
* Clean up commented code block
* Fix system backend mount test
* Set plugin_name to omitempty, fix handleMountTable config parsing
* Clean up comments, keep shim connections alive until cleanup
* Include pluginClient, disallow LookupPlugin call from within a plugin
* Add wrapper around backendPluginClient for proper cleanup
* Add logger shim tests
* Add logger, storage, and system shim tests
* Use pointer receivers for system view shim
* Use plugin name if no path is provided on mount
* Enable plugins for auth backends
* Add backend type attribute, move builtin/plugin/package
* Fix merge conflict
* Fix missing plugin name in mount config
* Add integration tests on enabling auth backend plugins
* Remove dependency cycle on mock-plugin
* Add passthrough backend plugin, use logical.BackendType to determine lease generation
* Remove vault package dependency on passthrough package
* Add basic impl test for passthrough plugin
* Incorporate feedback; set b.backend after shims creation on backendPluginServer
* Fix totp plugin test
* Add plugin backends docs
* Fix tests
* Fix builtin/plugin tests
* Remove flatten from PluginRunner fields
* Move mock plugin to logical/plugin, remove totp and passthrough plugins
* Move pluginMap into newPluginClient
* Do not create storage RPC connection on HandleRequest and HandleExistenceCheck
* Change shim logger's Fatal to no-op
* Change BackendType to uint32, match UX backend types
* Change framework.Backend Setup signature
* Add Setup func to logical.Backend interface
* Move OptionallyEnableMlock call into plugin.Serve, update docs and comments
* Remove commented var in plugin package
* RegisterLicense on logical.Backend interface (#3017)
* Add RegisterLicense to logical.Backend interface
* Update RegisterLicense to use callback func on framework.Backend
* Refactor framework.Backend.RegisterLicense
* plugin: Prevent plugin.SystemViewClient.ResponseWrapData from getting JWTs
* plugin: Revert BackendType to remove TypePassthrough and related references
* Fix typo in plugin backends docs
2017-07-20 17:28:40 +00:00
|
|
|
if authType == "plugin" {
|
2017-09-05 03:59:39 +00:00
|
|
|
authPath = c.flagPluginName
|
Backend plugin system (#2874)
* Add backend plugin changes
* Fix totp backend plugin tests
* Fix logical/plugin InvalidateKey test
* Fix plugin catalog CRUD test, fix NoopBackend
* Clean up commented code block
* Fix system backend mount test
* Set plugin_name to omitempty, fix handleMountTable config parsing
* Clean up comments, keep shim connections alive until cleanup
* Include pluginClient, disallow LookupPlugin call from within a plugin
* Add wrapper around backendPluginClient for proper cleanup
* Add logger shim tests
* Add logger, storage, and system shim tests
* Use pointer receivers for system view shim
* Use plugin name if no path is provided on mount
* Enable plugins for auth backends
* Add backend type attribute, move builtin/plugin/package
* Fix merge conflict
* Fix missing plugin name in mount config
* Add integration tests on enabling auth backend plugins
* Remove dependency cycle on mock-plugin
* Add passthrough backend plugin, use logical.BackendType to determine lease generation
* Remove vault package dependency on passthrough package
* Add basic impl test for passthrough plugin
* Incorporate feedback; set b.backend after shims creation on backendPluginServer
* Fix totp plugin test
* Add plugin backends docs
* Fix tests
* Fix builtin/plugin tests
* Remove flatten from PluginRunner fields
* Move mock plugin to logical/plugin, remove totp and passthrough plugins
* Move pluginMap into newPluginClient
* Do not create storage RPC connection on HandleRequest and HandleExistenceCheck
* Change shim logger's Fatal to no-op
* Change BackendType to uint32, match UX backend types
* Change framework.Backend Setup signature
* Add Setup func to logical.Backend interface
* Move OptionallyEnableMlock call into plugin.Serve, update docs and comments
* Remove commented var in plugin package
* RegisterLicense on logical.Backend interface (#3017)
* Add RegisterLicense to logical.Backend interface
* Update RegisterLicense to use callback func on framework.Backend
* Refactor framework.Backend.RegisterLicense
* plugin: Prevent plugin.SystemViewClient.ResponseWrapData from getting JWTs
* plugin: Revert BackendType to remove TypePassthrough and related references
* Fix typo in plugin backends docs
2017-07-20 17:28:40 +00:00
|
|
|
} else {
|
2017-09-05 03:59:39 +00:00
|
|
|
authPath = authType
|
Backend plugin system (#2874)
* Add backend plugin changes
* Fix totp backend plugin tests
* Fix logical/plugin InvalidateKey test
* Fix plugin catalog CRUD test, fix NoopBackend
* Clean up commented code block
* Fix system backend mount test
* Set plugin_name to omitempty, fix handleMountTable config parsing
* Clean up comments, keep shim connections alive until cleanup
* Include pluginClient, disallow LookupPlugin call from within a plugin
* Add wrapper around backendPluginClient for proper cleanup
* Add logger shim tests
* Add logger, storage, and system shim tests
* Use pointer receivers for system view shim
* Use plugin name if no path is provided on mount
* Enable plugins for auth backends
* Add backend type attribute, move builtin/plugin/package
* Fix merge conflict
* Fix missing plugin name in mount config
* Add integration tests on enabling auth backend plugins
* Remove dependency cycle on mock-plugin
* Add passthrough backend plugin, use logical.BackendType to determine lease generation
* Remove vault package dependency on passthrough package
* Add basic impl test for passthrough plugin
* Incorporate feedback; set b.backend after shims creation on backendPluginServer
* Fix totp plugin test
* Add plugin backends docs
* Fix tests
* Fix builtin/plugin tests
* Remove flatten from PluginRunner fields
* Move mock plugin to logical/plugin, remove totp and passthrough plugins
* Move pluginMap into newPluginClient
* Do not create storage RPC connection on HandleRequest and HandleExistenceCheck
* Change shim logger's Fatal to no-op
* Change BackendType to uint32, match UX backend types
* Change framework.Backend Setup signature
* Add Setup func to logical.Backend interface
* Move OptionallyEnableMlock call into plugin.Serve, update docs and comments
* Remove commented var in plugin package
* RegisterLicense on logical.Backend interface (#3017)
* Add RegisterLicense to logical.Backend interface
* Update RegisterLicense to use callback func on framework.Backend
* Refactor framework.Backend.RegisterLicense
* plugin: Prevent plugin.SystemViewClient.ResponseWrapData from getting JWTs
* plugin: Revert BackendType to remove TypePassthrough and related references
* Fix typo in plugin backends docs
2017-07-20 17:28:40 +00:00
|
|
|
}
|
2015-04-02 00:09:11 +00:00
|
|
|
}
|
|
|
|
|
2017-09-05 03:59:39 +00:00
|
|
|
// Append a trailing slash to indicate it's a path in output
|
|
|
|
authPath = ensureTrailingSlash(authPath)
|
2015-04-02 00:09:11 +00:00
|
|
|
|
2017-09-05 03:59:39 +00:00
|
|
|
if err := client.Sys().EnableAuthWithOptions(authPath, &api.EnableAuthOptions{
|
2017-02-16 16:37:27 +00:00
|
|
|
Type: authType,
|
2017-09-05 03:59:39 +00:00
|
|
|
Description: c.flagDescription,
|
2017-08-31 16:16:59 +00:00
|
|
|
Config: api.AuthConfigInput{
|
2017-09-05 03:59:39 +00:00
|
|
|
PluginName: c.flagPluginName,
|
2017-08-31 16:16:59 +00:00
|
|
|
},
|
2017-09-05 03:59:39 +00:00
|
|
|
Local: c.flagLocal,
|
2017-02-16 16:37:27 +00:00
|
|
|
}); err != nil {
|
2017-09-05 03:59:39 +00:00
|
|
|
c.UI.Error(fmt.Sprintf("Error enabling %s auth: %s", authType, err))
|
2015-04-02 00:09:11 +00:00
|
|
|
return 2
|
|
|
|
}
|
|
|
|
|
2017-09-05 03:59:39 +00:00
|
|
|
authThing := authType + " auth provider"
|
2017-08-16 18:31:16 +00:00
|
|
|
if authType == "plugin" {
|
2017-09-05 03:59:39 +00:00
|
|
|
authThing = c.flagPluginName + " plugin"
|
2017-08-16 18:31:16 +00:00
|
|
|
}
|
|
|
|
|
2017-09-05 03:59:39 +00:00
|
|
|
c.UI.Output(fmt.Sprintf("Success! Enabled %s at: %s", authThing, authPath))
|
2015-04-02 00:09:11 +00:00
|
|
|
return 0
|
|
|
|
}
|