Commit Graph

159 Commits

Author SHA1 Message Date
Takashi Kajinami e8de6c9ea5 Fix incomplete exception message
This is follow-up of 76d414e58d and fixes
the incomplete construction of an exception message. This also removes
the translation according to the other messages.

Change-Id: Ie2ed619b06d9d6340eb81fc1fac4dbd21702de19
2024-02-18 02:52:02 +09:00
Zuul 8aba3853ab Merge "redis: Add functional tests" 2024-02-14 13:23:58 +00:00
Zuul 98e8de2ec9 Merge "config: Document backends supporting specific options" 2024-02-14 13:19:29 +00:00
Zuul 44285d9a4c Merge "Prevent potential ReDoS attack" 2024-02-13 15:48:31 +00:00
Zuul 4136a7107a Merge "Add support for Redis Sentinel backend" 2024-02-13 13:33:01 +00:00
Zuul 85b30d9061 Merge "Add native options for redis backend" 2024-02-13 13:33:00 +00:00
Zuul 50345eb5b6 Merge "memcache: Remove "default" username and password" 2024-02-13 11:27:54 +00:00
Takashi Kajinami 29d1ab7c9f Prevent potential ReDoS attack
Although the logic is used to parse a config value, it'd be better to
eliminate a risk.

Change-Id: I9ef3fedf9d23f8ca8f87a63a55f1f90e5b07d2f1
2024-02-13 09:37:49 +09:00
Takashi Kajinami 76d414e58d config: Document backends supporting specific options
... and shows the backend actually picked up in logs.

Change-Id: Ib19fdd289444a8db5ebc682e7cb5723b994ae9dc
2024-02-12 20:33:53 +09:00
Takashi Kajinami 6c73ace4f7 redis: Add functional tests
This adds functional tests with redis and redis sentinel, to ensure
the current implementation can initialize clients properly.

Change-Id: I6318f6ad00d5b0ee3db1be5e8671a4c346b9daff
2024-02-04 13:20:54 +00:00
Takashi Kajinami 7bb43bbbd5 Add support for Redis Sentinel backend
This introduces support for Redis Sentinel backend. Users can now
use Redis Sentinel backend instead of Redis backend by configurations
like the example below.

[cache]
enabled = True
backend = dogpile.cache.redis_sentinel
redis_password = <password>
redis_sentinels = 192.0.2.1:26379,192.0.2.2:26379,192.0.2.3:26379

If tls_enabled option is set to True then all the tls settings are
applied for connections to Redis as well as connections to Redis
Sentinel.

Change-Id: Ic3b84fe6810e08337a884c68625ccfed11665269
2024-02-04 13:20:41 +00:00
Takashi Kajinami 28411250da Add native options for redis backend
This introduces a few new redis_* options to simplify the settings
required to use the redis backend. The main aim of this change is to
replace the requirement to inject url by backend_argument.

[cache]
backend=dogpile.cache.redis
redis_server=127.0.0.1:6379
redis_username=default
redis_password=a_big_secret
redis_socket_timeout=1.0

Closes-Bug: #2052351
Change-Id: Id72878f9cddaa99146eab5fb4ee76c8e6a633809
2024-02-04 13:20:18 +00:00
Takashi Kajinami ced97d218b 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
2024-02-04 17:35:38 +09:00
Takashi Kajinami 31201ce71c Automate TLS certificates settings for redis backend
This adds support for configuring certificate/key files used for TLS
connection with Redis using the existing tls_* options.

example)

[cache]
backend=dogpile.cache.backend.redis
backend_arguments=url:rediss://:a_big_secret@localhost:2679
tls_enabled=True
tls_cafile = /etc/pki/tls/certs/ca-bundle.crt

Change-Id: I2ab38b8c88274cb4908791eea8212a79e3d524a2
2024-02-03 20:17:22 +09:00
Takashi Kajinami f1950fdaa9 Fail if tls_enabled is True but backend does not support it
The tls_enabled option works properly only for the following backends.
 - oslo_cache.memcache_pool
 - dogpile.cache.bmemcache
 - dogpile.cache.pymemcache

