Skip to content

Commit

Permalink
Remove sensitive info from rpc logging.
Browse files Browse the repository at this point in the history
Fixes bug 920687

Change-Id: Ic83145adcfe73c29a85e7916f2fda48d1bb5ccea
  • Loading branch information
rconradharris committed Jan 23, 2012
1 parent 9019b09 commit ccbc940
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
17 changes: 17 additions & 0 deletions nova/rpc/common.py
Expand Up @@ -17,6 +17,7 @@
# License for the specific language governing permissions and limitations
# under the License.

import copy

from nova import exception
from nova import flags
Expand Down Expand Up @@ -102,3 +103,19 @@ def consume_in_thread(self):
pool for dispatching the messages to the proxy objects.
"""
raise NotImplementedError()


def _safe_log(log_func, msg, msg_data):
"""Sanitizes the msg_data field before logging."""
SANITIZE = {'set_admin_password': ('new_pass',)}
method = msg_data['method']
if method in SANITIZE:
msg_data = copy.deepcopy(msg_data)
args_to_sanitize = SANITIZE[method]
for arg in args_to_sanitize:
try:
msg_data['args'][arg] = "<SANITIZED>"
except KeyError:
pass

return log_func(msg, msg_data)
2 changes: 1 addition & 1 deletion nova/rpc/impl_carrot.py
Expand Up @@ -258,7 +258,7 @@ def process_data(self, message_data, message):
# the previous context is stored in local.store.context
if hasattr(local.store, 'context'):
del local.store.context
LOG.debug(_('received %s') % message_data)
rpc_common._safe_log(LOG.debug, _('received %s'), message_data)
# This will be popped off in _unpack_context
msg_id = message_data.get('_msg_id', None)
ctxt = _unpack_context(message_data)
Expand Down
2 changes: 1 addition & 1 deletion nova/rpc/impl_kombu.py
Expand Up @@ -700,7 +700,7 @@ def __call__(self, message_data):
# the previous context is stored in local.store.context
if hasattr(local.store, 'context'):
del local.store.context
LOG.debug(_('received %s') % message_data)
rpc_common._safe_log(LOG.debug, _('received %s'), message_data)
ctxt = _unpack_context(message_data)
method = message_data.get('method')
args = message_data.get('args', {})
Expand Down

0 comments on commit ccbc940

Please sign in to comment.