[MM-57194] Allow plugins to mark setting fields as secret (#27986)

Co-authored-by: Claudio Costa <cstcld91@gmail.com>
Этот коммит содержится в:
Ben Schumacher
2024-09-12 19:23:57 +02:00
коммит произвёл GitHub
родитель 84a0c09d56
Коммит 70fe2abea6
13 изменённых файлов: 311 добавлений и 45 удалений

Просмотреть файл

@@ -3197,6 +3197,38 @@ func (s *PluginSettings) SetDefaults(ls LogSettings) {
}
}
// Sanitize cleans up the plugin settings by removing any sensitive information.
// It does so by checking if the setting is marked as secret in the plugin manifest.
// If it is, the setting is replaced with a fake value.
// If a plugin is no longer installed, all settings of it's are sanitized.
// If the list of manifests in nil, i.e. plugins are disabled, all settings are sanitized.
func (s *PluginSettings) Sanitize(pluginManifests []*Manifest) {
manifestMap := make(map[string]*Manifest, len(pluginManifests))
for _, manifest := range pluginManifests {
manifestMap[manifest.Id] = manifest
}
for id, settings := range s.Plugins {
manifest := manifestMap[id]
for key := range settings {
if manifest == nil {
// Sanitize plugin settings for plugins that are not installed
settings[key] = FakeSetting
continue
}
for _, definedSetting := range manifest.SettingsSchema.Settings {
if definedSetting.Secret && strings.EqualFold(definedSetting.Key, key) {
settings[key] = FakeSetting
break
}
}
}
}
}
type WranglerSettings struct {
PermittedWranglerRoles []string
AllowedEmailDomain []string
@@ -4396,7 +4428,7 @@ func (o *Config) GetSanitizeOptions() map[string]bool {
return options
}
func (o *Config) Sanitize() {
func (o *Config) Sanitize(pluginManifests []*Manifest) {
if o.LdapSettings.BindPassword != nil && *o.LdapSettings.BindPassword != "" {
*o.LdapSettings.BindPassword = FakeSetting
}
@@ -4462,6 +4494,8 @@ func (o *Config) Sanitize() {
if o.ServiceSettings.SplitKey != nil {
*o.ServiceSettings.SplitKey = FakeSetting
}
o.PluginSettings.Sanitize(pluginManifests)
}
// structToMapFilteredByTag converts a struct into a map removing those fields that has the tag passed