# HG changeset patch # User Marcin Kuzminski # Date 2017-04-10 15:14:07 # Node ID 73a21507d67f886ca1ca2146e188fa9cb4283da4 # Parent c0e9cf6d62cfb955c1e93ee6de22b3f76a95dda0 auth-plugins: add mechanismy to remove secrets from plugin logs. - it's not recommended to log things like ldap access passwords or other credentials. - we expose a machanismy for each plugin to define a unsafe keys to be removed. diff --git a/rhodecode/authentication/base.py b/rhodecode/authentication/base.py --- a/rhodecode/authentication/base.py +++ b/rhodecode/authentication/base.py @@ -23,6 +23,7 @@ Authentication modules """ import colander +import copy import logging import time import traceback @@ -109,6 +110,10 @@ class RhodeCodeAuthPluginBase(object): colander.List: 'list', } + # list of keys in settings that are unsafe to be logged, should be passwords + # or other crucial credentials + _settings_unsafe_keys = [] + def __init__(self, plugin_id): self._plugin_id = plugin_id @@ -199,13 +204,23 @@ class RhodeCodeAuthPluginBase(object): settings[node.name] = self.get_setting_by_name(node.name) return settings + def log_safe_settings(self, settings): + """ + returns a log safe representation of settings, without any secrets + """ + settings_copy = copy.deepcopy(settings) + for k in self._settings_unsafe_keys: + if k in settings_copy: + del settings_copy[k] + return settings_copy + @property def validators(self): """ Exposes RhodeCode validators modules """ # this is a hack to overcome issues with pylons threadlocals and - # translator object _() not beein registered properly. + # translator object _() not being registered properly. class LazyCaller(object): def __init__(self, name): self.validator_name = name @@ -559,7 +574,8 @@ def authenticate(username, password, env # load plugin settings from RhodeCode database plugin_settings = plugin.get_settings() - log.debug('Plugin settings:%s', plugin_settings) + plugin_sanitized_settings = plugin.log_safe_settings(plugin_settings) + log.debug('Plugin settings:%s', plugin_sanitized_settings) log.debug('Trying authentication using ** %s **', plugin.get_id()) # use plugin's method of user extraction.