Skip to content

Commit 23707a3

Browse files
kajinamitpriteau
authored andcommitted
Hide credentials in contexts from logs
Do not record the full context values in plain format, because these may contain sensitive values such as request token. Use the generic mask feature to detect potentially sensitive fields and replace raw values by '***'. Story: 2011523 Task: 52787 Change-Id: Ic997d36ec188b390473437c874085ef9a8c41f2f Signed-off-by: Takashi Kajinami <kajinamit@oss.nttdata.com> (cherry picked from commit 56af015)
1 parent aabb673 commit 23707a3

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

cloudkitty/common/policy.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from oslo_policy import opts as policy_opts
2424
from oslo_policy import policy
2525
from oslo_utils import excutils
26+
from oslo_utils import strutils
2627

2728
from cloudkitty.common import policies
2829

@@ -108,8 +109,9 @@ def authorize(context, action, target):
108109
init()
109110

110111
try:
111-
LOG.debug('Authenticating user with credentials %(credentials)s',
112-
{'credentials': context.to_dict()})
112+
LOG.debug(
113+
'Authenticating user with credentials %(credentials)s',
114+
{'credentials': strutils.mask_dict_password(context.to_dict())})
113115
return _ENFORCER.authorize(action, target, context,
114116
do_raise=True,
115117
exc=PolicyNotAuthorized,
@@ -120,9 +122,12 @@ def authorize(context, action, target):
120122
LOG.exception('Policy not registered')
121123
except Exception:
122124
with excutils.save_and_reraise_exception():
123-
LOG.error('Policy check for %(action)s failed with credentials '
124-
'%(credentials)s',
125-
{'action': action, 'credentials': context.to_dict()})
125+
LOG.error(
126+
'Policy check for %(action)s failed with credentials '
127+
'%(credentials)s', {
128+
'action': action,
129+
'credentials': strutils.mask_dict_password(
130+
context.to_dict())})
126131

127132

128133
def check_is_admin(context):
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
security:
3+
- |
4+
Previously, cloudkitty-api recorded request token in plain text format when
5+
a request does not comply with policy rules or debug log is enabled. This
6+
has been fixed and now token is masked in logs.

0 commit comments

Comments
 (0)