Currently the tls options are all ignored in case a different backend
is used, but this does not allow users to notice that TLS is not
enabled contrary to their expectations.

This introduces the validation to ensure an appropriate backend is used
when tls is enabled.

NOTE:
The oslo_cache.memcache_pool bakcend supports tls_enabled only when
sasl_enabled is true, which can be fixed separately.

Change-Id: Ib967bf8cb21fb97fff94a6d6cb5983374e4798eb
2024-02-01 02:34:03 +09:00
Takashi Kajinami af77d1da80 Fix minor typos in parameter help texts
Change-Id: I38755167fb67b0b78f6e8ea69e6569f13b35cf74
2024-01-30 18:23:56 +09:00
Hervé Beraud f438770767 Add a new option to enforce the OpenSSL FIPS mode
This option ``enforce_fips_mode`` allow us to enforce the FIPS mode
if supported by the version of python in use.

https://en.wikipedia.org/wiki/Federal_Information_Processing_Standards

Change-Id: I220012094d2be3c2c47a444260bc42fb53aaf6bc
2024-01-23 10:55:17 +01:00
Zuul 6855ffca1d Merge "Clean-up memcache connection sockets" 2024-01-11 17:46:46 +00:00
Zuul 3694193d6c Merge "Do not mark hosts as alive when they are all dead" 2024-01-05 13:33:55 +00:00
Thomas Goirand bae5561d4d Clean-up memcache connection sockets
The ConnectionPool currently opens sockets, but never closes them. As a
result, any client using oslo.cache memcache pool leaves sockets in a
CLOSE_WAIT state, with the source port not being re-usable.

In our production system, were we have A LOT of activity, this creates
a storm of non-reusable ports: all source ports are in use, making the
node unuseable for other things.

This patch adds a __del__ destructor closing inactive connections,
fixing the issue.

Closes-Bug: #2043121
Change-Id: I09d632346c76d1aff7c534f0d040162d1985f548
2023-11-13 15:46:59 +01:00
Takashi Kajinami 790fb9391f [cache] memcache_password should be secret
... because the parameter accepts a password in plain text.

Change-Id: I97df7068cc06c88d9a9adba032a2186a301d7777
2023-03-23 00:50:26 +09:00
Damian Dabrowski e34fbe2925 Do not mark hosts as alive when they are all dead
This feature is supposed to check for alive servers more frequently when they are all down.
Unfortunately, it does more harm than good.

I have made several tests with keystone and here is what I saw when all memcached backends were unreachable:
1. memcached services were stopped but their hosts were alive(keystone received 'connection refused') - everything was working fine
2. memcached backends and their hosts were completely unreachable(keystone received 'no route to host') - the whole keystone stopped responding

Keystone should be working fine even if all memcached backends are down. In this case it wasn't.
After I deleted the discussed functionality from the code, keystone was finally able to handle failure of all memcached backends.
I believe this issue is not only limited to keystone, I just used it as an example.

Change-Id: Ib3e3028d967c166d21b60cf4cb7c9d5dc82a8fe7
2023-02-27 13:41:38 +00:00
Corey Bryant edd10f7a9c Allow bmemcached to be optional for memcache_pool
This allows oslo_cache.memcache_pool to be used without the
python-binary-memcached package being installed, as it is
only required if sasl_enabled is set to True.

Closes-Bug: #1991250
Change-Id: I7e6cc83864be68e946d86b1f4b44847b95ea8b05
2023-02-23 14:55:12 +00:00
Zuul 7fb06bc203 Merge "Support SASL protocol for memcached" 2022-08-03 12:31:42 +00:00
OpenStack Proposal Bot 79945c1ab2 Imported Translations from Zanata
For more information about this automatic import see:
https://docs.openstack.org/i18n/latest/reviewing-translation-import.html

