From 7726e5c04e7009452d321f01a0b75986c25cf853 Mon Sep 17 00:00:00 2001 From: Timur Duehr Date: Wed, 8 May 2019 13:46:35 -0500 Subject: [PATCH] review fixes --- docs/configuration/config_yaml.rst | 4 ++-- src/octoprint/server/__init__.py | 23 +++++++++++++---------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/docs/configuration/config_yaml.rst b/docs/configuration/config_yaml.rst index 68e36c098..623fc18a4 100644 --- a/docs/configuration/config_yaml.rst +++ b/docs/configuration/config_yaml.rst @@ -65,8 +65,8 @@ Use the following settings to enable access control: # Whether to trust remote user headers. If you have setup authentication in front of # OctoPrint and the user names you use there match OctoPrint accounts, by setting this to true users will # be logged into OctoPrint as the user provided in the header. Your should ONLY ENABLE THIS if your - # OctoPrint instance is only accessible through a connection locked down through an authenitating reverse proxy! - trustBasicAuthentication: false + # OctoPrint instance is only accessible through a connection locked down through an authenticating reverse proxy! + trustRemoteUser: false # Header used by the reverse proxy to convey the authenticated user. remoteUserHeader: REMOTE_USER diff --git a/src/octoprint/server/__init__.py b/src/octoprint/server/__init__.py index bf16a5f68..1317bab11 100644 --- a/src/octoprint/server/__init__.py +++ b/src/octoprint/server/__init__.py @@ -147,14 +147,15 @@ def load_user(id): return None +def load_user_from_request_chain(request): + user = None + if g.get("trust_basic_authentication"): + user = util.get_user_for_authorization_header(request.headers.get('Authorization')) -def load_remote_user_from_request(request): - return util.get_user_for_remote_user_header(request) - - -def load_user_from_request(request): - return util.get_user_for_authorization_header(request.headers.get('Authorization')) + if user is None and g.get("trust_remote_user"): + user = util.get_user_for_remote_user_header(request) + return user def unauthorized_user(): from flask import abort @@ -1606,11 +1607,13 @@ class Server(object): # login users authenticated by basic auth if self._settings.get(["accessControl", "trustBasicAuthentication"]): - loginManager.request_callback = load_user_from_request + g.trust_basic_authentication = True - # Login via REMOTE_USER header - if self._settings.get(["accessControl", "useRemoteUser"]): - loginManager.request_callback = load_remote_user_from_request + if self._settings.get(["accessControl", "trustRemoteUser"]): + g.trust_remote_user = True + + if g.get("trust_basic_authentication") or g.get("trust_remote_user"): + loginManager.request_callback = load_user_from_request_chain if not userManager.enabled: loginManager.anonymous_user = users.DummyUser