summaryrefslogtreecommitdiff
path: root/nova/network/neutron.py
diff options
context:
space:
mode:
authormelanie witt <melwittt@gmail.com>2023-05-09 03:11:25 +0000
committermelanie witt <melwittt@gmail.com>2023-05-10 14:52:59 +0000
commit41c64b94b0af333845e998f6cc195e72ca5ab6bc (patch)
treec34fe5f4cb10c814ae0120ff1935660df8870284 /nova/network/neutron.py
parentdb455548a12beac1153ce04eca5e728d7b773901 (diff)
downloadnova-41c64b94b0af333845e998f6cc195e72ca5ab6bc.tar.gz
Enable use of service user token with admin context
When the [service_user] section is configured in nova.conf, nova will have the ability to send a service user token alongside the user's token. The service user token is sent when nova calls other services' REST APIs to authenticate as a service, and service calls can sometimes have elevated privileges. Currently, nova does not however have the ability to send a service user token with an admin context. This means that when nova makes REST API calls to other services with an anonymous admin RequestContext (such as in nova-manage or periodic tasks), it will not be authenticated as a service. This adds a keyword argument to service_auth.get_auth_plugin() to enable callers to provide a user_auth object instead of attempting to extract the user_auth from the RequestContext. The cinder and neutron client modules are also adjusted to make use of the new user_auth keyword argument so that nova calls made with anonymous admin request contexts can authenticate as a service when configured. Related-Bug: #2004555 Change-Id: I14df2d55f4b2f0be58f1a6ad3f19e48f7a6bfcb4
Diffstat (limited to 'nova/network/neutron.py')
-rw-r--r--nova/network/neutron.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/nova/network/neutron.py b/nova/network/neutron.py
index 0ae0f4099f..eef2abe364 100644
--- a/nova/network/neutron.py
+++ b/nova/network/neutron.py
@@ -222,13 +222,15 @@ def _get_auth_plugin(context, admin=False):
# support some services (metadata API) where an admin context is used
# without an auth token.
global _ADMIN_AUTH
+ user_auth = None
if admin or (context.is_admin and not context.auth_token):
if not _ADMIN_AUTH:
_ADMIN_AUTH = _load_auth_plugin(CONF)
- return _ADMIN_AUTH
+ user_auth = _ADMIN_AUTH
- if context.auth_token:
- return service_auth.get_auth_plugin(context)
+ if context.auth_token or user_auth:
+ # When user_auth = None, user_auth will be extracted from the context.
+ return service_auth.get_auth_plugin(context, user_auth=user_auth)
# We did not get a user token and we should not be using
# an admin token so log an error