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-29 18:21:36 +00:00
|
|
|
type backend struct {
|
|
|
|
*framework.Backend
|
|
|
|
salt *salt.Salt
|
|
|
|
}
|
|
|
|
|
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) {
|
2015-09-09 19:42:29 +00:00
|
|
|
salt, err := salt.NewSalt(conf.StorageView, nil)
|
2015-07-22 18:15:19 +00:00
|
|
|
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-08-29 19:24:15 +00:00
|
|
|
pathConfigZeroAddress(&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
|
|
|
}
|
|
|
|
|
|
|
|
const backendHelp = `
|
2015-08-18 01:22:03 +00:00
|
|
|
The SSH backend generates credentials to establish SSH connection with remote hosts.
|
|
|
|
There are two types of credentials that could be generated: Dynamic and OTP. The
|
|
|
|
desired way of key creation should be chosen by using 'key_type' parameter of 'roles/'
|
|
|
|
endpoint. When a credential is requested for a particular role, Vault will generate
|
|
|
|
a credential accordingly and issue it.
|
2015-07-02 01:26:42 +00:00
|
|
|
|
2015-08-18 01:22:03 +00:00
|
|
|
Dynamic Key: is a RSA private key which can be used to establish SSH session using
|
|
|
|
publickey authentication. When the client receives a key and uses it to establish
|
2015-09-09 19:42:29 +00:00
|
|
|
connections with hosts, Vault server will have no way to know when and how many
|
2015-08-18 01:22:03 +00:00
|
|
|
times the key will be used. So, these login attempts will not be audited by Vault.
|
|
|
|
To create a dynamic credential, Vault will use the shared private key registered
|
|
|
|
with the role. Named key should be created using 'keys/' endpoint and used with
|
|
|
|
'roles/' endpoint for Vault to know the shared key to use for installing the newly
|
|
|
|
generated key. Since Vault uses the shared key to install keys for other usernames,
|
|
|
|
shared key should have sudoer privileges in remote hosts and password prompts for
|
|
|
|
sudoers should be disabled. Also, dynamic keys are leased keys and gets revoked
|
|
|
|
in remote hosts by Vault after the expiry.
|
2015-07-27 17:02:31 +00:00
|
|
|
|
2015-08-18 01:22:03 +00:00
|
|
|
OTP Key: is a UUID which can be used to login using keyboard-interactive authentication.
|
|
|
|
All the hosts that intend to support OTP should have Vault SSH Agent installed in
|
|
|
|
them. This agent will receive the OTP from client and get it validated by Vault server.
|
|
|
|
And since Vault server has a role to play for each successful connection, all the
|
|
|
|
events will be audited. Vault server validates a key only once, hence it is a OTP.
|
2015-07-27 17:02:31 +00:00
|
|
|
|
2015-08-18 01:22:03 +00:00
|
|
|
After mounting this backend, before generating the keys, configure the lease using
|
|
|
|
'congig/lease' endpoint and create roles using 'roles/' endpoint.
|
2015-06-16 20:58:54 +00:00
|
|
|
`
|