fix: osh.pl: plugin_config 'disabled' key is a boolean

This commit is contained in:
Stéphane Lesimple 2020-12-15 10:04:03 +00:00
parent 6e03fa2877
commit 790802e6da
No known key found for this signature in database
GPG key ID: 4B4A3289E9D35658
2 changed files with 10 additions and 1 deletions

View file

@ -827,7 +827,7 @@ if ($osh_command) {
my $isDisabled = OVH::Bastion::plugin_config(plugin => $osh_command, key => "disabled"); my $isDisabled = OVH::Bastion::plugin_config(plugin => $osh_command, key => "disabled");
# plugin is enabled by default if not explicitly disabled # plugin is enabled by default if not explicitly disabled
if ($isDisabled and $isDisabled->value() =~ /yes/) { if ($isDisabled and $isDisabled->value()) {
main_exit OVH::Bastion::EXIT_RESTRICTED_COMMAND, "plugin_disabled", "Sorry, this plugin has been disabled by policy."; main_exit OVH::Bastion::EXIT_RESTRICTED_COMMAND, "plugin_disabled", "Sorry, this plugin has been disabled by policy.";
} }
if ($isDisabled->is_err && $isDisabled->err ne 'KO_NO_SUCH_FILE') { if ($isDisabled->is_err && $isDisabled->err ne 'KO_NO_SUCH_FILE') {

View file

@ -401,6 +401,15 @@ sub plugin_config {
} }
} }
# compat: we previously expected "yes" as a value for the 'disabled' option, instead of a boolean.
# To keep compatibility we still consider "yes" as a true value (as any non-empty string is),
# however we check that the user was not confused and didn't try to enable the plugin by using
# a string such as "no" or "false" instead of a real false boolean:
if (defined $config{'disabled'} && $config{'disabled'} =~ /no|false/) {
warn_syslog("Configuration error for plugin $plugin on the 'disabled' key: expected a boolean, casted '" . $config{'disabled'} . "' into false");
$config{'disabled'} = 0;
}
$_plugin_config_cache{$plugin} = \%config; $_plugin_config_cache{$plugin} = \%config;
} }