三方库:keystonemiddleware
入口:auth_token/init.py#filter_factory()方法
通过之前的wsgi知识可以知道,消息在中间件中传递的时候是调用的中间件的call方法;
这里是调用了父类BaseAuthProtocol的call方法,然后调用到AuthProtocol的process_request方法;
如果token非法则抛出异常返回401;合法则业务继续向下流动。
[keystone_authtoken]
token_cache_time = 300
keystone_offline_time = 0
check_revocations_for_cached = false
revocation_cache_time = 86400
insecure = true
cafile = xxx
auth_section = trustee
[trustee]
auth_type = password
auth_url = xxxx
username = ts
password = xxx
user_domain_name = op_service
insecure = true
根据header中塞入的内容不同分别走走不同的流程:service_token和user_token;
两者大体流程一致。
931 try:
932 return verify()
933 except ksc_exceptions.CertificateConfigError:
934 # the certs might be missing; unconditionally fetch to avoid racing
935 self._fetch_signing_cert()
936 self._fetch_ca_cert()
937
938 try:
939 # retry with certs in place
940 return verify()
941 except ksc_exceptions.CertificateConfigError as err:
942 # if this is still occurring, something else is wrong and we
943 # need err.output to identify the problem
944 self.log.error(_LE(‘CMS Verify output: %s‘), err.output)
945 raise
946 except ksm_exceptions.InvalidToken:
947 # Used for mo_pki certificate updates,
948 # while local authentication files are still old.
949 self._fetch_signing_cert()
950 self._fetch_ca_cert()
951
952 # retry with certs in place
953 return verify()
其中
except ksm_exceptions.InvalidToken:
# Used for mo_pki certificate updates,
# while local authentication files are still old.
self._fetch_signing_cert()
self._fetch_ca_cert()
# retry with certs in place
return verify()
为新增的代码片段。
keystonemiddleware
中使用keystoneClient
客户端去请求证书内容,
其中keystoneClient
就是访问的配置文件中定义的auth_url
地址(auth_url
节点服务器就是获取token的地方)。
主要验证token是否快超期
根据下面的策略
class _BIND_MODE(object):
DISABLED = ‘disabled’
PERMISSIVE = ‘permissive’
STRICT = ‘strict’
REQUIRED = ‘required’
KERBEROS = ‘kerberos’
然后判断绑定的是否合理
参考文档:https://www.cnblogs.com/menkeyi/p/6995372.html
原文:https://www.cnblogs.com/tunsuy/p/14723512.html