2015-06-16 20:58:54 +00:00
|
|
|
package ssh
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
2017-05-05 19:01:52 +00:00
|
|
|
"sync"
|
2015-06-16 20:58:54 +00:00
|
|
|
|
2015-07-22 18:15:19 +00:00
|
|
|
"github.com/hashicorp/vault/helper/salt"
|
2015-06-16 20:58:54 +00:00
|
|
|
"github.com/hashicorp/vault/logical"
|
|
|
|
"github.com/hashicorp/vault/logical/framework"
|
|
|
|
)
|
|
|
|
|
2015-07-29 18:21:36 +00:00
|
|
|
type backend struct {
|
|
|
|
*framework.Backend
|
2017-05-05 19:01:52 +00:00
|
|
|
view logical.Storage
|
|
|
|
salt *salt.Salt
|
|
|
|
saltMutex sync.RWMutex
|
2015-07-29 18:21:36 +00:00
|
|
|
}
|
|
|
|
|
2015-07-01 13:37:11 +00:00
|
|
|
func Factory(conf *logical.BackendConfig) (logical.Backend, error) {
|
2015-07-22 18:15:19 +00:00
|
|
|
b, err := Backend(conf)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return b.Setup(conf)
|
2015-06-16 20:58:54 +00:00
|
|
|
}
|
|
|
|
|
2016-06-01 16:17:47 +00:00
|
|
|
func Backend(conf *logical.BackendConfig) (*backend, error) {
|
2015-06-16 20:58:54 +00:00
|
|
|
var b backend
|
2017-02-16 21:29:30 +00:00
|
|
|
b.view = conf.StorageView
|
2015-06-16 20:58:54 +00:00
|
|
|
b.Backend = &framework.Backend{
|
|
|
|
Help: strings.TrimSpace(backendHelp),
|
|
|
|
|
|
|
|
PathsSpecial: &logical.Paths{
|
2015-07-23 22:12:13 +00:00
|
|
|
Unauthenticated: []string{
|
|
|
|
"verify",
|
2016-12-26 14:03:27 +00:00
|
|
|
"public_key",
|
2015-07-23 22:12:13 +00:00
|
|
|
},
|
2017-02-16 21:29:30 +00:00
|
|
|
|
|
|
|
LocalStorage: []string{
|
|
|
|
"otp/",
|
|
|
|
},
|
2015-06-16 20:58:54 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
Paths: []*framework.Path{
|
2015-08-29 19:24:15 +00:00
|
|
|
pathConfigZeroAddress(&b),
|
2015-06-24 22:13:12 +00:00
|
|
|
pathKeys(&b),
|
2016-01-28 17:48:00 +00:00
|
|
|
pathListRoles(&b),
|
2015-06-16 20:58:54 +00:00
|
|
|
pathRoles(&b),
|
2015-07-24 16:13:26 +00:00
|
|
|
pathCredsCreate(&b),
|
2015-06-26 01:47:32 +00:00
|
|
|
pathLookup(&b),
|
2015-07-22 18:15:19 +00:00
|
|
|
pathVerify(&b),
|
2016-12-26 14:03:27 +00:00
|
|
|
pathConfigCA(&b),
|
|
|
|
pathSign(&b),
|
|
|
|
pathFetchPublicKey(&b),
|
2015-06-16 20:58:54 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
Secrets: []*framework.Secret{
|
2015-07-23 22:12:13 +00:00
|
|
|
secretDynamicKey(&b),
|
2015-07-22 18:15:19 +00:00
|
|
|
secretOTP(&b),
|
2015-06-16 20:58:54 +00:00
|
|
|
},
|
2017-02-16 21:29:30 +00:00
|
|
|
|
2017-05-05 19:01:52 +00:00
|
|
|
Init: b.initialize,
|
|
|
|
|
|
|
|
Invalidate: b.invalidate,
|
2015-06-16 20:58:54 +00:00
|
|
|
}
|
2016-06-01 16:17:47 +00:00
|
|
|
return &b, nil
|
2015-06-16 20:58:54 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 19:01:52 +00:00
|
|
|
func (b *backend) initialize() error {
|
|
|
|
b.saltMutex.Lock()
|
|
|
|
defer b.saltMutex.Unlock()
|
2017-02-16 21:29:30 +00:00
|
|
|
salt, err := salt.NewSalt(b.view, &salt.Config{
|
|
|
|
HashFunc: salt.SHA256Hash,
|
2017-05-05 19:01:52 +00:00
|
|
|
Location: salt.DefaultLocation,
|
2017-02-16 21:29:30 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
b.salt = salt
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-05-05 19:01:52 +00:00
|
|
|
func (b *backend) invalidate(key string) {
|
|
|
|
switch key {
|
|
|
|
case salt.DefaultLocation:
|
|
|
|
// reread the salt
|
|
|
|
b.initialize()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-16 20:58:54 +00:00
|
|
|
const backendHelp = `
|
2015-09-21 20:12:38 +00:00
|
|
|
The SSH backend generates credentials allowing clients to establish SSH
|
|
|
|
connections to remote hosts.
|
2015-07-02 01:26:42 +00:00
|
|
|
|
2016-12-26 14:03:27 +00:00
|
|
|
There are three variants of the backend, which generate different types of
|
|
|
|
credentials: dynamic keys, One-Time Passwords (OTPs) and certificate authority. The desired behavior
|
2015-09-21 20:12:38 +00:00
|
|
|
is role-specific and chosen at role creation time with the 'key_type'
|
|
|
|
parameter.
|
2015-07-27 17:02:31 +00:00
|
|
|
|
2015-09-21 20:12:38 +00:00
|
|
|
Please see the backend documentation for a thorough description of both
|
|
|
|
types. The Vault team strongly recommends the OTP type.
|
2015-07-27 17:02:31 +00:00
|
|
|
|
2015-09-21 20:12:38 +00:00
|
|
|
After mounting this backend, before generating credentials, configure the
|
|
|
|
backend's lease behavior using the 'config/lease' endpoint and create roles
|
|
|
|
using the 'roles/' endpoint.
|
2015-06-16 20:58:54 +00:00
|
|
|
`
|