From b36fe03702e76294d530d405ca61f45a7a382057 Mon Sep 17 00:00:00 2001 From: Luis Pabon Date: Tue, 26 Nov 2013 20:21:10 -0500 Subject: Return BadRequest on X-Delete-At/After headers Gluster-swift does not support X-Delete-After or X-Delete-At headers. The code needs to inform the caller with a 400-BadRequest if they use these headers. Change-Id: Ic9d3a1646c0d26bb0204245efce4501f7479fee6 Signed-off-by: Luis Pabon Reviewed-on: http://review.gluster.org/6364 Reviewed-by: Chetan Risbud --- gluster/swift/common/Glusterfs.py | 14 +++++++++++++ gluster/swift/common/constraints.py | 39 ++++++++++++++++++++++++++++++++++++- 2 files changed, 52 insertions(+), 1 deletion(-) (limited to 'gluster/swift/common') diff --git a/gluster/swift/common/Glusterfs.py b/gluster/swift/common/Glusterfs.py index 55012d3..5d2cab1 100644 --- a/gluster/swift/common/Glusterfs.py +++ b/gluster/swift/common/Glusterfs.py @@ -37,6 +37,7 @@ _allow_mount_per_server = False _implicit_dir_objects = False _container_update_object_count = False _account_update_container_count = False +_ignore_unsupported_headers = False if _fs_conf.read(os.path.join(SWIFT_DIR, 'fs.conf')): try: @@ -97,6 +98,19 @@ if _fs_conf.read(os.path.join(SWIFT_DIR, 'fs.conf')): except (NoSectionError, NoOptionError): pass + # -- Hidden configuration option -- + # Ignore unsupported headers and allow them in a request without + # returning a 400-BadRequest. This setting can be set to + # allow unsupported headers such as X-Delete-At and + # X-Delete-After even though they will not be used. + try: + _ignore_unsupported_headers = \ + _fs_conf.get('DEFAULT', + 'ignore_unsupported_headers', + "no") in TRUE_VALUES + except (NoSectionError, NoOptionError): + pass + NAME = 'glusterfs' diff --git a/gluster/swift/common/constraints.py b/gluster/swift/common/constraints.py index 523277d..7681c49 100644 --- a/gluster/swift/common/constraints.py +++ b/gluster/swift/common/constraints.py @@ -23,6 +23,7 @@ import swift.common.ring as _ring from gluster.swift.common import Glusterfs, ring MAX_OBJECT_NAME_COMPONENT_LENGTH = 255 +UNSUPPORTED_HEADERS = ['x-delete-at', 'x-delete-after'] def set_object_name_component_length(len=None): @@ -54,8 +55,41 @@ def validate_obj_name_component(obj): return 'cannot be . or ..' return '' + +def validate_headers(req): + """ + Validate client header requests + :param req: Http request + """ + if not Glusterfs._ignore_unsupported_headers: + for unsupported_header in UNSUPPORTED_HEADERS: + if unsupported_header in req.headers: + return '%s headers are not supported' \ + % ','.join(UNSUPPORTED_HEADERS) + return '' + # Save the original check object creation __check_object_creation = swift.common.constraints.check_object_creation +__check_metadata = swift.common.constraints.check_metadata + + +def gluster_check_metadata(req, target_type, POST=True): + """ + :param req: HTTP request object + :param target_type: Value from POST passed to __check_metadata + :param POST: Only call __check_metadata on POST since Swift only + calls check_metadata on POSTs. + """ + ret = None + if POST: + ret = __check_metadata(req, target_type) + if ret is None: + bdy = validate_headers(req) + if bdy: + ret = HTTPBadRequest(body=bdy, + request=req, + content_type='text/plain') + return ret # Define our new one which invokes the original @@ -85,11 +119,14 @@ def gluster_check_object_creation(req, object_name): ret = HTTPBadRequest(body=bdy, request=req, content_type='text/plain') + if ret is None: + ret = gluster_check_metadata(req, 'object', POST=False) return ret -# Replace the original check object creation with ours +# Replace the original checks with ours swift.common.constraints.check_object_creation = gluster_check_object_creation +swift.common.constraints.check_metadata = gluster_check_metadata # Replace the original check mount with ours swift.common.constraints.check_mount = Glusterfs.mount -- cgit