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
This commit is contained in:
Michael Krotscheck 2016-03-01 11:31:40 -08:00
parent 8fbc112a99
commit abba492184
6 changed files with 37 additions and 5 deletions

View File

@ -59,6 +59,7 @@ def main():
gmr_opts.set_defaults(CONF) gmr_opts.set_defaults(CONF)
CONF(sys.argv[1:], project='cinder', CONF(sys.argv[1:], project='cinder',
version=version.version_string()) version=version.version_string())
config.set_middleware_defaults()
logging.setup(CONF, "cinder") logging.setup(CONF, "cinder")
LOG = logging.getLogger('cinder.all') LOG = logging.getLogger('cinder.all')

View File

@ -34,7 +34,7 @@ from cinder import i18n
i18n.enable_lazy() i18n.enable_lazy()
# Need to register global_opts # Need to register global_opts
from cinder.common import config # noqa from cinder.common import config
from cinder import rpc from cinder import rpc
from cinder import service from cinder import service
from cinder import utils from cinder import utils
@ -49,6 +49,7 @@ def main():
gmr_opts.set_defaults(CONF) gmr_opts.set_defaults(CONF)
CONF(sys.argv[1:], project='cinder', CONF(sys.argv[1:], project='cinder',
version=version.version_string()) version=version.version_string())
config.set_middleware_defaults()
logging.setup(CONF, "cinder") logging.setup(CONF, "cinder")
python_logging.captureWarnings(True) python_logging.captureWarnings(True)
utils.monkey_patch() utils.monkey_patch()

View File

@ -29,6 +29,7 @@ import socket
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging from oslo_log import log as logging
from oslo_middleware import cors
from oslo_utils import netutils from oslo_utils import netutils
from cinder.i18n import _ from cinder.i18n import _
@ -209,3 +210,32 @@ global_opts = [
] ]
CONF.register_opts(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']
)

View File

@ -28,7 +28,7 @@ from cinder import i18n
i18n.enable_lazy() i18n.enable_lazy()
# Need to register global_opts # Need to register global_opts
from cinder.common import config # noqa from cinder.common import config
from cinder import rpc from cinder import rpc
from cinder import version from cinder import version
@ -40,6 +40,7 @@ def initialize_application():
CONF(sys.argv[1:], project='cinder', CONF(sys.argv[1:], project='cinder',
version=version.version_string()) version=version.version_string())
logging.setup(CONF, "cinder") logging.setup(CONF, "cinder")
config.set_middleware_defaults()
rpc.init(CONF) rpc.init(CONF)
return wsgi.Loader(CONF).load_app(name='osapi_volume') return wsgi.Loader(CONF).load_app(name='osapi_volume')

View File

@ -33,9 +33,6 @@ paste.filter_factory = oslo_middleware.request_id:RequestId.factory
[filter:cors] [filter:cors]
paste.filter_factory = oslo_middleware.cors:filter_factory paste.filter_factory = oslo_middleware.cors:filter_factory
oslo_config_project = cinder 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] [filter:faultwrap]
paste.filter_factory = cinder.api.middleware.fault:FaultWrapper.factory paste.filter_factory = cinder.api.middleware.fault:FaultWrapper.factory

View File

@ -47,6 +47,8 @@ oslo.config.opts =
oslo_concurrency = oslo_concurrency.opts:list_opts oslo_concurrency = oslo_concurrency.opts:list_opts
oslo.messaging = oslo_messaging.opts:list_opts oslo.messaging = oslo_messaging.opts:list_opts
oslo.db.concurrency = oslo.db.concurrency:list_opts oslo.db.concurrency = oslo.db.concurrency:list_opts
oslo.config.opts.defaults =
oslo.middleware = cinder.common.config:set_middleware_defaults
console_scripts = console_scripts =
cinder-all = cinder.cmd.all:main cinder-all = cinder.cmd.all:main
cinder-api = cinder.cmd.api:main cinder-api = cinder.cmd.api:main