Add support for remote users
This commit is contained in:
1 parent
a35b7cddf2
commit
495d99fbe9
5 files changed
+47
-1
No files matched your search
@@ -101,6 +101,7 @@ date of first contribution):
|
||||
* [Fabio Santos](https://github.com/Fabi0San)
|
||||
* [Jack Wilsdon](https://github.com/jackwilsdon)
|
||||
* [Ryan Finnie](https://github.com/rfinnie)
|
||||
* [Timur Duehr](https://github.com/tduehr)
|
||||
|
||||
OctoPrint started off as a fork of [Cura](https://github.com/daid/Cura) by
|
||||
[Daid Braam](https://github.com/daid). Parts of its communication layer and
|
||||
|
||||
@@ -62,6 +62,18 @@ Use the following settings to enable access control:
|
||||
# header and login the user without further checks. Use with caution.
|
||||
checkBasicAuthenticationPassword: true
|
||||
|
||||
# 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
|
||||
|
||||
# Header used by the reverse proxy to convey the authenticated user.
|
||||
remoteUserHeader: REMOTE_USER
|
||||
|
||||
# If a remote user is not found, add them. Use this only if all users from the remote system can use OctoPrint.
|
||||
addRemoteUsers: false
|
||||
|
||||
.. _sec-configuration-config_yaml-api:
|
||||
|
||||
API
|
||||
|
||||
@@ -147,9 +147,15 @@ def load_user(id):
|
||||
|
||||
return None
|
||||
|
||||
|
||||
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'))
|
||||
|
||||
|
||||
def unauthorized_user():
|
||||
from flask import abort
|
||||
abort(403)
|
||||
@@ -1602,6 +1608,10 @@ class Server(object):
|
||||
if self._settings.get(["accessControl", "trustBasicAuthentication"]):
|
||||
loginManager.request_callback = load_user_from_request
|
||||
|
||||
# Login via REMOTE_USER header
|
||||
if self._settings.get(["accessControl", "useRemoteUser"]):
|
||||
loginManager.request_callback = load_remote_user_from_request
|
||||
|
||||
if not userManager.enabled:
|
||||
loginManager.anonymous_user = users.DummyUser
|
||||
principals.identity_loaders.appendleft(users.dummy_identity_loader)
|
||||
|
||||
@@ -199,6 +199,26 @@ def get_user_for_apikey(apikey):
|
||||
return None
|
||||
|
||||
|
||||
def get_user_for_remote_user_header(request):
|
||||
if not octoprint.server.userManager.enabled:
|
||||
return None
|
||||
|
||||
if not settings().getBoolean(["accessControl", "trustRemoteUser"]):
|
||||
return None
|
||||
|
||||
header = request.headers.get(settings().get(["accessControl", "remoteUserHeader"]))
|
||||
if header is None:
|
||||
return None
|
||||
|
||||
user = octoprint.server.userManager.findUser(userid=header)
|
||||
|
||||
if user is None and settings().getBoolean(["accessControl", "addRemoteUsers"]):
|
||||
octoprint.server.userManager.addUser(header, settings().generateApiKey(), active=True)
|
||||
user = octoprint.server.userManager.findUser(userid=header)
|
||||
|
||||
return user
|
||||
|
||||
|
||||
def get_user_for_authorization_header(header):
|
||||
if not settings().getBoolean(["accessControl", "trustBasicAuthentication"]):
|
||||
return None
|
||||
|
||||
@@ -337,7 +337,10 @@ default_settings = {
|
||||
"localNetworks": ["127.0.0.0/8", "::1/128"],
|
||||
"autologinAs": None,
|
||||
"trustBasicAuthentication": False,
|
||||
"checkBasicAuthenticationPassword": True
|
||||
"checkBasicAuthenticationPassword": True,
|
||||
"trustRemoteUser": False,
|
||||
"remoteUserHeader": "REMOTE_USER",
|
||||
"addRemoteUsers": False
|
||||
},
|
||||
"slicing": {
|
||||
"enabled": True,
|
||||
|
||||
Reference in new issue
Block a user