From 3006787997fbd4a545e80624cf6075e3297d6fe6 Mon Sep 17 00:00:00 2001 From: Davanum Srinivas Date: Tue, 4 Jun 2013 22:26:31 -0400 Subject: Sanitize passwords in _safe_log replace the specific sanitization with a generic one that digs deeper into msg_data and sanitize known password fields. Fixes LP# 1171446 Change-Id: I17926cca13175507b8869b25c1d979da88ac9037 --- openstack/common/rpc/common.py | 49 ++++++++++++------------------------------ 1 file changed, 14 insertions(+), 35 deletions(-) (limited to 'openstack') diff --git a/openstack/common/rpc/common.py b/openstack/common/rpc/common.py index 5eacd32..e116e92 100644 --- a/openstack/common/rpc/common.py +++ b/openstack/common/rpc/common.py @@ -261,41 +261,20 @@ class Connection(object): def _safe_log(log_func, msg, msg_data): """Sanitizes the msg_data field before logging.""" - SANITIZE = {'set_admin_password': [('args', 'new_pass')], - 'run_instance': [('args', 'admin_password')], - 'route_message': [('args', 'message', 'args', 'method_info', - 'method_kwargs', 'password'), - ('args', 'message', 'args', 'method_info', - 'method_kwargs', 'admin_password')]} - - has_method = 'method' in msg_data and msg_data['method'] in SANITIZE - has_context_token = '_context_auth_token' in msg_data - has_token = 'auth_token' in msg_data - - if not any([has_method, has_context_token, has_token]): - return log_func(msg, msg_data) - - msg_data = copy.deepcopy(msg_data) - - if has_method: - for arg in SANITIZE.get(msg_data['method'], []): - try: - d = msg_data - for elem in arg[:-1]: - d = d[elem] - d[arg[-1]] = '' - except KeyError as e: - LOG.info(_('Failed to sanitize %(item)s. Key error %(err)s'), - {'item': arg, - 'err': e}) - - if has_context_token: - msg_data['_context_auth_token'] = '' - - if has_token: - msg_data['auth_token'] = '' - - return log_func(msg, msg_data) + SANITIZE = ['_context_auth_token', 'auth_token', 'new_pass'] + + def _fix_passwords(d): + """Sanitizes the password fields in the dictionary.""" + for k in d.iterkeys(): + if k.lower().find('password') != -1: + d[k] = '' + elif k.lower() in SANITIZE: + d[k] = '' + elif isinstance(d[k], dict): + _fix_passwords(d[k]) + return d + + return log_func(msg, _fix_passwords(copy.deepcopy(msg_data))) def serialize_remote_exception(failure_info, log_failure=True): -- cgit