Commit 3487e518 by Ryan McKinley Committed by GitHub

Signing: allow unsigned plugin in dev mode (#24242)

parent 83683d87
...@@ -282,26 +282,32 @@ func (scanner *PluginScanner) loadPlugin(pluginJsonFilePath string) error { ...@@ -282,26 +282,32 @@ func (scanner *PluginScanner) loadPlugin(pluginJsonFilePath string) error {
pluginCommon.PluginDir = filepath.Dir(pluginJsonFilePath) pluginCommon.PluginDir = filepath.Dir(pluginJsonFilePath)
// For the time being, we choose to only require back-end plugins to be signed // For the time being, we choose to only require back-end plugins to be signed
// NOTE: the state is calculated again for when setting metadata on the object
if pluginCommon.Backend && scanner.requireSigned { if pluginCommon.Backend && scanner.requireSigned {
scanner.log.Debug("Plugin signature required, validating", "pluginID", pluginCommon.Id, sig := GetPluginSignatureState(&pluginCommon)
"pluginDir", pluginCommon.PluginDir) if sig != PluginSignatureValid {
allowUnsigned := false scanner.log.Debug("Invalid Plugin Signature", "pluginID", pluginCommon.Id, "pluginDir", pluginCommon.PluginDir, "state", sig)
for _, plug := range scanner.cfg.PluginsAllowUnsigned { if sig == PluginSignatureUnsigned {
if plug == pluginCommon.Id { allowUnsigned := false
allowUnsigned = true for _, plug := range scanner.cfg.PluginsAllowUnsigned {
break if plug == pluginCommon.Id {
} allowUnsigned = true
} break
if sig := GetPluginSignatureState(&pluginCommon); sig != PluginSignatureValid && !allowUnsigned { }
switch sig { }
case PluginSignatureUnsigned: if setting.Env != setting.DEV && !allowUnsigned {
return fmt.Errorf("plugin %q is unsigned", pluginCommon.Id) return fmt.Errorf("plugin %q is unsigned", pluginCommon.Id)
case PluginSignatureInvalid: }
return fmt.Errorf("plugin %q has an invalid signature", pluginCommon.Id) scanner.log.Warn("Running an unsigned backend plugin", "pluginID", pluginCommon.Id, "pluginDir", pluginCommon.PluginDir)
case PluginSignatureModified: } else {
return fmt.Errorf("plugin %q's signature has been modified", pluginCommon.Id) switch sig {
default: case PluginSignatureInvalid:
return fmt.Errorf("unrecognized plugin signature state %v", sig) return fmt.Errorf("plugin %q has an invalid signature", pluginCommon.Id)
case PluginSignatureModified:
return fmt.Errorf("plugin %q's signature has been modified", pluginCommon.Id)
default:
return fmt.Errorf("unrecognized plugin signature state %v", sig)
}
} }
} }
} }
......
...@@ -18,15 +18,18 @@ import ( ...@@ -18,15 +18,18 @@ import (
func TestPluginManager_Init(t *testing.T) { func TestPluginManager_Init(t *testing.T) {
origRootPath := setting.StaticRootPath origRootPath := setting.StaticRootPath
origRaw := setting.Raw origRaw := setting.Raw
origEnv := setting.Env
t.Cleanup(func() { t.Cleanup(func() {
setting.StaticRootPath = origRootPath setting.StaticRootPath = origRootPath
setting.Raw = origRaw setting.Raw = origRaw
setting.Env = origEnv
}) })
var err error var err error
setting.StaticRootPath, err = filepath.Abs("../../public/") setting.StaticRootPath, err = filepath.Abs("../../public/")
require.NoError(t, err) require.NoError(t, err)
setting.Raw = ini.Empty() setting.Raw = ini.Empty()
setting.Env = setting.PROD
t.Run("Base case", func(t *testing.T) { t.Run("Base case", func(t *testing.T) {
pm := &PluginManager{ pm := &PluginManager{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment