From: Michael Krotscheck Date: Tue, 1 Mar 2016 19:31:40 +0000 (-0800) Subject: Moved CORS middleware configuration into oslo-config-generator X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=abba4921845cbdb66dfb5112c20dc04446870a42;p=openstack-build%2Fcinder-build.git Moved CORS middleware configuration into oslo-config-generator The default values needed for cinder's implementation of cors middleware have been moved from paste.ini into the configuration hooks provided by oslo.config. Furthermore, these values have been added to cinder's default configuration parsing. This ensures that if a value remains unset in cinder.conf, it will be set to use sane defaults, and that an operator modifying the configuration file will be presented with a default set of necessary sane headers. Depends-on: I658e54966c390b41e3b551dd9827606c2e013511 Change-Id: Ia8735d5952d7e03b6948f748afead13e6f890271 Closes-Bug: 1551836 --- diff --git a/cinder/cmd/all.py b/cinder/cmd/all.py index 705fbff06..28b897588 100644 --- a/cinder/cmd/all.py +++ b/cinder/cmd/all.py @@ -59,6 +59,7 @@ def main(): gmr_opts.set_defaults(CONF) CONF(sys.argv[1:], project='cinder', version=version.version_string()) + config.set_middleware_defaults() logging.setup(CONF, "cinder") LOG = logging.getLogger('cinder.all') diff --git a/cinder/cmd/api.py b/cinder/cmd/api.py index 80e25eed4..aef3f58cb 100644 --- a/cinder/cmd/api.py +++ b/cinder/cmd/api.py @@ -34,7 +34,7 @@ from cinder import i18n i18n.enable_lazy() # Need to register global_opts -from cinder.common import config # noqa +from cinder.common import config from cinder import rpc from cinder import service from cinder import utils @@ -49,6 +49,7 @@ def main(): gmr_opts.set_defaults(CONF) CONF(sys.argv[1:], project='cinder', version=version.version_string()) + config.set_middleware_defaults() logging.setup(CONF, "cinder") python_logging.captureWarnings(True) utils.monkey_patch() diff --git a/cinder/common/config.py b/cinder/common/config.py index 65390fad2..24ee23d0b 100644 --- a/cinder/common/config.py +++ b/cinder/common/config.py @@ -29,6 +29,7 @@ import socket from oslo_config import cfg from oslo_log import log as logging +from oslo_middleware import cors from oslo_utils import netutils from cinder.i18n import _ @@ -209,3 +210,32 @@ global_opts = [ ] CONF.register_opts(global_opts) + + +def set_middleware_defaults(): + """Update default configuration options for oslo.middleware.""" + # CORS Defaults + # TODO(krotscheck): Update with https://review.openstack.org/#/c/285368/ + cfg.set_defaults(cors.CORS_OPTS, + allow_headers=['X-Auth-Token', + 'X-Identity-Status', + 'X-Roles', + 'X-Service-Catalog', + 'X-User-Id', + 'X-Tenant-Id', + 'X-OpenStack-Request-ID', + 'X-Trace-Info', + 'X-Trace-HMAC', + 'OpenStack-API-Version'], + expose_headers=['X-Auth-Token', + 'X-Subject-Token', + 'X-Service-Token', + 'X-OpenStack-Request-ID', + 'OpenStack-API-Version'], + allow_methods=['GET', + 'PUT', + 'POST', + 'DELETE', + 'PATCH', + 'HEAD'] + ) diff --git a/cinder/wsgi/wsgi.py b/cinder/wsgi/wsgi.py index 2f8290521..7b2d71d71 100644 --- a/cinder/wsgi/wsgi.py +++ b/cinder/wsgi/wsgi.py @@ -28,7 +28,7 @@ from cinder import i18n i18n.enable_lazy() # Need to register global_opts -from cinder.common import config # noqa +from cinder.common import config from cinder import rpc from cinder import version @@ -40,6 +40,7 @@ def initialize_application(): CONF(sys.argv[1:], project='cinder', version=version.version_string()) logging.setup(CONF, "cinder") + config.set_middleware_defaults() rpc.init(CONF) return wsgi.Loader(CONF).load_app(name='osapi_volume') diff --git a/etc/cinder/api-paste.ini b/etc/cinder/api-paste.ini index 5914d81af..f4c507f9d 100644 --- a/etc/cinder/api-paste.ini +++ b/etc/cinder/api-paste.ini @@ -33,9 +33,6 @@ paste.filter_factory = oslo_middleware.request_id:RequestId.factory [filter:cors] paste.filter_factory = oslo_middleware.cors:filter_factory oslo_config_project = cinder -latent_allow_headers = X-Auth-Token, X-Identity-Status, X-Roles, X-Service-Catalog, X-User-Id, X-Tenant-Id, X-OpenStack-Request-ID, X-Trace-Info, X-Trace-HMAC, OpenStack-Volume-microversion -latent_expose_headers = X-Auth-Token, X-Subject-Token, X-Service-Token, X-OpenStack-Request-ID, OpenStack-Volume-microversion -latent_allow_methods = GET, PUT, POST, DELETE, PATCH [filter:faultwrap] paste.filter_factory = cinder.api.middleware.fault:FaultWrapper.factory diff --git a/setup.cfg b/setup.cfg index 8d8ea3123..19e340f5f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -47,6 +47,8 @@ oslo.config.opts = oslo_concurrency = oslo_concurrency.opts:list_opts oslo.messaging = oslo_messaging.opts:list_opts oslo.db.concurrency = oslo.db.concurrency:list_opts +oslo.config.opts.defaults = + oslo.middleware = cinder.common.config:set_middleware_defaults console_scripts = cinder-all = cinder.cmd.all:main cinder-api = cinder.cmd.api:main