Files
swift/swift/common/base_storage_server.py
Tim Burke 9eb81f6e69 Allow replication servers to handle all request methods
Previously, the replication_server setting could take one of three
states:

 * If unspecified, the server would handle all available methods.
 * If "true", "yes", "on", etc. it would only handle replication
   methods (REPLICATE, SSYNC).
 * If any other value (including blank), it would only handle
   non-replication methods.

However, because SSYNC tunnels PUTs, POSTs, and DELETEs through
the same object-server app that's responding to SSYNC, setting
`replication_server = true` would break the protocol. This has
been the case ever since ssync was introduced.

Now, get rid of that second state -- operators can still set
`replication_server = false` as a principle-of-least-privilege guard
to ensure proxy-servers can't make replication requests, but replication
servers will be able to serve all traffic. This will allow replication
servers to be used as general internal-to-the-cluster endpoints, leaving
non-replication servers to handle client-driven traffic.

Closes-Bug: #1446873
Change-Id: Ica2b41a52d11cb10c94fa8ad780a201318c4fc87
2020-07-23 09:11:07 -07:00

71 lines
2.5 KiB
Python

# Copyright (c) 2010-2014 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.
import inspect
from swift import __version__ as swift_version
from swift.common.utils import public, timing_stats, config_true_value, \
LOG_LINE_DEFAULT_FORMAT
from swift.common.swob import Response
class BaseStorageServer(object):
"""
Implements common OPTIONS method for object, account, container servers.
"""
def __init__(self, conf, **kwargs):
self._allowed_methods = None
self.replication_server = config_true_value(
conf.get('replication_server', 'true'))
self.log_format = conf.get('log_format', LOG_LINE_DEFAULT_FORMAT)
self.anonymization_method = conf.get('log_anonymization_method', 'md5')
self.anonymization_salt = conf.get('log_anonymization_salt', '')
@property
def server_type(self):
raise NotImplementedError(
'Storage nodes have not implemented the Server type.')
@property
def allowed_methods(self):
if self._allowed_methods is None:
self._allowed_methods = []
all_methods = inspect.getmembers(self, predicate=callable)
for name, m in all_methods:
if not getattr(m, 'publicly_accessible', False):
continue
if getattr(m, 'replication', False) and \
not self.replication_server:
continue
self._allowed_methods.append(name)
self._allowed_methods.sort()
return self._allowed_methods
@public
@timing_stats()
def OPTIONS(self, req):
"""
Base handler for OPTIONS requests
:param req: swob.Request object
:returns: swob.Response object
"""
# Prepare the default response
headers = {'Allow': ', '.join(self.allowed_methods),
'Server': '%s/%s' % (self.server_type, swift_version)}
resp = Response(status=200, request=req, headers=headers)
return resp