Change-Id: I41cfe5824865714d70e1a739029c8a592f1b9f0c
2022-06-21 03:41:55 +00:00
dengzhaosen d229d3edb7 Support SASL protocol for memcached
Add the SASL protocol for memcached, to improve the security of authority.
SASL(Simple Authentication and Security Layer): is a memchanism used to
extend the verification ability of C/S mode. SASL is only the
authentication process, which integrates the application layer and the
system authentication mechanism. However, the current memcached hasn't
any authenticaction mechanism to protect the user's data cached in
memcached server.

Depends-On: 7828bed0febabfa11a0a8f6960f4c7cc8acec841

Implements: blueprint enable-sasl-protocol

Change-Id: I40b9f4eac518f34a3dfb710b5c4ab3a76da7c00c
2022-05-03 10:58:53 +08:00
songwenping 2d610d0abc Remove unnecessary unicode prefixes
All strings are unicode by default in Python 3. No need to mark them as such.

Change-Id: If2b75ca342bf613d9c1bc3f34f6afcf51a22d640
2022-04-19 15:07:53 +08:00
Takashi Kajinami 557d4a2295 Fix description of memcache_servers
Current description says the option is used by only two backends but
in fact this option is used by all backends dependent on memcached.

Note that the inet6 prefix is specific to the python-memcached library
and should not be used if a backend dependent on different libraries
(eg. pymemcache) is used. This change describes that point, too.

Change-Id: I3c967841c94b9409096c9b9591f9fb162db7a1ac
2022-03-18 23:03:55 +09:00
Hervé Beraud d75020b335 Use the right backend for TLS tests
The TLS features were introduced to be consummed by the
dogpile.cache.pymemcache backend [1][2], however, the tests
modified by this commit do not instantiate the
dogpile.cache.pymemcache backend but rather the oslo_cache.dict
backend which won't consumme the TLS arguments.

These tests do not really reflects the thing they were made for.

The oslo.cache.dict backend do not expect TLS options [3] whereas
the dogpile.cache.memcached module (and backend) expect TLS
context [4].

This patch propose to switch to the right backend.

[1] 996036acd7
[2] a2e25bc743
[3] https://opendev.org/openstack/oslo.cache/src/branch/master/oslo_cache/backends/dictionary.py
[4] https://github.com/sqlalchemy/dogpile.cache/search?q=tls_context

Change-Id: Ia28ce314044f5790372e6a75dd5d6ae0407bec74
2022-02-11 15:16:53 +01:00
Hervé Beraud cb118d04ce Expose pymemcache's HashClient public params
This patch expose a couple of pymemcache's HashClient public
params that can be useful to configure HA and failover for
clustered memcached servers.

These options can be used in addition of the previously added
retrying mechanismes.

This patch rely on recent changes [1] of dogpile.cache that
aim to expose these options too.

[1] https://gerrit.sqlalchemy.org/c/sqlalchemy/dogpile.cache/+/3528

Change-Id: I24fc853db4237c08b87871ddff1b3ced27cc7fce
2022-01-21 08:54:13 +01:00
Hervé Beraud 42bf82d550 Add retry mechanisms to oslo.cache
This patch specifies a set of options required to setup a retry
context.  The context built from those options can later on be
passed to any of the oslo.cache backends that supports pymemcache's
retry mechanisms.

This patch also sets up the retry mechanisms context based on
the configuration option passed via oslo.config and adds it
as an argument to be passed to the selected oslo.cache backend.

Change-Id: I6c1a4872d7cf19e3a55c676ef4b4200f18e08f2c
2022-01-07 11:58:28 +01:00
Hervé Beraud f4fa6aa6fa Add socket keepalive options to oslo.cache
This patch specifies a set of options required to setup the
socket keepalive of the dogpile.cache's pymemcache
backend [1][2]. This setup from those options can later on
be passed to this backend.

