Commit Graph

30 Commits

Author SHA1 Message Date
Sahid Orentino Ferdjaoui 70337682d9 auth_token: fix issue when data in cache gets corrupted
Previously token cache was not correctly handling the case when data
in memcached is un-decryptable.
The cache process was returning a null value that was not considered
resulting a python exception raised

The commit fixes the issue by adding a condition to validate the value
returned.

Closes-bug: #2023015
Change-Id: Ic48d20569980781febc194083651736bed446953
Signed-off-by: Sahid Orentino Ferdjaoui <sahid.ferdjaoui@industrialdiscipline.com>
2023-08-14 14:42:50 +00:00
Stephen Finucane 22408f8da0 Remove six
Change-Id: Ib3edfdd087ed1d954f1ecf72a191138f8f1c46a1
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2023-06-27 18:03:31 +01:00
Michal Arbet 788d3c4969 Switch to eventlet-safe oslo.cache's MemcacheClientPool
In past days there were discussions about various issues
with memcached connections [1][2][3].

After investigation it looks like common root cause for above
problems is keystonemiddleware. More precisely said the way
how keystonemiddleware is caching tokens.

Currently it's using some home-made CachePool with direct
usage of memcached library, moreover it looks like its
approach is not eventlet-safe.
Discussion can be mainly found in [4].

Fortunately keystonemiddleware can use "advanced cache pool",
which is oslo.cache's implementation and was added long time ago [5],
but it is turned on only if memcache_use_advanced_pool=True.

This patch is switching to more elaborated oslo.cache CachePool
and adding deprecation warning about eventlet-unsafe variant
of keystonemiddleware's memcache pool.

How to reproduce ?

with memcache_use_advanced_pool=False

1. Build clean ENV of openstack
2. Deploy core projects (keystone,glance,nova,placement...)
3. Run while true; do COMMAND FOR SERVICE; done
   - several bashes, in parallel (5-7)

COMMAND FOR SERVICE:
- openstack network list
- openstack volume list
- openstack server list
- openstack image list

4. Check memcached connections (which will grow up):
    - ss | grep 11211 | wc -l   every second

How to fix and test it ?

Repeat above, to fix:
 - with memcache_use_advanced_pool=True
   OR
 - apply this patch

Compare measurements in graph.

[1] https://bugs.launchpad.net/keystonemiddleware/+bug/1892852
[2] https://bugs.launchpad.net/oslo.cache/+bug/1888394
[3] https://bugs.launchpad.net/keystonemiddleware/+bug/1883659

[4] https://review.opendev.org/c/openstack/oslo.cache/+/742193

[5] https://review.opendev.org/c/openstack/keystonemiddleware/+/268664

Closes-Bug: #1883659
Closes-Bug: #1892852
Closes-Bug: #1888394

Change-Id: I0e96334b65a0bf369ebf1d88651d13feb8d2ecac
2021-02-11 14:36:25 +00:00
Morgan Fainberg c46f29278d Fix KeystoneMiddleware memcachepool abstraction
Keystonemiddleware's abstraction for the memcache pool was broken
when converting to use a queue.Queue. The logic that placed the
connection back into the pool was moved to .acquire and the reserve
method was not using acquire.

Change-Id: I0eda5981cbb661f63790258cf8e70c7340615159
Closes-Bug: #1782404
2018-07-18 11:56:43 -07:00
wangxiyuan 33a712bed7 Fix the AttributeError: __exit__ error
The memcache client class actually has no __exit__ function.

Remove the "with" usage to avoid the __exit__ error.

Change-Id: I15b3d08f4afae289e7eb0848ff1db08141196d3c
Closes-Bug: #1747565
2018-02-22 16:31:11 +08:00
wangxiyuan ce06c0ce10 Add arguments for MemcacheClientPool init
Now keystonemiddleware use oslo.cache to init the
MemcacheClientPool. The MemcacheClientPool in
Olso.cache needs (urls, arguments, **kwargs) parameter
to init, but keystonemiddleware passed only
(urls, **kwargs). Then it leads the error:
__init__() takes exactly 3 arguments (2 given)

This patch fixed this issue.

Please note that even this error is fixed, set
"memcache_use_advanced_pool = True" will lead another
error, see bug #1747565 for the detail. It will be
fixed in the following patch.

Closes-bug: #1748160
Change-Id: I642f959ab8b010207314312a6b6a06a6de23e92c
2018-02-22 16:27:31 +08:00
Mehdi Abaakouk a08bc44e04 rel-note and doc for lazy loading of oslo_cache
In continuation of I00e953abb3e835a94353fe458100c96e8e9c095a,
this change adds the release note and documentation.

Related-bug #1737115

Change-Id: I456239842d139074cc38cfd620bb88561bb4d0d7
2017-12-13 11:57:54 +01:00
Mehdi Abaakouk 35fa0e1da1 lazy loading of oslo_cache
Now, we depend on oslo.cache [1], and use the private/internal
memcache_pool code of the lib, making oslo.cache failing to import
instead of just log an error about missing requirement for selected
drivers at runtime.

