Noauth should also use request_id from compute_req_id.py
When using noauth midlleware, the context is generated here:
ef6f4e4c8e/nova/api/openstack/auth.py (L56)
as the openstack.request_id from req.environ, previously created in:
https://github.com/openstack/oslo.middleware/blob/master/oslo_middleware/request_id.py#L57
was not included in the initialize of the context obj,
oslo_context.context.Context.__init__ will generate a new request_id for
context obj.
As the req.environ['openstack.request_id'] will later be returned to the
user as the 'x-openstack-request-id' field in the response header, users
may use this for searching etc. But the Nova workflow will all use the
context.request_id, which will lead to an inconsistency problem.
Change-Id: I047b5f66b33ac89b2b5e9170c12bc87d76d0946b
Closes-Bug: #1758031
This commit is contained in:
parent
8df0fc88c4
commit
dbca8153e3
|
@ -14,6 +14,7 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oslo_middleware import request_id
|
||||
import webob.dec
|
||||
import webob.exc
|
||||
|
||||
|
@ -53,10 +54,10 @@ class NoAuthMiddlewareBase(base_wsgi.Middleware):
|
|||
if CONF.api.use_forwarded_for:
|
||||
remote_address = req.headers.get('X-Forwarded-For', remote_address)
|
||||
is_admin = always_admin or (user_id == 'admin')
|
||||
ctx = context.RequestContext(user_id,
|
||||
project_id,
|
||||
is_admin=is_admin,
|
||||
remote_address=remote_address)
|
||||
ctx = context.RequestContext(
|
||||
user_id, project_id, is_admin=is_admin,
|
||||
remote_address=remote_address,
|
||||
request_id=req.environ.get(request_id.ENV_REQUEST_ID))
|
||||
|
||||
req.environ['nova.context'] = ctx
|
||||
return self.application
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
# Copyright (c) 2018 OpenStack Foundation
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oslo_middleware import request_id
|
||||
from oslo_serialization import jsonutils
|
||||
import webob
|
||||
import webob.exc
|
||||
|
||||
import nova.api.openstack.auth
|
||||
import nova.conf
|
||||
from nova import test
|
||||
|
||||
CONF = nova.conf.CONF
|
||||
|
||||
|
||||
class NoAuthMiddleware(test.NoDBTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(NoAuthMiddleware, self).setUp()
|
||||
|
||||
@webob.dec.wsgify()
|
||||
def fake_app(req):
|
||||
self.context = req.environ['nova.context']
|
||||
return webob.Response()
|
||||
|
||||
self.context = None
|
||||
self.middleware = nova.api.openstack.auth.NoAuthMiddleware(fake_app)
|
||||
self.request = webob.Request.blank('/')
|
||||
self.request.headers['X_TENANT_ID'] = 'testtenantid'
|
||||
self.request.headers['X_AUTH_TOKEN'] = 'testauthtoken'
|
||||
self.request.headers['X_SERVICE_CATALOG'] = jsonutils.dumps({})
|
||||
|
||||
def test_request_id_extracted_from_env(self):
|
||||
req_id = 'dummy-request-id'
|
||||
self.request.headers['X_PROJECT_ID'] = 'testtenantid'
|
||||
self.request.headers['X_USER_ID'] = 'testuserid'
|
||||
self.request.environ[request_id.ENV_REQUEST_ID] = req_id
|
||||
self.request.get_response(self.middleware)
|
||||
self.assertEqual(req_id, self.context.request_id)
|
Loading…
Reference in New Issue