2023-03-15 16:00:52 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2015-06-16 20:58:54 +00:00
|
|
|
package ssh
|
|
|
|
|
|
|
|
import (
|
2018-01-19 06:44:44 +00:00
|
|
|
"context"
|
2015-06-16 20:58:54 +00:00
|
|
|
"strings"
|
2017-05-05 19:01:52 +00:00
|
|
|
"sync"
|
2015-06-16 20:58:54 +00:00
|
|
|
|
2019-04-13 07:44:06 +00:00
|
|
|
"github.com/hashicorp/vault/sdk/framework"
|
2019-04-12 21:54:35 +00:00
|
|
|
"github.com/hashicorp/vault/sdk/helper/salt"
|
|
|
|
"github.com/hashicorp/vault/sdk/logical"
|
2015-06-16 20:58:54 +00:00
|
|
|
)
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-01-19 06:44:44 +00:00
|
|
|
func Factory(ctx context.Context, conf *logical.BackendConfig) (logical.Backend, error) {
|
2015-07-22 18:15:19 +00:00
|
|
|
b, err := Backend(conf)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2018-01-19 06:44:44 +00:00
|
|
|
if err := b.Setup(ctx, conf); err != nil {
|
Backend plugin system (#2874)
* Add backend plugin changes
* Fix totp backend plugin tests
* Fix logical/plugin InvalidateKey test
* Fix plugin catalog CRUD test, fix NoopBackend
* Clean up commented code block
* Fix system backend mount test
* Set plugin_name to omitempty, fix handleMountTable config parsing
* Clean up comments, keep shim connections alive until cleanup
* Include pluginClient, disallow LookupPlugin call from within a plugin
* Add wrapper around backendPluginClient for proper cleanup
* Add logger shim tests
* Add logger, storage, and system shim tests
* Use pointer receivers for system view shim
* Use plugin name if no path is provided on mount
* Enable plugins for auth backends
* Add backend type attribute, move builtin/plugin/package
* Fix merge conflict
* Fix missing plugin name in mount config
* Add integration tests on enabling auth backend plugins
* Remove dependency cycle on mock-plugin
* Add passthrough backend plugin, use logical.BackendType to determine lease generation
* Remove vault package dependency on passthrough package
* Add basic impl test for passthrough plugin
* Incorporate feedback; set b.backend after shims creation on backendPluginServer
* Fix totp plugin test
* Add plugin backends docs
* Fix tests
* Fix builtin/plugin tests
* Remove flatten from PluginRunner fields
* Move mock plugin to logical/plugin, remove totp and passthrough plugins
* Move pluginMap into newPluginClient
* Do not create storage RPC connection on HandleRequest and HandleExistenceCheck
* Change shim logger's Fatal to no-op
* Change BackendType to uint32, match UX backend types
* Change framework.Backend Setup signature
* Add Setup func to logical.Backend interface
* Move OptionallyEnableMlock call into plugin.Serve, update docs and comments
* Remove commented var in plugin package
* RegisterLicense on logical.Backend interface (#3017)
* Add RegisterLicense to logical.Backend interface
* Update RegisterLicense to use callback func on framework.Backend
* Refactor framework.Backend.RegisterLicense
* plugin: Prevent plugin.SystemViewClient.ResponseWrapData from getting JWTs
* plugin: Revert BackendType to remove TypePassthrough and related references
* Fix typo in plugin backends docs
2017-07-20 17:28:40 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return b, nil
|
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/",
|
|
|
|
},
|
2017-10-23 21:39:21 +00:00
|
|
|
|
|
|
|
SealWrapStorage: []string{
|
|
|
|
caPrivateKey,
|
|
|
|
caPrivateKeyStoragePath,
|
2023-02-01 15:09:16 +00:00
|
|
|
keysStoragePrefix,
|
2017-10-23 21:39:21 +00:00
|
|
|
},
|
2015-06-16 20:58:54 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
Paths: []*framework.Path{
|
2015-08-29 19:24:15 +00:00
|
|
|
pathConfigZeroAddress(&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),
|
2022-06-10 13:48:19 +00:00
|
|
|
pathIssue(&b),
|
2016-12-26 14:03:27 +00:00
|
|
|
pathFetchPublicKey(&b),
|
2023-02-01 15:09:16 +00:00
|
|
|
pathCleanupKeys(&b),
|
2015-06-16 20:58:54 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
Secrets: []*framework.Secret{
|
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-07-28 18:04:46 +00:00
|
|
|
Invalidate: b.invalidate,
|
|
|
|
BackendType: logical.TypeLogical,
|
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
|
|
|
}
|
|
|
|
|
2018-03-08 19:21:11 +00:00
|
|
|
func (b *backend) Salt(ctx context.Context) (*salt.Salt, error) {
|
2017-05-09 21:51:09 +00:00
|
|
|
b.saltMutex.RLock()
|
|
|
|
if b.salt != nil {
|
|
|
|
defer b.saltMutex.RUnlock()
|
|
|
|
return b.salt, nil
|
|
|
|
}
|
|
|
|
b.saltMutex.RUnlock()
|
2017-05-05 19:01:52 +00:00
|
|
|
b.saltMutex.Lock()
|
|
|
|
defer b.saltMutex.Unlock()
|
2017-05-09 21:51:09 +00:00
|
|
|
if b.salt != nil {
|
|
|
|
return b.salt, nil
|
|
|
|
}
|
2018-03-08 19:21:11 +00:00
|
|
|
salt, err := salt.NewSalt(ctx, b.view, &salt.Config{
|
2017-02-16 21:29:30 +00:00
|
|
|
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 {
|
2017-05-09 21:51:09 +00:00
|
|
|
return nil, err
|
2017-02-16 21:29:30 +00:00
|
|
|
}
|
|
|
|
b.salt = salt
|
2017-05-09 21:51:09 +00:00
|
|
|
return salt, nil
|
2017-02-16 21:29:30 +00:00
|
|
|
}
|
|
|
|
|
2018-01-19 06:44:44 +00:00
|
|
|
func (b *backend) invalidate(_ context.Context, key string) {
|
2017-05-05 19:01:52 +00:00
|
|
|
switch key {
|
|
|
|
case salt.DefaultLocation:
|
2017-05-09 21:51:09 +00:00
|
|
|
b.saltMutex.Lock()
|
|
|
|
defer b.saltMutex.Unlock()
|
|
|
|
b.salt = nil
|
2017-05-05 19:01:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2023-01-31 21:02:22 +00:00
|
|
|
There are two variants of the backend, which generate different types of
|
|
|
|
credentials: 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
|
|
|
`
|