summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHervé Beraud <hberaud@redhat.com>2022-03-09 14:23:29 +0100
committerHervé Beraud <herveberaud.pro@gmail.com>2022-03-15 12:41:49 +0000
commit1a6643e5e03c536f7d4ba2f3c15d2d646ab4dbd7 (patch)
treeb6e7fc478e9bf3b0532bbd27ed306f7d72e5759e
parent473f300b07641d79d5253208a4058e773857bec5 (diff)
downloadoslo-utils-1a6643e5e03c536f7d4ba2f3c15d2d646ab4dbd7.tar.gz
fix strutils password regex
Those regexes will fix Object style representation output. See the payload used in tests for details. This kind of output can be obtained by using the command: ``` $ openstack --debug ``` Co-Authored-By: Daniel Bengtsson <dbengt@redhat.com> Change-Id: I9024be93b109d1b64ca736546c0f69db7a5e06d0 (cherry picked from commit de4429f2be5fa21d1f6e1cacbb3c8417a7c56310) (cherry picked from commit 2c1b0628771695e546b0acb1e3c44c16c0c690db) (cherry picked from commit 90a504672071d61bdae3206c4764bd3528c165d6) (cherry picked from commit a38b56a6f9438d256d6e0f9b03181015f2b27d8c) (cherry picked from commit 1656a00d410374bb5a0e4df7e6f7b7ce3433c608) (cherry picked from commit 5c430356a660d88f1d5b16cb3f5d7d2ee89a9253)
-rw-r--r--oslo_utils/strutils.py2
-rw-r--r--oslo_utils/tests/test_strutils.py11
-rw-r--r--releasenotes/notes/mask-password-pattern-c8c880098743de3e.yaml5
3 files changed, 18 insertions, 0 deletions
diff --git a/oslo_utils/strutils.py b/oslo_utils/strutils.py
index 760693b..caaef0d 100644
--- a/oslo_utils/strutils.py
+++ b/oslo_utils/strutils.py
@@ -80,6 +80,8 @@ _SANITIZE_PATTERNS_WILDCARD = {}
# have two parameters. Use different lists of patterns here.
_FORMAT_PATTERNS_1 = [r'(%(key)s[0-9]*\s*[=]\s*)[^\s^\'^\"]+']
_FORMAT_PATTERNS_2 = [r'(%(key)s[0-9]*\s*[=]\s*[\"\'])[^\"\']*([\"\'])',
+ r'(%(key)s[0-9]*\s*[=]\s*[\"])[^\"]*([\"])',
+ r'(%(key)s[0-9]*\s*[=]\s*[\'])[^\']*([\'])',
r'(%(key)s[0-9]*\s+[\"\'])[^\"\']*([\"\'])',
r'([-]{2}%(key)s[0-9]*\s+)[^\'^\"^=^\s]+([\s]*)',
r'(<%(key)s[0-9]*>)[^<]*(</%(key)s[0-9]*>)',
diff --git a/oslo_utils/tests/test_strutils.py b/oslo_utils/tests/test_strutils.py
index f9fdf5e..9ad8f20 100644
--- a/oslo_utils/tests/test_strutils.py
+++ b/oslo_utils/tests/test_strutils.py
@@ -296,6 +296,17 @@ StringToBytesTest.generate_scenarios()
class MaskPasswordTestCase(test_base.BaseTestCase):
+ def test_namespace_objects(self):
+ payload = """
+ Namespace(passcode='', username='', password='my"password',
+ profile='', verify=None, token='')
+ """
+ expected = """
+ Namespace(passcode='', username='', password='***',
+ profile='', verify=None, token='***')
+ """
+ self.assertEqual(expected, strutils.mask_password(payload))
+
def test_sanitize_keys(self):
lowered = [k.lower() for k in strutils._SANITIZE_KEYS]
diff --git a/releasenotes/notes/mask-password-pattern-c8c880098743de3e.yaml b/releasenotes/notes/mask-password-pattern-c8c880098743de3e.yaml
new file mode 100644
index 0000000..15b3efb
--- /dev/null
+++ b/releasenotes/notes/mask-password-pattern-c8c880098743de3e.yaml
@@ -0,0 +1,5 @@
+---
+security:
+ - |
+ This patch ensures that we mask sensitive data when masking password, even
+ if double quotes are used as password value.