Commit 8fb06da3 by Leonard Gram Committed by GitHub

Plugins: allow override when allowing unsigned plugins (#28901)

* Plugins: allow override when allowing unsigned plugins

* Update pkg/plugins/plugins.go

Co-authored-by: Emil Tullstedt <emil.tullstedt@grafana.com>

* Plugins: removed java-style setter

* Plugins: cleanup

* Update pkg/plugins/plugins.go

Co-authored-by: Agnès Toulet <35176601+AgnesToulet@users.noreply.github.com>

Co-authored-by: Emil Tullstedt <emil.tullstedt@grafana.com>
Co-authored-by: Agnès Toulet <35176601+AgnesToulet@users.noreply.github.com>
parent 5b00b500
...@@ -40,6 +40,8 @@ var ( ...@@ -40,6 +40,8 @@ var (
pluginScanningErrors map[string]*PluginError pluginScanningErrors map[string]*PluginError
) )
type unsignedPluginConditionFunc = func(plugin *PluginBase) bool
type PluginScanner struct { type PluginScanner struct {
pluginPath string pluginPath string
errors []error errors []error
...@@ -48,6 +50,7 @@ type PluginScanner struct { ...@@ -48,6 +50,7 @@ type PluginScanner struct {
requireSigned bool requireSigned bool
log log.Logger log log.Logger
plugins map[string]*PluginBase plugins map[string]*PluginBase
allowUnsignedPluginsCondition unsignedPluginConditionFunc
} }
type PluginManager struct { type PluginManager struct {
...@@ -55,6 +58,10 @@ type PluginManager struct { ...@@ -55,6 +58,10 @@ type PluginManager struct {
Cfg *setting.Cfg `inject:""` Cfg *setting.Cfg `inject:""`
log log.Logger log log.Logger
scanningErrors []error scanningErrors []error
// AllowUnsignedPluginsCondition changes the policy for allowing unsigned plugins. Signature validation only runs when plugins are starting
// and running plugins will not be terminated if they violate the new policy.
AllowUnsignedPluginsCondition unsignedPluginConditionFunc
} }
func init() { func init() {
...@@ -193,6 +200,7 @@ func (pm *PluginManager) scan(pluginDir string, requireSigned bool) error { ...@@ -193,6 +200,7 @@ func (pm *PluginManager) scan(pluginDir string, requireSigned bool) error {
requireSigned: requireSigned, requireSigned: requireSigned,
log: pm.log, log: pm.log,
plugins: map[string]*PluginBase{}, plugins: map[string]*PluginBase{},
allowUnsignedPluginsCondition: pm.AllowUnsignedPluginsCondition,
} }
// 1st pass: Scan plugins, also mapping plugins to their respective directories // 1st pass: Scan plugins, also mapping plugins to their respective directories
...@@ -405,21 +413,13 @@ func (s *PluginScanner) validateSignature(plugin *PluginBase) *PluginError { ...@@ -405,21 +413,13 @@ func (s *PluginScanner) validateSignature(plugin *PluginBase) *PluginError {
switch plugin.Signature { switch plugin.Signature {
case PluginSignatureUnsigned: case PluginSignatureUnsigned:
allowUnsigned := false if allowed := s.allowUnsigned(plugin); !allowed {
for _, plug := range s.cfg.PluginsAllowUnsigned {
if plug == plugin.Id {
allowUnsigned = true
break
}
}
if setting.Env != setting.Dev && !allowUnsigned {
s.log.Debug("Plugin is unsigned", "id", plugin.Id) s.log.Debug("Plugin is unsigned", "id", plugin.Id)
s.errors = append(s.errors, fmt.Errorf("plugin %q is unsigned", plugin.Id)) s.errors = append(s.errors, fmt.Errorf("plugin %q is unsigned", plugin.Id))
return &PluginError{ return &PluginError{
ErrorCode: signatureMissing, ErrorCode: signatureMissing,
} }
} }
s.log.Warn("Running an unsigned backend plugin", "pluginID", plugin.Id, "pluginDir", s.log.Warn("Running an unsigned backend plugin", "pluginID", plugin.Id, "pluginDir",
plugin.PluginDir) plugin.PluginDir)
return nil return nil
...@@ -440,6 +440,24 @@ func (s *PluginScanner) validateSignature(plugin *PluginBase) *PluginError { ...@@ -440,6 +440,24 @@ func (s *PluginScanner) validateSignature(plugin *PluginBase) *PluginError {
} }
} }
func (s *PluginScanner) allowUnsigned(plugin *PluginBase) bool {
if s.allowUnsignedPluginsCondition != nil {
return s.allowUnsignedPluginsCondition(plugin)
}
if setting.Env == setting.Dev {
return true
}
for _, plug := range s.cfg.PluginsAllowUnsigned {
if plug == plugin.Id {
return true
}
}
return false
}
func ScanningErrors() []PluginError { func ScanningErrors() []PluginError {
scanningErrs := make([]PluginError, 0) scanningErrs := make([]PluginError, 0)
for id, e := range pluginScanningErrors { for id, e := range pluginScanningErrors {
......
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