From ced97d218b6452754f335f1787ceefeac6395905 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Sat, 3 Feb 2024 22:01:56 +0900 Subject: [PATCH] memcache: Remove "default" username and password Because these are not intentional default. This also adds a validation logic to catch the case where SASL is requested but username or password is not given. Change-Id: Ia98bfc5f9a42c13acfdb2192bb1fa11773f6ccf8 --- oslo_cache/_opts.py | 2 -- oslo_cache/backends/memcache_pool.py | 6 ++++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/oslo_cache/_opts.py b/oslo_cache/_opts.py index 0787959f..1849b992 100644 --- a/oslo_cache/_opts.py +++ b/oslo_cache/_opts.py @@ -122,10 +122,8 @@ FILE_OPTIONS = { help='Enable the SASL(Simple Authentication and Security' 'Layer) if the SASL_enable is true, else disable.'), cfg.StrOpt('memcache_username', - default='', help='the user name for the memcached which SASL enabled'), cfg.StrOpt('memcache_password', - default='', secret=True, help='the password for the memcached which SASL enabled'), cfg.BoolOpt('tls_enabled', diff --git a/oslo_cache/backends/memcache_pool.py b/oslo_cache/backends/memcache_pool.py index cf68a884..0ad36cb5 100644 --- a/oslo_cache/backends/memcache_pool.py +++ b/oslo_cache/backends/memcache_pool.py @@ -27,6 +27,7 @@ except ImportError as e: else: raise from oslo_cache import _memcache_pool +from oslo_cache import exception # Helper to ease backend refactoring @@ -63,6 +64,11 @@ class PooledMemcachedBackend(memcached_backend.MemcachedBackend): def __init__(self, arguments): super(PooledMemcachedBackend, self).__init__(arguments) if arguments.get('sasl_enabled', False): + if (arguments.get('username') is None or + arguments.get('password') is None): + raise exception.ConfigurationError( + 'username and password should be configured to use SASL ' + 'authentication.') if not _bmemcache_pool: raise ImportError("python-binary-memcached package is missing") self.client_pool = _bmemcache_pool.BMemcacheClientPool(