This patch also sets up the socket keepalive object based on
the configuration options passed via oslo.config and adds it
as an argument to be passed to the selected oslo.cache backend.

Dogpile.cache will be used as an interface between oslo.cache and
pymemcache [3].

[1] https://github.com/sqlalchemy/dogpile.cache/pull/205
[2]
b289c87bb8
[3]
https://dogpilecache.sqlalchemy.org/en/latest/api.html?highlight=keepalive#dogpile.cache.backends.memcached.PyMemcacheBackend.params.socket_keepalive

Change-Id: I501100e1a48cdd4e094c08046e2150405dcf371e
2022-01-07 11:58:28 +01:00
Hervé Beraud 8290f80e8b Drop pymongo useless and removed attribute
The current version of oslo.cache isn't compatible with the recent
major upgrade of pymongo [1].

These changes remove the usage of this attribut as it is useless
and removed from the recent versions of pymongo [2]. That will
fix our gates.

[1] 7ea8101652
[2] https://pymongo.readthedocs.io/en/stable/migrate-to-pymongo4.html?highlight=MongoReplicaSetClient#mongoreplicasetclient

Change-Id: I21ad7023b14ff2ad33ddd036bfecc905d2c68871
2021-12-13 14:12:31 +01:00
Hervé Beraud 04e3860742 fix typo
Change-Id: I5575d729ccb061c481a039a175ea8d357084496d
2021-07-06 15:03:18 +02:00
Mitya_Eremeev 40946a9349 Don't import module "etcd3gw" if etcd3gw backend is not used.
If module etcd3gw is not required for used backend,
then no need to have it installed and imported.
Otherwise we always have ugly log error:
Could not load 'oslo_cache.etcd3gw': No module named 'etcd3gw': ModuleNotFoundError: No module named 'etcd3gw

Closes-Bug: 1928318
Change-Id: Icbe6dc3e93b4d2fec1ceb88366027294e49d7032
2021-05-26 16:58:31 +00:00
Zuul bce13254d1 Merge "Adding technical details about the memcache pool backend." 2021-04-16 12:57:16 +00:00
Zuul ca02481310 Merge "Drop use of deprecated collections classes" 2021-04-16 11:56:37 +00:00
Hervé Beraud 6f3c6c9e30 Adding technical details about the memcache pool backend.
This backend lack of documentation and technical details.
Many people think that this the memcache pool backend is going to be HA
and think that values are replicated.

The added details try to give more details about how this backend works
under the hood.

Change-Id: If9056168aacca85ae072172ec203319af42962d8
2021-03-10 15:17:54 +01:00
Zuul eed7c03dd6 Merge "Add bug comment and fix nits" 2021-02-08 15:14:36 +00:00
Hervé Beraud e5d0b2019e Add bug comment and fix nits
Change-Id: Icb2b62d7d51cac652f9958ee094fef78a8ac9574
2021-02-05 14:35:18 +01:00
Zuul 062d29b256 Merge "Do not hardcode flush_on_reconnect, move to oslo.cache config" 2021-02-03 12:27:25 +00:00
Stephen Finucane 51d7b465b5 Drop use of deprecated collections classes
These were moved in Python 3.3 and the aliases will be dropped in 3.10.

Change-Id: I98985aef57ebe024e97e444ffd0d43ee2b88b332
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2021-02-01 11:07:54 +00:00
Moisés Guimarães de Medeiros b00b3b23b4 Add dogpile.cache.pymemcache backend
Depends-On: https://review.opendev.org/c/openstack/requirements/+/772684
Change-Id: Ibdc6015ac1a9812976c4f3d8a737f7245599553e
Signed-off-by: Moisés Guimarães de Medeiros <moguimar@redhat.com>
2021-01-27 15:11:27 +01:00
Michal Arbet a437b219ac Do not hardcode flush_on_reconnect, move to oslo.cache config
Param flush_on_reconnect is very risky to use on production
deployments. It can cause exponential raising of connections
to memcached servers. Moreover this option makes sense only
in keystone's oslo.cache config.

