From 8417882de56ae5c0c667f2614aedc2f51a1feda2 Mon Sep 17 00:00:00 2001 From: Marcin Kuzminski Date: Mon, 10 Apr 2017 17:14:07 +0200 Subject: [PATCH] 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. --- rhodecode/authentication/base.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/rhodecode/authentication/base.py b/rhodecode/authentication/base.py index 1dff506b..052482d3 100644 --- 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 @@ -557,7 +572,8 @@ def authenticate(username, password, environ=None, auth_type=None, # 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.