Skip to content

Commit

Permalink
Refactor keystone session TLS verification
Browse files Browse the repository at this point in the history
This patch refactors the session verify configuration into a single method
for all Keystone related operations.
  • Loading branch information
Dany9966 committed Jul 30, 2024
1 parent 6acc2e1 commit e735358
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions coriolis/keystone.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,20 @@ def _get_trusts_auth_plugin(trust_id=None):
CONF, TRUSTEE_CONF_GROUP, trust_id=trust_id)


def create_trust(ctxt):
if ctxt.trust_id:
return

def _get_verify_option():
cafile = CONF.keystone.cafile
if cafile and cafile != "":
verify = cafile
else:
verify = not CONF.keystone.allow_untrusted

return verify


def create_trust(ctxt):
if ctxt.trust_id:
return

LOG.debug("Creating Keystone trust")

trusts_auth_plugin = _get_trusts_auth_plugin()
Expand All @@ -63,7 +67,7 @@ def create_trust(ctxt):
project_name=ctxt.project_name,
project_domain_name=ctxt.project_domain_name)
session = ks_session.Session(
auth=auth, verify=verify)
auth=auth, verify=_get_verify_option())

try:
trustee_user_id = trusts_auth_plugin.get_user_id(session)
Expand Down Expand Up @@ -100,7 +104,7 @@ def delete_trust(ctxt):

auth = _get_trusts_auth_plugin(ctxt.trust_id)
session = ks_session.Session(
auth=auth, verify=not CONF.keystone.allow_untrusted)
auth=auth, verify=_get_verify_option())
client = kc_v3.Client(session=session)
try:
client.trusts.delete(ctxt.trust_id)
Expand All @@ -110,11 +114,7 @@ def delete_trust(ctxt):


def create_keystone_session(ctxt, connection_info={}):
allow_untrusted = connection_info.get(
"allow_untrusted", CONF.keystone.allow_untrusted)
# TODO(alexpilotti): add "ca_cert" to connection_info
verify = not allow_untrusted

username = connection_info.get("username")
auth = None

Expand All @@ -137,10 +137,6 @@ def create_keystone_session(ctxt, connection_info={}):
"password": password,
}

cafile = CONF.keystone.cafile
if cafile and cafile != "":
verify = cafile

if not auth:
project_name = connection_info.get("project_name", ctxt.project_name)

Expand Down Expand Up @@ -200,4 +196,4 @@ def create_keystone_session(ctxt, connection_info={}):
loader = loading.get_plugin_loader(plugin_name)
auth = loader.load_from_options(**plugin_args)

return ks_session.Session(auth=auth, verify=verify)
return ks_session.Session(auth=auth, verify=_get_verify_option())

0 comments on commit e735358

Please sign in to comment.