From: liushi Date: Fri, 14 Feb 2020 09:14:11 +0000 (+0800) Subject: mgr/restful: allow disable http authentication X-Git-Tag: v16.1.0~2004^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=b0cc0d45de45868dbf13a21a716da1801133f5e4;p=ceph.git mgr/restful: allow disable http authentication Signed-off-by: liushi --- diff --git a/src/pybind/mgr/restful/decorators.py b/src/pybind/mgr/restful/decorators.py index abf36e339ab5..d1d3fbcd5178 100644 --- a/src/pybind/mgr/restful/decorators.py +++ b/src/pybind/mgr/restful/decorators.py @@ -13,6 +13,9 @@ from . import context def auth(f): @wraps(f) def decorated(*args, **kwargs): + if not context.instance.enable_auth: + return f(*args, **kwargs) + if not request.authorization: response.status = 401 response.headers['WWW-Authenticate'] = 'Basic realm="Login Required"' diff --git a/src/pybind/mgr/restful/module.py b/src/pybind/mgr/restful/module.py index 049a09e14711..00e7676371bf 100644 --- a/src/pybind/mgr/restful/module.py +++ b/src/pybind/mgr/restful/module.py @@ -198,6 +198,7 @@ class Module(MgrModule): {'name': 'server_addr'}, {'name': 'server_port'}, {'name': 'key_file'}, + {'name': 'enable_auth', 'type': 'bool', 'default': True}, ] COMMANDS = [ @@ -236,7 +237,7 @@ class Module(MgrModule): self.requests_lock = threading.RLock() self.keys = {} - self.disable_auth = False + self.enable_auth = True self.server = None @@ -302,6 +303,8 @@ class Module(MgrModule): else: pkey_fname = self.get_localized_module_option('key_file') + self.enable_auth = self.get_localized_module_option('enable_auth', True) + if not cert_fname or not pkey_fname: raise CannotServe('no certificate configured') if not os.path.isfile(cert_fname): @@ -385,6 +388,9 @@ class Module(MgrModule): # the command was not issued by me pass + def config_notify(self): + self.enable_auth = self.get_localized_module_option('enable_auth', True) + def create_self_signed_cert(self): # create a key pair