Add service_token for nova-neutron interaction
Service token will be passed along with user token to communicate with services when dealing with long running tasks like live migration. This change addresses adding service_token to the request when nova requests neutron session. Implements: blueprint use-service-tokens Change-Id: I5e6d6dfeda3673d38bab0bc692c50ca74eb90fc1
This commit is contained in:
parent
9e54b29c4f
commit
596e8de5eb
@ -32,7 +32,7 @@ service_user_opts = [
|
|||||||
When True, if sending a user token to an REST API, also send a service token.
|
When True, if sending a user token to an REST API, also send a service token.
|
||||||
|
|
||||||
Nova often reuses the user token provided to the nova-api to talk to other
|
Nova often reuses the user token provided to the nova-api to talk to other
|
||||||
REST APIs, such as Cinder. It is possible that while the
|
REST APIs, such as Cinder and Neutron. It is possible that while the
|
||||||
user token was valid when the request was made to Nova, the token may expire
|
user token was valid when the request was made to Nova, the token may expire
|
||||||
before it reaches the other service. To avoid any failures, and to
|
before it reaches the other service. To avoid any failures, and to
|
||||||
make it clear it is Nova calling the service on the users behalf, we include
|
make it clear it is Nova calling the service on the users behalf, we include
|
||||||
|
@ -39,6 +39,8 @@ from nova.pci import request as pci_request
|
|||||||
from nova.pci import utils as pci_utils
|
from nova.pci import utils as pci_utils
|
||||||
from nova.pci import whitelist as pci_whitelist
|
from nova.pci import whitelist as pci_whitelist
|
||||||
from nova.policies import base as base_policies
|
from nova.policies import base as base_policies
|
||||||
|
from nova import service_auth
|
||||||
|
|
||||||
|
|
||||||
CONF = nova.conf.CONF
|
CONF = nova.conf.CONF
|
||||||
|
|
||||||
@ -136,7 +138,7 @@ def get_client(context, admin=False):
|
|||||||
auth_plugin = _ADMIN_AUTH
|
auth_plugin = _ADMIN_AUTH
|
||||||
|
|
||||||
elif context.auth_token:
|
elif context.auth_token:
|
||||||
auth_plugin = context.get_auth_plugin()
|
auth_plugin = service_auth.get_auth_plugin(context)
|
||||||
|
|
||||||
if not auth_plugin:
|
if not auth_plugin:
|
||||||
# We did not get a user token and we should not be using
|
# We did not get a user token and we should not be using
|
||||||
|
@ -20,6 +20,7 @@ import uuid
|
|||||||
|
|
||||||
from keystoneauth1.fixture import V2Token
|
from keystoneauth1.fixture import V2Token
|
||||||
from keystoneauth1 import loading as ks_loading
|
from keystoneauth1 import loading as ks_loading
|
||||||
|
from keystoneauth1 import service_token
|
||||||
import mock
|
import mock
|
||||||
from mox3 import mox
|
from mox3 import mox
|
||||||
import netaddr
|
import netaddr
|
||||||
@ -140,6 +141,17 @@ class TestNeutronClient(test.NoDBTestCase):
|
|||||||
neutronapi.get_client,
|
neutronapi.get_client,
|
||||||
my_context)
|
my_context)
|
||||||
|
|
||||||
|
def test_non_admin_with_service_token(self):
|
||||||
|
self.flags(send_service_user_token=True, group='service_user')
|
||||||
|
|
||||||
|
my_context = context.RequestContext('userid',
|
||||||
|
uuids.my_tenant,
|
||||||
|
auth_token='token')
|
||||||
|
|
||||||
|
cl = neutronapi.get_client(my_context)
|
||||||
|
self.assertIsInstance(cl.httpclient.auth,
|
||||||
|
service_token.ServiceTokenAuthWrapper)
|
||||||
|
|
||||||
@mock.patch.object(client.Client, "list_networks",
|
@mock.patch.object(client.Client, "list_networks",
|
||||||
side_effect=exceptions.Unauthorized())
|
side_effect=exceptions.Unauthorized())
|
||||||
def test_Unauthorized_user(self, mock_list_networks):
|
def test_Unauthorized_user(self, mock_list_networks):
|
||||||
|
@ -4,11 +4,11 @@ features:
|
|||||||
sent along with the user token, then it will ignore the expiration of user
|
sent along with the user token, then it will ignore the expiration of user
|
||||||
token. This helps deal with issues of user tokens expiring during long
|
token. This helps deal with issues of user tokens expiring during long
|
||||||
running operations, such as live-migration where nova tries to access
|
running operations, such as live-migration where nova tries to access
|
||||||
Cinder at the end of the operation using the user token that has expired.
|
Cinder and Neutron at the end of the operation using the user token that
|
||||||
In order to use this functionality a service user needs to be created.
|
has expired. In order to use this functionality a service user needs to
|
||||||
Add service user configurations in ``nova.conf`` under
|
be created. Add service user configurations in ``nova.conf`` under
|
||||||
``service_user`` group and set ``send_service_user_token`` flag to
|
``service_user`` group and set ``send_service_user_token`` flag to
|
||||||
``True``. The minimum Keytone API version 3.8 and Keystone middleware
|
``True``. The minimum Keytone API version 3.8 and Keystone middleware
|
||||||
version 4.12.0 is required to use this functionality.
|
version 4.12.0 is required to use this functionality.
|
||||||
This only currently works with nova - cinder API interactions.
|
This only currently works with Nova - Cinder and Nova - Neutron API
|
||||||
|
interactions.
|
||||||
|
Loading…
Reference in New Issue
Block a user