2015-06-16 20:58:54 +00:00
|
|
|
package ssh
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
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-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
|
|
|
}
|
|
|
|
|
2015-07-22 18:15:19 +00:00
|
|
|
func Backend(conf *logical.BackendConfig) (*framework.Backend, error) {
|
|
|
|
salt, err := salt.NewSalt(conf.View, nil)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2015-06-16 20:58:54 +00:00
|
|
|
var b backend
|
2015-07-22 18:15:19 +00:00
|
|
|
b.salt = salt
|
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
|
|
|
Root: []string{
|
|
|
|
"config/*",
|
|
|
|
"keys/*",
|
|
|
|
},
|
|
|
|
Unauthenticated: []string{
|
|
|
|
"verify",
|
|
|
|
},
|
2015-06-16 20:58:54 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
Paths: []*framework.Path{
|
|
|
|
pathConfigLease(&b),
|
2015-06-24 22:13:12 +00:00
|
|
|
pathKeys(&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),
|
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
|
|
|
},
|
|
|
|
}
|
2015-07-22 18:15:19 +00:00
|
|
|
return b.Backend, nil
|
2015-06-16 20:58:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type backend struct {
|
|
|
|
*framework.Backend
|
2015-07-22 18:15:19 +00:00
|
|
|
salt *salt.Salt
|
2015-06-16 20:58:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const backendHelp = `
|
2015-07-27 17:02:31 +00:00
|
|
|
The SSH backend generates keys to eatablish SSH connection
|
|
|
|
with remote hosts. There are two options to create the keys:
|
|
|
|
long lived dynamic key, one time password.
|
2015-07-02 01:26:42 +00:00
|
|
|
|
2015-07-27 17:02:31 +00:00
|
|
|
Long lived dynamic key is a rsa private key which can be used
|
|
|
|
to login to remote host using the publickey authentication.
|
|
|
|
There is no additional change required in the remote hosts to
|
|
|
|
support this type of keys. But the keys generated will be valid
|
|
|
|
as long as the lease of the key is valid. Also, logins to remote
|
|
|
|
hosts will not be audited in vault server.
|
|
|
|
|
|
|
|
One Time Password (OTP), on the other hand is a randomly generated
|
|
|
|
UUID that is used to login to remote host using the keyboard-
|
|
|
|
interactive challenge response authentication. A vault agent
|
|
|
|
has to be installed at the remote host to support OTP. Upon
|
|
|
|
request, vault server generates and provides the key to the
|
|
|
|
user. During login, vault agent receives the key and verifies
|
|
|
|
the correctness with the vault server (and hence audited). The
|
|
|
|
server after verifying the key for the first time, deletes the
|
|
|
|
same (and hence one-time).
|
|
|
|
|
|
|
|
Both type of keys have a configurable lease set and are automatically
|
|
|
|
revoked at the end of the lease.
|
|
|
|
|
|
|
|
After mounting this backend, before generating the keys, configure
|
|
|
|
the lease using the 'config/lease' endpoint and create roles using
|
|
|
|
the 'roles/' endpoint.
|
2015-06-16 20:58:54 +00:00
|
|
|
`
|