当前位置: 代码迷 >> 综合 >> keystonemiddleware支持SASL--系列2
  详细解决方案

keystonemiddleware支持SASL--系列2

热度:94   发布时间:2024-01-29 02:53:36.0

step1:

首先在keystonemiddleware组件的_opts.py文件中,将*.conf文件中的配置项读出来:

[keystone_authtoken]
memcache_sasl_enable = true
memcache_usrname = username
memcache_password = Password
_OPTS = [  
.........cfg.BoolOpt('memcache_sasl_enable',default=False,help='Enable the SASL(Simple Authentication and Security Layer) ''if the SALA_enable is true, else disable.'),cfg.StrOpt('memcache_usrname',default='',help='the user name for the SASL'),cfg.StrOpt('memcache_password',default='',help='the username password for SAS'),
]

step2:

在__init__.py文件中的_token_cache_factory函数中,添加如下的字段:

cache_kwargs = dict(......sasl_enable=self._conf.get('memcache_sasl_enable'),usrname=self._conf.get('memcache_usrname'),password=self._conf.get('memcache_password'),)

后面根据security_strategy选择加密传输或者不加密传输。

1)加密的话,调用

                    _cache.SecureTokenCache(self.log,security_strategy,secret_key,**cache_kwargs)

2)不加密的话,调用:

_cache.TokenCache(self.log, **cache_kwargs)

这样就可以经过传参的方式将上面的三个参数传进去了!

由于类SecureTokenCache也是集成的TokenCache,所以下面只需要分析TokenCache类就可以了!

step3:

1)如果开启_use_advanced_pool的话:会调用:

_MemcacheClientPool(self._memcached_servers,self._arguments,**self._memcache_pool_options)

在_cache.py文件中修改MemcacheClientPool类

class MemcacheClientPool(object):"""An advanced memcached client pool that is eventlet safe."""def __init__(self, memcache_servers, arguments, **kwargs):# NOTE(sileht): This will import python-memcached, we don't want# it as hard dependency, so lazy load it.if ag:from oslo_cache import _bmemcache_poolself._pool = _bmemcache_pool.BMemcacheClientPool(memcache_servers,arguments,**kwargs)else:from oslo_cache import _memcache_poolself._pool = _memcache_pool.MemcacheClientPool(memcache_servers,arguments,

2)如果不开启的话:

_CachePool(self._memcached_servers, self._LOG, **self._memcache_pool_options)

增加一个_memcache_pool_options参数的选项;

然后在类_CachePool中增加如下的属性:

        self._sasl_enable = kwargs.get("sasl_enable")self._usrname = kwargs.get("usrname")self._password = kwargs.get("password")

然后在reserve函数中的代码增加如下:

if self._sasl_enable:import bmemcachedc = bmemcached.Client(self._memcached_servers, self._usrname,self._password)
else:import memcachec = memcache.Client(self._memcached_servers, debug=0)