open-vault/builtin/logical/ssh/backend.go

107 lines
2.2 KiB
Go
Raw Normal View History

package ssh
import (
"strings"
"sync"
2015-07-22 18:15:19 +00:00
"github.com/hashicorp/vault/helper/salt"
"github.com/hashicorp/vault/logical"
"github.com/hashicorp/vault/logical/framework"
)
2015-07-29 18:21:36 +00:00
type backend struct {
*framework.Backend
view logical.Storage
salt *salt.Salt
saltMutex sync.RWMutex
2015-07-29 18:21:36 +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)
}
func Backend(conf *logical.BackendConfig) (*backend, error) {
var b backend
b.view = conf.StorageView
b.Backend = &framework.Backend{
Help: strings.TrimSpace(backendHelp),
PathsSpecial: &logical.Paths{
Unauthenticated: []string{
"verify",
2016-12-26 14:03:27 +00:00
"public_key",
},
LocalStorage: []string{
"otp/",
},
},
Paths: []*framework.Path{
pathConfigZeroAddress(&b),
pathKeys(&b),
2016-01-28 17:48:00 +00:00
pathListRoles(&b),
pathRoles(&b),
2015-07-24 16:13:26 +00:00
pathCredsCreate(&b),
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),
},
Secrets: []*framework.Secret{
secretDynamicKey(&b),
2015-07-22 18:15:19 +00:00
secretOTP(&b),
},
Init: b.initialize,
Invalidate: b.invalidate,
}
return &b, nil
}
func (b *backend) initialize() error {
b.saltMutex.Lock()
defer b.saltMutex.Unlock()
salt, err := salt.NewSalt(b.view, &salt.Config{
HashFunc: salt.SHA256Hash,
Location: salt.DefaultLocation,
})
if err != nil {
return err
}
b.salt = salt
return nil
}
func (b *backend) invalidate(key string) {
switch key {
case salt.DefaultLocation:
// reread the salt
b.initialize()
}
}
const backendHelp = `
The SSH backend generates credentials allowing clients to establish SSH
connections to remote hosts.
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
is role-specific and chosen at role creation time with the 'key_type'
parameter.
2015-07-27 17:02:31 +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
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.
`