2015-06-30 03:29:41 +00:00
|
|
|
package cert
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/hashicorp/vault/api"
|
|
|
|
"github.com/mitchellh/mapstructure"
|
|
|
|
)
|
|
|
|
|
|
|
|
type CLIHandler struct{}
|
|
|
|
|
2017-08-31 20:57:00 +00:00
|
|
|
func (h *CLIHandler) Auth(c *api.Client, m map[string]string) (*api.Secret, error) {
|
2015-06-30 03:29:41 +00:00
|
|
|
var data struct {
|
2015-12-08 04:32:49 +00:00
|
|
|
Mount string `mapstructure:"mount"`
|
2017-04-30 15:37:10 +00:00
|
|
|
Name string `mapstructure:"name"`
|
2015-06-30 03:29:41 +00:00
|
|
|
}
|
|
|
|
if err := mapstructure.WeakDecode(m, &data); err != nil {
|
2017-08-31 20:57:00 +00:00
|
|
|
return nil, err
|
2015-06-30 03:29:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if data.Mount == "" {
|
|
|
|
data.Mount = "cert"
|
|
|
|
}
|
|
|
|
|
2017-04-30 15:37:10 +00:00
|
|
|
options := map[string]interface{}{
|
|
|
|
"name": data.Name,
|
|
|
|
}
|
2015-06-30 03:29:41 +00:00
|
|
|
path := fmt.Sprintf("auth/%s/login", data.Mount)
|
2017-04-30 15:37:10 +00:00
|
|
|
secret, err := c.Logical().Write(path, options)
|
2015-06-30 03:29:41 +00:00
|
|
|
if err != nil {
|
2017-08-31 20:57:00 +00:00
|
|
|
return nil, err
|
2015-06-30 03:29:41 +00:00
|
|
|
}
|
|
|
|
if secret == nil {
|
2017-08-31 20:57:00 +00:00
|
|
|
return nil, fmt.Errorf("empty response from credential provider")
|
2015-06-30 03:29:41 +00:00
|
|
|
}
|
|
|
|
|
2017-08-31 20:57:00 +00:00
|
|
|
return secret, nil
|
2015-06-30 03:29:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (h *CLIHandler) Help() string {
|
|
|
|
help := `
|
2017-09-06 14:02:15 +00:00
|
|
|
Usage: vault login -method=cert [CONFIG K=V...]
|
2015-06-30 03:29:41 +00:00
|
|
|
|
2018-03-20 18:54:10 +00:00
|
|
|
The certificate auth method allows users to authenticate with a
|
2017-09-02 22:49:55 +00:00
|
|
|
client certificate passed with the request. The -client-cert and -client-key
|
2017-09-06 14:02:15 +00:00
|
|
|
flags are included with the "vault login" command, NOT as configuration to the
|
2017-09-13 01:48:52 +00:00
|
|
|
auth method.
|
2015-06-30 03:29:41 +00:00
|
|
|
|
2017-09-02 22:49:55 +00:00
|
|
|
Authenticate using a local client certificate:
|
|
|
|
|
2017-09-06 14:02:15 +00:00
|
|
|
$ vault login -method=cert -client-cert=cert.pem -client-key=key.pem
|
2017-09-02 22:49:55 +00:00
|
|
|
|
|
|
|
Configuration:
|
|
|
|
|
|
|
|
name=<string>
|
|
|
|
Certificate role to authenticate against.
|
|
|
|
`
|
2015-06-30 03:29:41 +00:00
|
|
|
|
|
|
|
return strings.TrimSpace(help)
|
|
|
|
}
|