Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
Refactor loading of plugins to require passing in both plugin file an…
Browse files Browse the repository at this point in the history
…d signature file if plugin is signed
  • Loading branch information
geauxvirtual committed Oct 24, 2015
1 parent 4851272 commit d2c9b1f
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 20 deletions.
40 changes: 31 additions & 9 deletions control/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,28 +250,49 @@ func (p *pluginControl) Stop() {
// Load is the public method to load a plugin into
// the LoadedPlugins array and issue an event when
// successful.
func (p *pluginControl) Load(path string) (core.CatalogedPlugin, perror.PulseError) {
func (p *pluginControl) Load(files ...string) (core.CatalogedPlugin, perror.PulseError) {
f := map[string]interface{}{
"_block": "load",
"path": path,
}

//Check plugin signing
signatureFile := path + ".asc"
var signed bool
if p.pluginTrust == PluginTrustEnabled || p.pluginTrust == PluginTrustWarn {
err := p.signingManager.ValidateSignature(p.keyringFile, path, signatureFile)
var pluginPath, signatureFile string

switch p.pluginTrust {
case PluginTrustDisabled:
pluginPath = files[0]
signatureFile = ""
signed = false
case PluginTrustEnabled:
if len(files) != 2 {
return nil, perror.New(fmt.Errorf("Plugin file and signature file required when plugin trust is enabled"))
}
pluginPath = files[0]
signatureFile = files[1]
err := p.signingManager.ValidateSignature(p.keyringFile, pluginPath, signatureFile)
if err != nil {
if p.pluginTrust == PluginTrustEnabled {
return nil, perror.New(err)
}
signed = true
case PluginTrustWarn:
if len(files) == 1 {
pluginPath = files[0]
signatureFile = ""
signed = false
controlLogger.WithFields(f).Warn("Loading unsigned plugin ", pluginPath)
} else {
pluginPath = files[0]
signatureFile = files[1]
err := p.signingManager.ValidateSignature(p.keyringFile, pluginPath, signatureFile)
if err != nil {
return nil, perror.New(err)
}
controlLogger.WithFields(f).Error(err)
} else {
signed = true
}
}

path, _, err := unpackage.Unpackager(path)
path, _, err := unpackage.Unpackager(pluginPath)
if err != nil {
return nil, perror.New(err)
}
Expand All @@ -289,6 +310,7 @@ func (p *pluginControl) Load(path string) (core.CatalogedPlugin, perror.PulseErr
return nil, pe
}
pl.Signed = signed
pl.SignatureFile = signatureFile

// defer sending event
event := &control_event.LoadPluginEvent{
Expand Down
2 changes: 1 addition & 1 deletion control/control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ func TestLoad(t *testing.T) {
lpe := newListenToPluginEvent()
c.eventManager.RegisterHandler("Control.PluginLoaded", lpe)
c.Start()
_, err := c.Load(PluginPath)
_, err := c.Load(PluginPath, "dummy.asc")
time.Sleep(100)
So(err, ShouldBeNil)
})
Expand Down
17 changes: 9 additions & 8 deletions control/plugin_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,15 @@ func (l *loadedPlugins) findLatest(typeName, name string) (*loadedPlugin, error)

// the struct representing a plugin that is loaded into Pulse
type loadedPlugin struct {
Meta plugin.PluginMeta
Path string
Type plugin.PluginType
Signed bool
State pluginState
Token string
LoadedTime time.Time
ConfigPolicy *cpolicy.ConfigPolicy
Meta plugin.PluginMeta
Path string
Type plugin.PluginType
Signed bool
SignatureFile string
State pluginState
Token string
LoadedTime time.Time
ConfigPolicy *cpolicy.ConfigPolicy
}

// returns plugin name
Expand Down
2 changes: 1 addition & 1 deletion mgmt/rest/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ type managesMetrics interface {
MetricCatalog() ([]core.CatalogedMetric, error)
FetchMetrics([]string, int) ([]core.CatalogedMetric, error)
GetMetric([]string, int) (core.CatalogedMetric, error)
Load(string) (core.CatalogedPlugin, perror.PulseError)
Load(...string) (core.CatalogedPlugin, perror.PulseError)
Unload(core.Plugin) (core.CatalogedPlugin, perror.PulseError)
PluginCatalog() core.PluginCatalog
AvailablePlugins() []core.AvailablePlugin
Expand Down
2 changes: 1 addition & 1 deletion mgmt/tribe/worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ type Task struct {
}

type ManagesPlugins interface {
Load(path string) (core.CatalogedPlugin, perror.PulseError)
Load(...string) (core.CatalogedPlugin, perror.PulseError)
Unload(plugin core.Plugin) (core.CatalogedPlugin, perror.PulseError)
PluginCatalog() core.PluginCatalog
}
Expand Down

0 comments on commit d2c9b1f

Please sign in to comment.