This change restores the previous behavior by lazy loading the module.

[1] 9d8e2836fe

Change-Id: I00e953abb3e835a94353fe458100c96e8e9c095a
Closes-bug: #1737115
2017-12-12 19:05:28 +01:00
Jamie Lennox 9d8e2836fe Use oslo_cache in auth_token middleware
Use the new oslo.cache library instead of using memcached directly.
This keeps the old options around and will continue to use those in
preference to the oslo.config library as there is no way to test whether
oslo.cache was explicitly configured to use that in preference.

Currently there are no messages or anything to deprecate the old options
until we've had a chance to test it in production environments.

Closes-Bug: #1523375
Change-Id: Ifccacc5db311ad538ce60191cbe221644d1a5807
Co-Authored-By: Nicolas Helgeson <nh202b@att.com>
2017-12-01 16:36:40 -08:00
D G Lee 50fcc70df1 Remove log translations
Log messages are no longer being translated. This removes all use of
the _LE, _LI, and _LW translation markers to simplify logging and to
avoid confusion with new contributions.

See:
http://lists.openstack.org/pipermail/openstack-i18n/2016-November/002574.html
http://lists.openstack.org/pipermail/openstack-dev/2017-March/113365.html

Change-Id: I73ca5fc046ad04505b52ca93c9bbdbfd72405aed
2017-05-02 09:58:02 +08:00
Jamie Lennox 41083a5dda Remove oslo-incubator
Oslo-incubator has been deprecated. The only thing that we use from it
is the memorycache which is hopefully going away soon. Copy this
memorycache code into the _cache module so that we can refactor it as
necessary without worrying about oslo-incubator.

Involves some minor cleanups for pep8 fixes and making functions
private.

