2015-05-15 16:13:05 +00:00
|
|
|
package pki
|
|
|
|
|
|
|
|
import (
|
2018-01-19 06:44:44 +00:00
|
|
|
"context"
|
2015-05-15 16:13:05 +00:00
|
|
|
"strings"
|
2015-06-19 16:48:18 +00:00
|
|
|
"sync"
|
|
|
|
"time"
|
2015-05-15 16:13:05 +00:00
|
|
|
|
2019-04-12 21:54:35 +00:00
|
|
|
"github.com/hashicorp/vault/sdk/framework"
|
2019-04-13 07:44:06 +00:00
|
|
|
"github.com/hashicorp/vault/sdk/logical"
|
2015-05-15 16:13:05 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Factory creates a new backend implementing the logical.Backend interface
|
2018-01-19 06:44:44 +00:00
|
|
|
func Factory(ctx context.Context, conf *logical.BackendConfig) (logical.Backend, error) {
|
2018-06-16 22:21:33 +00:00
|
|
|
b := Backend(conf)
|
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-05-15 16:13:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Backend returns a new Backend framework struct
|
2018-06-16 22:21:33 +00:00
|
|
|
func Backend(conf *logical.BackendConfig) *backend {
|
2015-05-15 16:13:05 +00:00
|
|
|
var b backend
|
|
|
|
b.Backend = &framework.Backend{
|
|
|
|
Help: strings.TrimSpace(backendHelp),
|
|
|
|
|
|
|
|
PathsSpecial: &logical.Paths{
|
|
|
|
Unauthenticated: []string{
|
|
|
|
"cert/*",
|
|
|
|
"ca/pem",
|
2016-09-28 00:50:17 +00:00
|
|
|
"ca_chain",
|
2015-05-15 16:13:05 +00:00
|
|
|
"ca",
|
|
|
|
"crl/pem",
|
|
|
|
"crl",
|
|
|
|
},
|
2017-02-16 21:29:30 +00:00
|
|
|
|
|
|
|
LocalStorage: []string{
|
|
|
|
"revoked/",
|
|
|
|
"crl",
|
|
|
|
"certs/",
|
|
|
|
},
|
2017-08-15 18:00:40 +00:00
|
|
|
|
|
|
|
Root: []string{
|
|
|
|
"root",
|
2017-09-01 03:07:15 +00:00
|
|
|
"root/sign-self-issued",
|
2017-08-15 18:00:40 +00:00
|
|
|
},
|
2017-10-23 21:39:21 +00:00
|
|
|
|
|
|
|
SealWrapStorage: []string{
|
|
|
|
"config/ca_bundle",
|
|
|
|
},
|
2015-05-15 16:13:05 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
Paths: []*framework.Path{
|
2016-01-28 20:18:07 +00:00
|
|
|
pathListRoles(&b),
|
2015-05-15 16:13:05 +00:00
|
|
|
pathRoles(&b),
|
2015-11-18 15:16:09 +00:00
|
|
|
pathGenerateRoot(&b),
|
2017-08-15 18:00:40 +00:00
|
|
|
pathSignIntermediate(&b),
|
2017-09-01 03:07:15 +00:00
|
|
|
pathSignSelfIssued(&b),
|
2017-08-15 18:00:40 +00:00
|
|
|
pathDeleteRoot(&b),
|
2015-11-18 15:16:09 +00:00
|
|
|
pathGenerateIntermediate(&b),
|
|
|
|
pathSetSignedIntermediate(&b),
|
2015-05-15 16:13:05 +00:00
|
|
|
pathConfigCA(&b),
|
2015-06-19 16:48:18 +00:00
|
|
|
pathConfigCRL(&b),
|
2015-10-14 01:13:40 +00:00
|
|
|
pathConfigURLs(&b),
|
2015-11-18 15:16:09 +00:00
|
|
|
pathSignVerbatim(&b),
|
2015-09-30 01:48:31 +00:00
|
|
|
pathSign(&b),
|
2015-05-15 16:13:05 +00:00
|
|
|
pathIssue(&b),
|
|
|
|
pathRotateCRL(&b),
|
|
|
|
pathFetchCA(&b),
|
2016-09-28 00:50:17 +00:00
|
|
|
pathFetchCAChain(&b),
|
2015-05-15 16:13:05 +00:00
|
|
|
pathFetchCRL(&b),
|
|
|
|
pathFetchCRLViaCertPath(&b),
|
|
|
|
pathFetchValid(&b),
|
2016-06-08 15:46:58 +00:00
|
|
|
pathFetchListCerts(&b),
|
2015-05-15 16:13:05 +00:00
|
|
|
pathRevoke(&b),
|
2016-02-24 21:19:01 +00:00
|
|
|
pathTidy(&b),
|
2015-05-15 16:13:05 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
Secrets: []*framework.Secret{
|
|
|
|
secretCerts(&b),
|
|
|
|
},
|
2017-07-28 18:04:46 +00:00
|
|
|
|
|
|
|
BackendType: logical.TypeLogical,
|
2015-05-15 16:13:05 +00:00
|
|
|
}
|
|
|
|
|
2015-06-19 16:48:18 +00:00
|
|
|
b.crlLifetime = time.Hour * 72
|
2018-06-16 22:21:33 +00:00
|
|
|
b.tidyCASGuard = new(uint32)
|
|
|
|
b.storage = conf.StorageView
|
2015-06-19 16:48:18 +00:00
|
|
|
|
2016-06-10 19:53:02 +00:00
|
|
|
return &b
|
2015-05-15 16:13:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type backend struct {
|
|
|
|
*framework.Backend
|
2015-06-19 16:48:18 +00:00
|
|
|
|
2018-06-16 22:21:33 +00:00
|
|
|
storage logical.Storage
|
2015-06-19 16:48:18 +00:00
|
|
|
crlLifetime time.Duration
|
2016-02-24 21:19:01 +00:00
|
|
|
revokeStorageLock sync.RWMutex
|
2018-06-16 22:21:33 +00:00
|
|
|
tidyCASGuard *uint32
|
2015-05-15 16:13:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const backendHelp = `
|
|
|
|
The PKI backend dynamically generates X509 server and client certificates.
|
|
|
|
|
2015-06-12 03:16:13 +00:00
|
|
|
After mounting this backend, configure the CA using the "pem_bundle" endpoint within
|
2015-05-15 16:13:05 +00:00
|
|
|
the "config/" path.
|
|
|
|
`
|