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
|
|
|
package plugin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/rpc"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/hashicorp/vault/helper/consts"
|
|
|
|
"github.com/hashicorp/vault/helper/pluginutil"
|
|
|
|
"github.com/hashicorp/vault/helper/wrapping"
|
|
|
|
"github.com/hashicorp/vault/logical"
|
|
|
|
)
|
|
|
|
|
|
|
|
type SystemViewClient struct {
|
|
|
|
client *rpc.Client
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SystemViewClient) DefaultLeaseTTL() time.Duration {
|
|
|
|
var reply DefaultLeaseTTLReply
|
|
|
|
err := s.client.Call("Plugin.DefaultLeaseTTL", new(interface{}), &reply)
|
|
|
|
if err != nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
return reply.DefaultLeaseTTL
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SystemViewClient) MaxLeaseTTL() time.Duration {
|
|
|
|
var reply MaxLeaseTTLReply
|
|
|
|
err := s.client.Call("Plugin.MaxLeaseTTL", new(interface{}), &reply)
|
|
|
|
if err != nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
return reply.MaxLeaseTTL
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SystemViewClient) SudoPrivilege(path string, token string) bool {
|
|
|
|
var reply SudoPrivilegeReply
|
|
|
|
args := &SudoPrivilegeArgs{
|
|
|
|
Path: path,
|
|
|
|
Token: token,
|
|
|
|
}
|
|
|
|
|
|
|
|
err := s.client.Call("Plugin.SudoPrivilege", args, &reply)
|
|
|
|
if err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return reply.Sudo
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SystemViewClient) Tainted() bool {
|
|
|
|
var reply TaintedReply
|
|
|
|
|
|
|
|
err := s.client.Call("Plugin.Tainted", new(interface{}), &reply)
|
|
|
|
if err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return reply.Tainted
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SystemViewClient) CachingDisabled() bool {
|
|
|
|
var reply CachingDisabledReply
|
|
|
|
|
|
|
|
err := s.client.Call("Plugin.CachingDisabled", new(interface{}), &reply)
|
|
|
|
if err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return reply.CachingDisabled
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SystemViewClient) ReplicationState() consts.ReplicationState {
|
|
|
|
var reply ReplicationStateReply
|
|
|
|
|
|
|
|
err := s.client.Call("Plugin.ReplicationState", new(interface{}), &reply)
|
|
|
|
if err != nil {
|
|
|
|
return consts.ReplicationDisabled
|
|
|
|
}
|
|
|
|
|
|
|
|
return reply.ReplicationState
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SystemViewClient) ResponseWrapData(data map[string]interface{}, ttl time.Duration, jwt bool) (*wrapping.ResponseWrapInfo, error) {
|
|
|
|
var reply ResponseWrapDataReply
|
|
|
|
// Do not allow JWTs to be returned
|
|
|
|
args := &ResponseWrapDataArgs{
|
|
|
|
Data: data,
|
|
|
|
TTL: ttl,
|
|
|
|
JWT: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
err := s.client.Call("Plugin.ResponseWrapData", args, &reply)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if reply.Error != nil {
|
|
|
|
return nil, reply.Error
|
|
|
|
}
|
|
|
|
|
|
|
|
return reply.ResponseWrapInfo, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SystemViewClient) LookupPlugin(name string) (*pluginutil.PluginRunner, error) {
|
|
|
|
return nil, fmt.Errorf("cannot call LookupPlugin from a plugin backend")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SystemViewClient) MlockEnabled() bool {
|
|
|
|
var reply MlockEnabledReply
|
|
|
|
err := s.client.Call("Plugin.MlockEnabled", new(interface{}), &reply)
|
|
|
|
if err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return reply.MlockEnabled
|
|
|
|
}
|
|
|
|
|
|
|
|
type SystemViewServer struct {
|
|
|
|
impl logical.SystemView
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SystemViewServer) DefaultLeaseTTL(_ interface{}, reply *DefaultLeaseTTLReply) error {
|
|
|
|
ttl := s.impl.DefaultLeaseTTL()
|
|
|
|
*reply = DefaultLeaseTTLReply{
|
|
|
|
DefaultLeaseTTL: ttl,
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SystemViewServer) MaxLeaseTTL(_ interface{}, reply *MaxLeaseTTLReply) error {
|
|
|
|
ttl := s.impl.MaxLeaseTTL()
|
|
|
|
*reply = MaxLeaseTTLReply{
|
|
|
|
MaxLeaseTTL: ttl,
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SystemViewServer) SudoPrivilege(args *SudoPrivilegeArgs, reply *SudoPrivilegeReply) error {
|
|
|
|
sudo := s.impl.SudoPrivilege(args.Path, args.Token)
|
|
|
|
*reply = SudoPrivilegeReply{
|
|
|
|
Sudo: sudo,
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SystemViewServer) Tainted(_ interface{}, reply *TaintedReply) error {
|
|
|
|
tainted := s.impl.Tainted()
|
|
|
|
*reply = TaintedReply{
|
|
|
|
Tainted: tainted,
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SystemViewServer) CachingDisabled(_ interface{}, reply *CachingDisabledReply) error {
|
|
|
|
cachingDisabled := s.impl.CachingDisabled()
|
|
|
|
*reply = CachingDisabledReply{
|
|
|
|
CachingDisabled: cachingDisabled,
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SystemViewServer) ReplicationState(_ interface{}, reply *ReplicationStateReply) error {
|
|
|
|
replicationState := s.impl.ReplicationState()
|
|
|
|
*reply = ReplicationStateReply{
|
|
|
|
ReplicationState: replicationState,
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SystemViewServer) ResponseWrapData(args *ResponseWrapDataArgs, reply *ResponseWrapDataReply) error {
|
|
|
|
// Do not allow JWTs to be returned
|
|
|
|
info, err := s.impl.ResponseWrapData(args.Data, args.TTL, false)
|
|
|
|
if err != nil {
|
|
|
|
*reply = ResponseWrapDataReply{
|
2017-10-19 20:29:59 +00:00
|
|
|
Error: wrapError(err),
|
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
|
|
|
|
}
|
|
|
|
*reply = ResponseWrapDataReply{
|
|
|
|
ResponseWrapInfo: info,
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SystemViewServer) MlockEnabled(_ interface{}, reply *MlockEnabledReply) error {
|
|
|
|
enabled := s.impl.MlockEnabled()
|
|
|
|
*reply = MlockEnabledReply{
|
|
|
|
MlockEnabled: enabled,
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type DefaultLeaseTTLReply struct {
|
|
|
|
DefaultLeaseTTL time.Duration
|
|
|
|
}
|
|
|
|
|
|
|
|
type MaxLeaseTTLReply struct {
|
|
|
|
MaxLeaseTTL time.Duration
|
|
|
|
}
|
|
|
|
|
|
|
|
type SudoPrivilegeArgs struct {
|
|
|
|
Path string
|
|
|
|
Token string
|
|
|
|
}
|
|
|
|
|
|
|
|
type SudoPrivilegeReply struct {
|
|
|
|
Sudo bool
|
|
|
|
}
|
|
|
|
|
|
|
|
type TaintedReply struct {
|
|
|
|
Tainted bool
|
|
|
|
}
|
|
|
|
|
|
|
|
type CachingDisabledReply struct {
|
|
|
|
CachingDisabled bool
|
|
|
|
}
|
|
|
|
|
|
|
|
type ReplicationStateReply struct {
|
|
|
|
ReplicationState consts.ReplicationState
|
|
|
|
}
|
|
|
|
|
|
|
|
type ResponseWrapDataArgs struct {
|
|
|
|
Data map[string]interface{}
|
|
|
|
TTL time.Duration
|
|
|
|
JWT bool
|
|
|
|
}
|
|
|
|
|
|
|
|
type ResponseWrapDataReply struct {
|
|
|
|
ResponseWrapInfo *wrapping.ResponseWrapInfo
|
2017-10-19 20:29:59 +00:00
|
|
|
Error error
|
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
|
|
|
}
|
|
|
|
|
|
|
|
type MlockEnabledReply struct {
|
|
|
|
MlockEnabled bool
|
|
|
|
}
|