Change-Id: I7a19d4ded8b538b6ea02e4a08068c863705194a3
2016-07-05 10:52:34 +10:00
Dolph Mathews ee73f702a3 Fix D202: No blank lines allowed after function docstring (PEP257)
Change-Id: I634dc4b1dd8fcbab05958d528888325451e2f930
2016-05-17 00:23:30 +00:00
Jenkins f1fbf82aac Merge "Handle cache invalidate outside cache object" 2016-05-11 22:24:07 +00:00
Navid Pustchi ed931a00d8 Fix D204 PEP257 violation and enable D301 and D209
Currently tox ignores D204, D209 and D301:
D204: 1 blank line required after class docstring.
D209: Multi-line docstring closing quotes should be on a separate line.
D301: Use r""" if any backslashes in a docstring.

This change makes keystonemiddleware docstrings compliant with D204.
D209 and D301 is already passing, so this commit also enables them.

Change-Id: I11e02ef5af7fc793f1a2438e091bbfb18618a7f5
2016-05-06 16:36:15 +00:00
Jamie Lennox f54ff06c1f Handle cache invalidate outside cache object
Move the logic that handles invalid cache entries out of the cache
object itself. This makes the cache interface more normal and will make
it easier to convert to oslo.cache later.

Rename the store method to set because this is the interface that
oslo.cache uses.

Related-Bug: #1523375
Change-Id: Ia7b11a69f14e17a9d7a36c009d9a965be16509d0
2016-04-04 14:54:55 +10:00
Brant Knudson f1aa4866c1 Deprecate in-process cache
For a long time now if you don't configure memcache then
auth_token middleware would cache the tokens in process
memory.

This is not the job of auth_token middleware. If you need to
cache you should configure memcache otherwise auth_token will
authenticate with keystone for every token request.

As such, this feature is deprecated and may be removed in the
5.0.0 release or the "O" development cycle (whichever is later).

Change-Id: Ied2b88c8cefe5655a88d0c2f334de04e588fa75a
2016-01-22 11:01:41 -06:00
Brant Knudson 70a9754ae6 Revert "Disable memory caching of tokens"
This reverts commit f27d7f776e.

This change broke the gate due to causing timeouts. The
functionality needs to go through the normal deprecation before
being removed.

Change-Id: I4ab07f6e2bd5bd084bd16707126728929a4ba0f7
2016-01-22 09:52:39 -06:00
Jamie Lennox f27d7f776e Disable memory caching of tokens
For a long time now if you don't configure memcache then auth_token
middleware would cache the tokens in process memory.

This is not the job of auth_token middleware. If you need to cache you
should configure memcache otherwise auth_token will authenticate with
keystone for every token request.

Change-Id: Idf7d864fe8b054738d8a240bc3da377a95eb7e62
2016-01-12 05:34:39 +00:00
Eric Brown 39560c7748 Use oslo_config choices support
The oslo_config library added support for a choices keyword argument in
version 1.2.0a3.  This commit leverages the use of choices for StrOpts of
keystonemiddleware configuration.

Change-Id: I8d9ee833263560caaffe083487abc5eda862f8ea
Closes-Bug: 1423973
2016-01-06 13:42:29 -08:00
Lance Bragstad 01297dce1a Address hacking check H405.
Previously, there were a string of commits to keystone that addresed ignored
hacking checks. This commit does the same for H405 in keystonemiddleware. This
also modifies our tox.ini so that we no longer ignore H405 violations.

This is a non-functional change.

Change-Id: I7bbe99719feb39e96634c903991294c18c33112b
Closes-Bug: 1482773
2015-11-16 22:34:32 +00:00
Jamie Lennox dfd228029e Import _memcache_pool normally
_memcache_pool is imported within a function so that we don't have a hard
dependency on memcache. This is a good idea but _memcache_pool doesn't
have a hard dependency on memcache either so there's no reason to
protect against this here.

Change-Id: I81418fc9fd41e40b9d508ad937d157b2f9ec44c1
2015-09-01 13:47:15 +10:00
Jamie Lennox 36d79649bc Create Environment cache pool
We have three distinct ways that a cache pool can be created, however
only two cache pool classes with the regular _CachePool doubling up.
There's no reason for this and it's harder to read.

Create a very simple _EnvCachePool for the situation where a cache
object was passed down through environment variables.

Change-Id: I86147e887efd6ae302caa12ce996be697d36aa17
2015-09-01 13:47:08 +10:00
Jamie Lennox e9ad5188de Handle memcache pool arguments collectively
Tracing the usage of memcache pool arguments goes through 3 different
functions and involves slightly tweaking the parameter names each time.

This was making it impossible to reason with so collapse down the
memcache arguments into a dictionary that is passed around.

Change-Id: I8bd5cb50183795d9b8fd953dabd935f15f03a385
2015-09-01 13:45:31 +10:00
Morgan Fainberg 2d4e19404a Ensure cache keys are a known/fixed length
Do not assume a token_id will result in a sane length for a memcache
key length. In cases such as Fernet, these ids can easily exceed the
limit on memcache key size. This change ensures we always use a SHA256
of the token id passed in, resulting in a fixed length cache key.

Change-Id: I550e0a1b190047438756bbf40490815a5f177ea7
Closes-Bug: #1460225
2015-06-12 10:36:56 +02:00
Jamie Lennox c965851d86 Don't store expire into memcache
There are two times related to storing token values in memcache. The
memcache timeout and the expiry that is saved alongside the token. We
purposefully set the timeout to be longer than the expiry so that we can
cache that we have seen an expired token.

The expiry that is saved with the token is taken from within the token
body itself and tested for expiry before being returned from the cache.
This expiry is still present in the token body though and it means that
we have two different but exactly the same paths for where we test
expiry from.

Change the cache so that it always returns the full token body from the
cache. This way it is a drop in replacement for fetching the body from
keystone server or from within PKI and the token data is validated in
one place.

Change-Id: Ibe9816826e7d78b7ae25085f07ff9a2f18db9db0
2015-06-03 09:36:48 +10:00
Jamie Lennox 530b5cbe5c Cleanup token hashes generated by cache
We hash a token under multiple configurable algorithms for revocations
and caching and so must check all of them. This hash generation was
being done and returned by the cache check and reused in revocation
check. This is an unusual pattern and requires the cache object to have
knowledge of token types and how to hash them.

Change validate so that we generate the hash values in the main function
and pass that to the cache and revocation functions. This moves the
function to get the first available token id from the list to the main
file. This means the cache interface is much more normal with get and
set id functions and encapsulates the hash list function in the one
file.

Change-Id: I9194dbd052674f64122ff74329ce292a342512d3
2015-05-13 12:02:19 +10:00
Victor Stinner 83f5d3ab5d Port keystonemiddleware to Python 3
On Python 3, memcache returns data as Unicode, but the hmac module
expects bytes. Encode data to UTF-8.

Fix also DisableModuleFixture.clear_module() on Python 3. dict.keys() is
now an iterator on Python 3: create a list because sys.modules is
modified in the loop body.

Closes-Bug: #1449423
Change-Id: Id4805c01b0127a3a86235a7d1a4bb3863b51a6b6
2015-04-28 10:30:21 +02:00
Mitsuhiro SHIGEMATSU abcdbb3afe Fix typos in keystonemiddleware
there were a few instances of 'memcache' instead of
'memcached'

Change-Id: I721ae76881ba566fa891a1655443149ea0ae0c8c
2015-04-05 16:12:43 +00:00
Brant Knudson 50c2baf1ad Move _memcache_pool into auth_token
The _memcache_pool module is only used by auth_token, so move it
in there.

Change-Id: I9a57ac68c9bffa42cece7ea966e7aef1653386ef
2015-03-13 08:59:15 -05:00
Jamie Lennox 9a511ee24e Extract all TokenCache related classes to file
Extract the two types of TokenCache and its helper classes to their
own file.

Change-Id: If8d703597b4dd1c578eaf5adc24e97962d5f08a2
Implements: bp refactor-extract-module
2015-02-26 10:01:15 +11:00