This patch is moving flush_on_reconnect from code to oslo.cache
config block to be configurable.

Co-Authored-By: Hervé Beraud <hberaud@redhat.com>
Change-Id: I8e6826bfb2c85e7ceed03e1667bd6a06b3dff469
Closes-Bug: #1888394
2021-01-18 13:59:55 +01:00
Hervé Beraud df075b2465 Adding functional tests for memcache_pool backend
Introducing the needed changes to functional tests to run
them against the memcache_pool backend.

These changes introduced a new zuul job related to memcache
to isolate this part during CI and get clear outputs.

Change-Id: Ib84b3db83e8c50c7929874c63177c94f459a1a2c
Co-authored-by: Radosław Piliszek <radoslaw.piliszek@gmail.com>
2020-08-25 14:01:17 +02:00
Moisés Guimarães de Medeiros a11cde4cc3 Add Memcached functional tests to gate
Change-Id: Ieca5e59e36879ce1e0277ee17a1fbe40c7316958
2020-08-20 14:41:47 +02:00
Moisés Guimarães de Medeiros 996036acd7 Add TLS context creation from config
This patch sets up the TLS context object based on the configuration
options passed via oslo.config and adds it as an argument to be passed
to the selected oslo.cache backend.

Change-Id: I825b5c37b2c6a96b459e6cc162ba5d1254091f0f
Signed-off-by: Moisés Guimarães de Medeiros <moguimar@redhat.com>
2020-06-09 14:28:03 -03:00
Moisés Guimarães de Medeiros c0e7543ca6 Add TLS options to oslo.cache
This patch specifies a set of options required to build a TLS context.
The context built from those options can later on be passed to any of
the oslo.cache backends that supports TLS connections.

Change-Id: Ief83bd490826d90eb5239ebb71394aa516f033b7
Signed-off-by: Moisés Guimarães de Medeiros <moguimar@redhat.com>
2020-06-09 14:22:32 -03:00
Hervé Beraud 6aa289228c Stop to use the __future__ module.
The __future__ module [1] was used in this context to ensure compatibility
between python 2 and python 3.

We previously dropped the support of python 2.7 [2] and now we only support
python 3 so we don't need to continue to use this module and the imports
listed below.

Imports commonly used and their related PEPs:
- `division` is related to PEP 238 [3]
- `print_function` is related to PEP 3105 [4]
- `unicode_literals` is related to PEP 3112 [5]
- `with_statement` is related to PEP 343 [6]
- `absolute_import` is related to PEP 328 [7]

[1] https://docs.python.org/3/library/__future__.html
[2] https://governance.openstack.org/tc/goals/selected/ussuri/drop-py27.html
[3] https://www.python.org/dev/peps/pep-0238
[4] https://www.python.org/dev/peps/pep-3105
[5] https://www.python.org/dev/peps/pep-3112
[6] https://www.python.org/dev/peps/pep-0343
[7] https://www.python.org/dev/peps/pep-0328

Change-Id: Ia4117323b7cf7fd657f072aa40ddfb2eac742f1c
2020-06-02 20:38:32 +02:00
Hervé Beraud 83de99cdad Refactoring functional tests based on standard usages
Refactoring the functional tests by using the standard usages [1]
and best pratices available in the oslo.cache documentation.

The main goal of these changes is to help us to
test oslo.cache in the way that quite close to real life usages.

To test new backend now we just need to create the associated test class
dedicated to pass backend's config fixture.

These changes allow to test a new backend by:
- passing the right config to backend by using dedicated config fixture;
- adding the zuul job dedicated to manage functional tests
  against etcd backend;
- adding the right server backend to bindep.

[1] https://docs.openstack.org/oslo.cache/latest/user/usage.html

Change-Id: Iaf196d2d93225afa54e324fb830761049059926e
2020-05-28 14:34:47 +02:00