🥅 Make access control mandatory
Apparently no matter how often you tell people to not put their stuff unsecured on the public internet, they still will do that happily and then I get the resulting fallout from the security community. So you now will HAVE to enable access control. No more disabled ACL. Apparently you can't trust people with this kind of responsibility. If you want a bit more convenience, look into the trusted network settings in config.yaml. And get a password manager. And stop port forwarding and exposing your OctoPrint on the public internet please - it can be found, you are not invisible, and you are putting yourself at risk. Learn what a VPN is and to set one up on your router, that is a valuable skill in any case.
This commit is contained in:
1 parent
fd319fc82f
commit
c0c6dd7c7b
19 files changed
+96
-230
No files matched your search
@@ -35,7 +35,6 @@ class UserManager(GroupChangeListener, object):
|
||||
self._logger = logging.getLogger(__name__)
|
||||
self._session_users_by_session = {}
|
||||
self._sessionids_by_userid = {}
|
||||
self._enabled = True
|
||||
|
||||
if settings is None:
|
||||
settings = s()
|
||||
@@ -50,29 +49,14 @@ class UserManager(GroupChangeListener, object):
|
||||
self._login_status_listeners.remove(listener)
|
||||
|
||||
def anonymous_user_factory(self):
|
||||
if self.enabled:
|
||||
return AnonymousUser([self._group_manager.guest_group])
|
||||
else:
|
||||
return AdminUser(
|
||||
[self._group_manager.admin_group, self._group_manager.user_group]
|
||||
)
|
||||
return AnonymousUser([self._group_manager.guest_group])
|
||||
|
||||
def api_user_factory(self):
|
||||
return ApiUser([self._group_manager.admin_group, self._group_manager.user_group])
|
||||
|
||||
@property
|
||||
def enabled(self):
|
||||
return self._enabled
|
||||
|
||||
@enabled.setter
|
||||
def enabled(self, value):
|
||||
self._enabled = value
|
||||
|
||||
def enable(self):
|
||||
self._enabled = True
|
||||
|
||||
def disable(self):
|
||||
self._enabled = False
|
||||
return True
|
||||
|
||||
def login_user(self, user):
|
||||
self._cleanup_sessions()
|
||||
@@ -112,7 +96,7 @@ class UserManager(GroupChangeListener, object):
|
||||
return user
|
||||
|
||||
def logout_user(self, user, stale=False):
|
||||
if user is None or user.is_anonymous or isinstance(user, AdminUser):
|
||||
if user is None or user.is_anonymous:
|
||||
return
|
||||
|
||||
if isinstance(user, LocalProxy):
|
||||
@@ -1444,11 +1428,3 @@ class SessionUser(wrapt.ObjectProxy):
|
||||
class ApiUser(User):
|
||||
def __init__(self, groups):
|
||||
User.__init__(self, "_api", "", True, [], groups)
|
||||
|
||||
|
||||
##~~ User object to use when access control is disabled
|
||||
|
||||
|
||||
class AdminUser(User):
|
||||
def __init__(self, groups):
|
||||
User.__init__(self, "_admin", "", True, [], groups)
|
||||
@@ -71,8 +71,6 @@ def user(ctx):
|
||||
err=True,
|
||||
)
|
||||
user_manager = FilebasedUserManager(group_manager, settings=settings)
|
||||
finally:
|
||||
user_manager.enabled = settings.getBoolean(["accessControl", "enabled"])
|
||||
|
||||
ctx.obj.user_manager = user_manager
|
||||
|
||||
|
||||
@@ -419,11 +419,7 @@ class AppKeysPlugin(
|
||||
with self._keys_lock:
|
||||
for user_id, data in self._keys.items():
|
||||
if any(filter(lambda x: x.api_key == api_key, data)):
|
||||
if self._user_manager.enabled:
|
||||
return self._user_manager.find_user(userid=user_id)
|
||||
elif user_id == "_admin" or user_id == "dummy":
|
||||
# dummy = backwards compatible
|
||||
return self._user_manager.anonymous_user_factory()
|
||||
return self._user_manager.find_user(userid=user_id)
|
||||
return None
|
||||
|
||||
def _api_keys_for_user(self, user_id):
|
||||
|
||||
@@ -1101,14 +1101,13 @@ class BackupPlugin(
|
||||
with io.open(configfile, "rt", encoding="utf-8") as f:
|
||||
configdata = yaml.safe_load(f)
|
||||
|
||||
if configdata.get("accessControl", {}).get("enabled", True):
|
||||
userfile = os.path.join(temp, "basedir", "users.yaml")
|
||||
if not os.path.exists(userfile):
|
||||
if callable(on_invalid_backup):
|
||||
on_invalid_backup("Backup lacks users.yaml")
|
||||
if callable(on_restore_failed):
|
||||
on_restore_failed(path)
|
||||
return False
|
||||
userfile = os.path.join(temp, "basedir", "users.yaml")
|
||||
if not os.path.exists(userfile):
|
||||
if callable(on_invalid_backup):
|
||||
on_invalid_backup("Backup lacks users.yaml")
|
||||
if callable(on_restore_failed):
|
||||
on_restore_failed(path)
|
||||
return False
|
||||
|
||||
if callable(on_log_progress):
|
||||
on_log_progress("Unpacked")
|
||||
|
||||
@@ -105,7 +105,7 @@ class CoreWizardPlugin(
|
||||
return result
|
||||
|
||||
def get_wizard_version(self):
|
||||
return 3
|
||||
return 4
|
||||
|
||||
# ~~ helpers
|
||||
|
||||
|
||||
@@ -9,20 +9,19 @@ $(function () {
|
||||
self.confirmedPassword = ko.observable(undefined);
|
||||
|
||||
self.setup = ko.observable(false);
|
||||
self.decision = ko.observable();
|
||||
|
||||
self.required = false;
|
||||
|
||||
self.passwordMismatch = ko.pureComputed(function () {
|
||||
return self.password() != self.confirmedPassword();
|
||||
return self.password() !== self.confirmedPassword();
|
||||
});
|
||||
|
||||
self.validUsername = ko.pureComputed(function () {
|
||||
return self.username() && self.username().trim() != "";
|
||||
return self.username() && self.username().trim() !== "";
|
||||
});
|
||||
|
||||
self.validPassword = ko.pureComputed(function () {
|
||||
return self.password() && self.password().trim() != "";
|
||||
return self.password() && self.password().trim() !== "";
|
||||
});
|
||||
|
||||
self.validData = ko.pureComputed(function () {
|
||||
@@ -31,11 +30,10 @@ $(function () {
|
||||
);
|
||||
});
|
||||
|
||||
self.keepAccessControl = function () {
|
||||
self.createAccount = function () {
|
||||
if (!self.validData()) return;
|
||||
|
||||
var data = {
|
||||
ac: true,
|
||||
user: self.username(),
|
||||
pass1: self.password(),
|
||||
pass2: self.confirmedPassword()
|
||||
@@ -43,35 +41,27 @@ $(function () {
|
||||
self._sendData(data);
|
||||
};
|
||||
|
||||
self.disableAccessControl = function () {
|
||||
var message = gettext(
|
||||
"If you disable Access Control <strong>and</strong> your OctoPrint installation is accessible from the internet, your printer <strong>will be accessible by everyone - that also includes the bad guys!</strong>"
|
||||
);
|
||||
showConfirmationDialog({
|
||||
message: message,
|
||||
onproceed: function (e) {
|
||||
var data = {
|
||||
ac: false
|
||||
};
|
||||
self._sendData(data);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
self._sendData = function (data, callback) {
|
||||
OctoPrint.postJson("plugin/corewizard/acl", data).done(function () {
|
||||
self.setup(true);
|
||||
self.decision(data.ac);
|
||||
if (data.ac) {
|
||||
// we now log the user in
|
||||
var user = data.user;
|
||||
var pass = data.pass1;
|
||||
self.loginStateViewModel.login(user, pass, true).done(function () {
|
||||
if (callback) callback();
|
||||
});
|
||||
} else {
|
||||
|
||||
// we now log the user in
|
||||
var user = data.user;
|
||||
var pass = data.pass1;
|
||||
self.loginStateViewModel.login(user, pass, true).done(function () {
|
||||
if (callback) callback();
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
self._showDecisionNeededDialog = function () {
|
||||
showMessageDialog({
|
||||
title: gettext("Please set up Access Control"),
|
||||
message: gettext(
|
||||
"You haven't yet set up access control. You need to setup a " +
|
||||
'username and password and click "Create Account" before ' +
|
||||
"continuing."
|
||||
)
|
||||
});
|
||||
};
|
||||
|
||||
@@ -85,12 +75,17 @@ $(function () {
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
showMessageDialog({
|
||||
title: gettext("Please set up Access Control"),
|
||||
message: gettext(
|
||||
'You haven\'t yet set up access control. You need to either setup a username and password and click "Keep Access Control Enabled" or click "Disable Access Control" before continuing'
|
||||
)
|
||||
});
|
||||
|
||||
self._showDecisionNeededDialog();
|
||||
return false;
|
||||
};
|
||||
|
||||
self.onBeforeWizardFinish = function () {
|
||||
if (!self.required) return true;
|
||||
|
||||
if (self.setup()) return true;
|
||||
|
||||
self._showDecisionNeededDialog();
|
||||
return false;
|
||||
};
|
||||
|
||||
@@ -102,14 +97,6 @@ $(function () {
|
||||
response.corewizard.details.acl &&
|
||||
response.corewizard.details.acl.required;
|
||||
};
|
||||
|
||||
self.onWizardFinish = function () {
|
||||
if (!self.required) return;
|
||||
|
||||
if (!self.decision()) {
|
||||
return "reload";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function CoreWizardWebcamViewModel(parameters) {
|
||||
|
||||
@@ -63,10 +63,10 @@ class WebcamSubwizard(object):
|
||||
# noinspection PyUnresolvedReferences,PyMethodMayBeStatic
|
||||
class AclSubwizard(object):
|
||||
def _is_acl_wizard_firstrunonly(self):
|
||||
return True
|
||||
return False
|
||||
|
||||
def _is_acl_wizard_required(self):
|
||||
return self._user_manager.enabled and not self._user_manager.has_been_customized()
|
||||
return not self._user_manager.has_been_customized()
|
||||
|
||||
def _get_acl_wizard_details(self):
|
||||
return {"required": self._is_acl_wizard_required()}
|
||||
@@ -81,11 +81,11 @@ class AclSubwizard(object):
|
||||
def acl_wizard_api(self):
|
||||
from flask import abort, request
|
||||
|
||||
from octoprint.server.api import NO_CONTENT, valid_boolean_trues
|
||||
from octoprint.server.api import NO_CONTENT
|
||||
|
||||
if (
|
||||
not self._settings.global_get(["server", "firstRun"])
|
||||
or self._user_manager.has_been_customized()
|
||||
and self._user_manager.has_been_customized()
|
||||
):
|
||||
abort(404)
|
||||
|
||||
@@ -94,17 +94,12 @@ class AclSubwizard(object):
|
||||
data = request.values
|
||||
|
||||
if (
|
||||
"ac" in data
|
||||
and data["ac"] in valid_boolean_trues
|
||||
and "user" in data
|
||||
"user" in data
|
||||
and "pass1" in data
|
||||
and "pass2" in data
|
||||
and data["pass1"] == data["pass2"]
|
||||
):
|
||||
# configure access control
|
||||
self._settings.global_set_boolean(["accessControl", "enabled"], True)
|
||||
self._user_manager.enable()
|
||||
|
||||
self._user_manager.add_user(
|
||||
data["user"],
|
||||
data["pass1"],
|
||||
@@ -113,10 +108,6 @@ class AclSubwizard(object):
|
||||
[USER_GROUP, ADMIN_GROUP],
|
||||
overwrite=True,
|
||||
)
|
||||
elif "ac" in data and data["ac"] not in valid_boolean_trues:
|
||||
# disable access control
|
||||
self._settings.global_set_boolean(["accessControl", "enabled"], False)
|
||||
self._user_manager.disable()
|
||||
self._settings.save()
|
||||
return NO_CONTENT
|
||||
|
||||
|
||||
@@ -1,26 +1,10 @@
|
||||
<h3>{{ _('Access Control') }}</h3>
|
||||
|
||||
{% trans safe_remote_url='https://octoprint.org/blog/2018/09/03/safe-remote-access/' %}<p>
|
||||
<strong>Please read the following, it is very important for your printer's health!</strong>
|
||||
</p>
|
||||
<p>
|
||||
OctoPrint by default ships with Access Control enabled, meaning you won't be able to do anything with the
|
||||
printer unless you login first as a configured user. This is to <strong>prevent strangers - possibly with
|
||||
malicious intent - to gain access to your printer</strong> via an untrustworthy network
|
||||
and using it in such a way that it is damaged or worse (i.e. causes a fire).
|
||||
</p>
|
||||
<p>
|
||||
If you plan on accessing OctoPrint remotely over the internet, <strong>you should not only rely on the built-in
|
||||
Access Control mechanisms</strong> however -
|
||||
<a href="{{ safe_remote_url }}" target="_blank" rel="noopener noreferrer">take additional precautions</a>.
|
||||
Your OctoPrint enabled printer is a critical home appliance you really should not give anyone who happens to be
|
||||
connected to the internet access to - even read-only! <strong>An instance available publicly on the internet
|
||||
will be found, and people will try to break it open.</strong>
|
||||
</p>
|
||||
<p>
|
||||
It looks like you haven't configured access control yet. Please <strong>set up a username and password</strong> for the
|
||||
initial administrator account who will have full access to both the printer and OctoPrint's settings, then click
|
||||
on "Keep Access Control Enabled":
|
||||
{% trans %}<p>
|
||||
It looks like you haven't configured access control yet, which is now mandatory.
|
||||
Please <strong>set up a username and password</strong> for the
|
||||
initial administrator account who will have full access to both the printer and
|
||||
OctoPrint's settings:
|
||||
</p>{% endtrans %}
|
||||
<form class="form-horizontal" onsubmit="return false;">
|
||||
<div class="control-group" data-bind="css: {success: validUsername()}">
|
||||
@@ -42,26 +26,7 @@
|
||||
<span class="help-inline" data-bind="visible: passwordMismatch()">{{ _('Passwords do not match') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="controls">
|
||||
<a href="#" class="btn btn-primary" data-bind="click: function() { if(!setup()){createAccount()}}, enable: !setup() && validData(), css: {disabled: !validData() || setup()}">{{ _('Create Account') }}</a>
|
||||
</div>
|
||||
</form>
|
||||
{% trans %}<p>
|
||||
<strong>Note:</strong> In case that your OctoPrint installation is only accessible from within a trustworthy local network and you don't
|
||||
need Access Control for other reasons, you may alternatively disable Access Control. You should only
|
||||
do this if you are absolutely certain that only people you know and trust will be able to connect to it.
|
||||
</p>
|
||||
<p>
|
||||
<strong>Do NOT underestimate the risk of access from the internet to your printer and OctoPrint instance!</strong>
|
||||
</p>{% endtrans %}
|
||||
|
||||
<div class="row-fluid">
|
||||
<a href="#" class="btn btn-danger span6" data-bind="click: function() { if(!setup()){disableAccessControl()}}, enable: !setup(), css: {disabled: setup()}">{{ _('Disable Access Control') }}</a>
|
||||
<a href="#" class="btn btn-primary span6" data-bind="click: function() { if(!setup()){keepAccessControl()}}, enable: !setup() && validData(), css: {disabled: !validData() || setup()}">{{ _('Keep Access Control Enabled') }}</a>
|
||||
</div>
|
||||
|
||||
<div class="acl_decision" style="display: none" data-bind="visible: setup()">
|
||||
<div class="text-center" style="display: none" data-bind="visible: decision()">{% trans %}
|
||||
Access control is <strong class="text-success">enabled</strong>.
|
||||
{% endtrans %}</div>
|
||||
<div class="text-center" style="display: none" data-bind="visible: !decision()">{% trans %}
|
||||
Access control is <strong class="text-danger">disabled</strong>.
|
||||
{% endtrans %}</div>
|
||||
</div>
|
||||
@@ -175,7 +175,7 @@ def on_user_logged_out(sender, user=None):
|
||||
|
||||
|
||||
def load_user(id):
|
||||
if id is None or not userManager.enabled:
|
||||
if id is None:
|
||||
return None
|
||||
|
||||
if id == "_api":
|
||||
@@ -553,10 +553,6 @@ class Server(object):
|
||||
"falling back to FilebasedUserManager!".format(user_manager_name)
|
||||
)
|
||||
userManager = octoprint.access.users.FilebasedUserManager(groupManager)
|
||||
finally:
|
||||
userManager.enabled = self._settings.getBoolean(
|
||||
["accessControl", "enabled"]
|
||||
)
|
||||
components.update({"user_manager": userManager})
|
||||
|
||||
# create printer instance
|
||||
@@ -1349,7 +1345,7 @@ class Server(object):
|
||||
if "X-Locale" in request.headers:
|
||||
return Locale.negotiate([request.headers["X-Locale"]], LANGUAGES)
|
||||
|
||||
if hasattr(g, "identity") and g.identity and userManager.enabled:
|
||||
if hasattr(g, "identity") and g.identity:
|
||||
userid = g.identity.id
|
||||
try:
|
||||
user_language = userManager.get_user_setting(
|
||||
|
||||
@@ -162,7 +162,11 @@ def pluginCommand(name):
|
||||
|
||||
@api.route("/setup/wizard", methods=["GET"])
|
||||
def wizardState():
|
||||
if not s().getBoolean(["server", "firstRun"]) and not Permissions.ADMIN.can():
|
||||
if (
|
||||
not s().getBoolean(["server", "firstRun"])
|
||||
and octoprint.server.userManager.has_been_customized()
|
||||
and not Permissions.ADMIN.can()
|
||||
):
|
||||
abort(403)
|
||||
|
||||
seen_wizards = s().get(["server", "seenWizards"])
|
||||
@@ -199,7 +203,11 @@ def wizardState():
|
||||
|
||||
@api.route("/setup/wizard", methods=["POST"])
|
||||
def wizardFinish():
|
||||
if not s().getBoolean(["server", "firstRun"]) and not Permissions.ADMIN.can():
|
||||
if (
|
||||
not s().getBoolean(["server", "firstRun"])
|
||||
and octoprint.server.userManager.has_been_customized()
|
||||
and not Permissions.ADMIN.can()
|
||||
):
|
||||
abort(403)
|
||||
|
||||
data = {}
|
||||
@@ -278,7 +286,7 @@ def login():
|
||||
if not data:
|
||||
data = request.values
|
||||
|
||||
if octoprint.server.userManager.enabled and "user" in data and "pass" in data:
|
||||
if "user" in data and "pass" in data:
|
||||
username = data["user"]
|
||||
password = data["pass"]
|
||||
|
||||
@@ -296,10 +304,10 @@ def login():
|
||||
if not user.is_active:
|
||||
return make_response(("Your account is deactivated", 403, []))
|
||||
|
||||
if octoprint.server.userManager.enabled:
|
||||
user = octoprint.server.userManager.login_user(user)
|
||||
session["usersession.id"] = user.session
|
||||
g.user = user
|
||||
user = octoprint.server.userManager.login_user(user)
|
||||
session["usersession.id"] = user.session
|
||||
g.user = user
|
||||
|
||||
login_user(user, remember=remember)
|
||||
identity_changed.send(
|
||||
current_app._get_current_object(), identity=Identity(user.get_id())
|
||||
|
||||
@@ -141,9 +141,6 @@ def remove_group(key):
|
||||
@no_firstrun_access
|
||||
@Permissions.SETTINGS.require(403)
|
||||
def get_users():
|
||||
if not userManager.enabled:
|
||||
return jsonify(SUCCESS)
|
||||
|
||||
return jsonify(users=list(map(lambda u: u.as_dict(), userManager.get_all_users())))
|
||||
|
||||
|
||||
@@ -151,9 +148,6 @@ def get_users():
|
||||
@no_firstrun_access
|
||||
@Permissions.SETTINGS.require(403)
|
||||
def add_user():
|
||||
if not userManager.enabled:
|
||||
return jsonify(SUCCESS)
|
||||
|
||||
if "application/json" not in request.headers["Content-Type"]:
|
||||
return make_response("Expected content-type JSON", 400)
|
||||
|
||||
@@ -189,9 +183,6 @@ def add_user():
|
||||
@api.route("/access/users/<username>", methods=["GET"])
|
||||
@no_firstrun_access
|
||||
def get_user(username):
|
||||
if not userManager.enabled:
|
||||
return jsonify(SUCCESS)
|
||||
|
||||
if (
|
||||
current_user is not None
|
||||
and not current_user.is_anonymous
|
||||
@@ -213,9 +204,6 @@ def get_user(username):
|
||||
@no_firstrun_access
|
||||
@Permissions.SETTINGS.require(403)
|
||||
def update_user(username):
|
||||
if not userManager.enabled:
|
||||
return jsonify(SUCCESS)
|
||||
|
||||
user = userManager.find_user(username)
|
||||
if user is not None:
|
||||
if "application/json" not in request.headers["Content-Type"]:
|
||||
@@ -254,9 +242,6 @@ def update_user(username):
|
||||
@no_firstrun_access
|
||||
@Permissions.SETTINGS.require(403)
|
||||
def remove_user(username):
|
||||
if not userManager.enabled:
|
||||
return jsonify(SUCCESS)
|
||||
|
||||
try:
|
||||
userManager.remove_user(username)
|
||||
return get_users()
|
||||
@@ -302,9 +287,6 @@ def change_password_for_user(username):
|
||||
@api.route("/access/users/<username>/settings", methods=["GET"])
|
||||
@no_firstrun_access
|
||||
def get_settings_for_user(username):
|
||||
if not userManager.enabled:
|
||||
return jsonify(SUCCESS)
|
||||
|
||||
if (
|
||||
current_user is None
|
||||
or current_user.is_anonymous
|
||||
@@ -324,9 +306,6 @@ def get_settings_for_user(username):
|
||||
@api.route("/access/users/<username>/settings", methods=["PATCH"])
|
||||
@no_firstrun_access
|
||||
def change_settings_for_user(username):
|
||||
if not userManager.enabled:
|
||||
return jsonify(SUCCESS)
|
||||
|
||||
if (
|
||||
current_user is None
|
||||
or current_user.is_anonymous
|
||||
@@ -355,9 +334,6 @@ def change_settings_for_user(username):
|
||||
@api.route("/access/users/<username>/apikey", methods=["DELETE"])
|
||||
@no_firstrun_access
|
||||
def delete_apikey_for_user(username):
|
||||
if not userManager.enabled:
|
||||
return jsonify(SUCCESS)
|
||||
|
||||
if (
|
||||
current_user is not None
|
||||
and not current_user.is_anonymous
|
||||
|
||||
@@ -14,7 +14,7 @@ from werkzeug.exceptions import BadRequest
|
||||
import octoprint.plugin
|
||||
import octoprint.util
|
||||
from octoprint.access.permissions import Permissions
|
||||
from octoprint.server import pluginManager, printer
|
||||
from octoprint.server import pluginManager, printer, userManager
|
||||
from octoprint.server.api import NO_CONTENT, api
|
||||
from octoprint.server.util.flask import no_firstrun_access, with_revalidation_checking
|
||||
from octoprint.settings import settings, valid_boolean_trues
|
||||
@@ -83,11 +83,13 @@ def _etag(lm=None):
|
||||
etag_factory=_etag,
|
||||
lastmodified_factory=_lastmodified,
|
||||
unless=lambda: request.values.get("force", "false") in valid_boolean_trues
|
||||
or settings().getBoolean(["server", "firstRun"]),
|
||||
or settings().getBoolean(["server", "firstRun"])
|
||||
or not userManager.has_been_customized(),
|
||||
)
|
||||
def getSettings():
|
||||
if not Permissions.SETTINGS_READ.can() and not settings().getBoolean(
|
||||
["server", "firstRun"]
|
||||
if not Permissions.SETTINGS_READ.can() and not (
|
||||
settings().getBoolean(["server", "firstRun"])
|
||||
or not userManager.has_been_customized()
|
||||
):
|
||||
abort(403)
|
||||
|
||||
|
||||
@@ -113,10 +113,7 @@ def requireLoginRequestHandler():
|
||||
if _flask.request.endpoint.endswith(".static"):
|
||||
return
|
||||
|
||||
if not (
|
||||
octoprint.server.userManager.enabled
|
||||
and octoprint.server.userManager.has_been_customized()
|
||||
):
|
||||
if not octoprint.server.userManager.has_been_customized():
|
||||
return
|
||||
|
||||
user = flask_login.current_user
|
||||
@@ -211,11 +208,10 @@ def get_user_for_apikey(apikey):
|
||||
# master key was used
|
||||
return octoprint.server.userManager.api_user_factory()
|
||||
|
||||
if octoprint.server.userManager.enabled:
|
||||
user = octoprint.server.userManager.find_user(apikey=apikey)
|
||||
if user is not None:
|
||||
# user key was used
|
||||
return user
|
||||
user = octoprint.server.userManager.find_user(apikey=apikey)
|
||||
if user is not None:
|
||||
# user key was used
|
||||
return user
|
||||
|
||||
apikey_hooks = plugin_manager().get_hooks("octoprint.accesscontrol.keyvalidator")
|
||||
for name, hook in apikey_hooks.items():
|
||||
@@ -233,9 +229,6 @@ def get_user_for_apikey(apikey):
|
||||
|
||||
|
||||
def get_user_for_remote_user_header(request):
|
||||
if not octoprint.server.userManager.enabled:
|
||||
return None
|
||||
|
||||
if not settings().getBoolean(["accessControl", "trustRemoteUser"]):
|
||||
return None
|
||||
|
||||
|
||||
@@ -1523,22 +1523,17 @@ def no_firstrun_access(func):
|
||||
If you decorate a view with this, it will ensure that first setup has been
|
||||
done for OctoPrint's Access Control.
|
||||
|
||||
If OctoPrint's Access Control has not been setup yet (indicated by the "firstRun"
|
||||
flag from the settings being set to True and the userManager not indicating
|
||||
that it's user database has been customized from default), the decorator
|
||||
If OctoPrint's Access Control has not been setup yet (indicated by the userManager
|
||||
not reporting that its user database has been customized from default), the decorator
|
||||
will cause a HTTP 403 status code to be returned by the decorated resource.
|
||||
"""
|
||||
|
||||
@functools.wraps(func)
|
||||
def decorated_view(*args, **kwargs):
|
||||
# if OctoPrint hasn't been set up yet, abort
|
||||
if (
|
||||
settings().getBoolean(["server", "firstRun"])
|
||||
and settings().getBoolean(["accessControl", "enabled"])
|
||||
and (
|
||||
octoprint.server.userManager is None
|
||||
or not octoprint.server.userManager.has_been_customized()
|
||||
)
|
||||
if settings().getBoolean(["server", "firstRun"]) and (
|
||||
octoprint.server.userManager is None
|
||||
or not octoprint.server.userManager.has_been_customized()
|
||||
):
|
||||
return flask.make_response("OctoPrint isn't setup yet", 403)
|
||||
return func(*args, **kwargs)
|
||||
|
||||
@@ -332,7 +332,6 @@ def index():
|
||||
|
||||
if (
|
||||
request.headers.get("X-Preemptive-Recording", "no") == "no"
|
||||
and userManager.enabled
|
||||
and userManager.has_been_customized()
|
||||
):
|
||||
if not _has_permissions(Permissions.STATUS, Permissions.SETTINGS_READ):
|
||||
@@ -376,7 +375,6 @@ def index():
|
||||
|
||||
now = datetime.datetime.utcnow()
|
||||
|
||||
enable_accesscontrol = userManager.enabled
|
||||
enable_timelapse = settings().getBoolean(["webcam", "timelapseEnabled"])
|
||||
enable_loading_animation = settings().getBoolean(["devel", "showLoadingAnimation"])
|
||||
enable_sd_support = settings().get(["feature", "sdSupport"])
|
||||
@@ -387,19 +385,12 @@ def index():
|
||||
sockjs_connect_timeout = settings().getInt(["devel", "sockJsConnectTimeout"])
|
||||
|
||||
def default_template_filter(template_type, template_key):
|
||||
if template_type == "navbar":
|
||||
return template_key != "login" or enable_accesscontrol
|
||||
elif template_type == "tab":
|
||||
if template_type == "tab":
|
||||
return template_key != "timelapse" or enable_timelapse
|
||||
elif template_type == "settings":
|
||||
return template_key != "accesscontrol" or enable_accesscontrol
|
||||
elif template_type == "usersettings":
|
||||
return enable_accesscontrol
|
||||
else:
|
||||
return True
|
||||
|
||||
default_additional_etag = [
|
||||
enable_accesscontrol,
|
||||
enable_timelapse,
|
||||
enable_loading_animation,
|
||||
enable_sd_support,
|
||||
@@ -613,7 +604,7 @@ def index():
|
||||
)
|
||||
|
||||
wizard = wizard_active(filtered_templates)
|
||||
accesscontrol_active = enable_accesscontrol and userManager.has_been_customized()
|
||||
accesscontrol_active = userManager.has_been_customized()
|
||||
|
||||
render_kwargs = _get_render_kwargs(
|
||||
filtered_templates, _plugin_names, _plugin_vars, now
|
||||
@@ -622,7 +613,7 @@ def index():
|
||||
{
|
||||
"enableWebcam": enable_webcam,
|
||||
"enableTemperatureGraph": enable_temperature_graph,
|
||||
"enableAccessControl": enable_accesscontrol,
|
||||
"enableAccessControl": True,
|
||||
"accessControlActive": accesscontrol_active,
|
||||
"enableLoadingAnimation": enable_loading_animation,
|
||||
"enableSdSupport": enable_sd_support,
|
||||
|
||||
@@ -377,7 +377,6 @@ default_settings = {
|
||||
"controls": [],
|
||||
"system": {"actions": []},
|
||||
"accessControl": {
|
||||
"enabled": True,
|
||||
"salt": None,
|
||||
"userManager": "octoprint.access.users.FilebasedUserManager",
|
||||
"groupManager": "octoprint.access.groups.FilebasedGroupManager",
|
||||
|
||||
@@ -18,10 +18,7 @@ $(function () {
|
||||
self.access.permissions.STATUS,
|
||||
self.access.permissions.SETTINGS_READ
|
||||
) &&
|
||||
(!CONFIG_FIRST_RUN ||
|
||||
(self.coreWizardAcl &&
|
||||
self.coreWizardAcl.setup() &&
|
||||
self.coreWizardAcl.decision()))
|
||||
CONFIG_ACCESS_CONTROL_ACTIVE
|
||||
) {
|
||||
location.reload();
|
||||
}
|
||||
|
||||
@@ -20,10 +20,7 @@ $(function () {
|
||||
self.showDialog = function () {
|
||||
if (
|
||||
!CONFIG_WIZARD ||
|
||||
!(
|
||||
(CONFIG_FIRST_RUN && !CONFIG_ACCESS_CONTROL_ACTIVE) ||
|
||||
self.loginState.isAdmin()
|
||||
)
|
||||
!(!CONFIG_ACCESS_CONTROL_ACTIVE || self.loginState.isAdmin())
|
||||
)
|
||||
return;
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
var CONFIG_USERSPERPAGE = 10;
|
||||
var CONFIG_GROUPSPERPAGE = 10;
|
||||
var CONFIG_WEBCAM_STREAM = "{{ webcamStream|e }}"; // deprecated, only left for compatibility reasons
|
||||
var CONFIG_ACCESS_CONTROL = {% if enableAccessControl -%} true; {% else %} false; {%- endif %}
|
||||
var CONFIG_ACCESS_CONTROL = true; // deprecated, only left for compatibility reasons
|
||||
var CONFIG_ACCESS_CONTROL_ACTIVE = {% if accessControlActive -%} true; {% else %} false; {%- endif %}
|
||||
var CONFIG_SD_SUPPORT = {% if enableSdSupport -%} true; {% else %} false; {%- endif %}
|
||||
var CONFIG_FIRST_RUN = {% if firstRun -%} true; {% else %} false; {%- endif %}
|
||||
|
||||
Reference in new issue
Block a user