diff --git a/src/octoprint/access/users.py b/src/octoprint/access/users.py index 951928384..5e3115d15 100644 --- a/src/octoprint/access/users.py +++ b/src/octoprint/access/users.py @@ -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) diff --git a/src/octoprint/cli/user.py b/src/octoprint/cli/user.py index d988777fd..9e9a24f67 100644 --- a/src/octoprint/cli/user.py +++ b/src/octoprint/cli/user.py @@ -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 diff --git a/src/octoprint/plugins/appkeys/__init__.py b/src/octoprint/plugins/appkeys/__init__.py index bf05ec9dd..855ac50b5 100644 --- a/src/octoprint/plugins/appkeys/__init__.py +++ b/src/octoprint/plugins/appkeys/__init__.py @@ -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): diff --git a/src/octoprint/plugins/backup/__init__.py b/src/octoprint/plugins/backup/__init__.py index b75985030..ab57aa5dc 100644 --- a/src/octoprint/plugins/backup/__init__.py +++ b/src/octoprint/plugins/backup/__init__.py @@ -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") diff --git a/src/octoprint/plugins/corewizard/__init__.py b/src/octoprint/plugins/corewizard/__init__.py index d457c5879..d5fbec327 100644 --- a/src/octoprint/plugins/corewizard/__init__.py +++ b/src/octoprint/plugins/corewizard/__init__.py @@ -105,7 +105,7 @@ class CoreWizardPlugin( return result def get_wizard_version(self): - return 3 + return 4 # ~~ helpers diff --git a/src/octoprint/plugins/corewizard/static/js/corewizard.js b/src/octoprint/plugins/corewizard/static/js/corewizard.js index c92cb9beb..ba87f2f04 100644 --- a/src/octoprint/plugins/corewizard/static/js/corewizard.js +++ b/src/octoprint/plugins/corewizard/static/js/corewizard.js @@ -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 and your OctoPrint installation is accessible from the internet, your printer will be accessible by everyone - that also includes the bad guys!" - ); - 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) { diff --git a/src/octoprint/plugins/corewizard/subwizards.py b/src/octoprint/plugins/corewizard/subwizards.py index 0655de0e5..f88575bc7 100644 --- a/src/octoprint/plugins/corewizard/subwizards.py +++ b/src/octoprint/plugins/corewizard/subwizards.py @@ -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 diff --git a/src/octoprint/plugins/corewizard/templates/corewizard_acl_wizard.jinja2 b/src/octoprint/plugins/corewizard/templates/corewizard_acl_wizard.jinja2 index 0fae5bcdd..1537989d2 100644 --- a/src/octoprint/plugins/corewizard/templates/corewizard_acl_wizard.jinja2 +++ b/src/octoprint/plugins/corewizard/templates/corewizard_acl_wizard.jinja2 @@ -1,26 +1,10 @@
- Please read the following, it is very important for your printer's health! -
-- 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 prevent strangers - possibly with - malicious intent - to gain access to your printer via an untrustworthy network - and using it in such a way that it is damaged or worse (i.e. causes a fire). -
-- If you plan on accessing OctoPrint remotely over the internet, you should not only rely on the built-in - Access Control mechanisms however - - take additional precautions. - 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! An instance available publicly on the internet - will be found, and people will try to break it open. -
-- It looks like you haven't configured access control yet. Please set up a username and password 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 %}
+ It looks like you haven't configured access control yet, which is now mandatory. + Please set up a username and password for the + initial administrator account who will have full access to both the printer and + OctoPrint's settings:
{% endtrans %} -{% trans %}- Note: 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. -
-- Do NOT underestimate the risk of access from the internet to your printer and OctoPrint instance! -
{% endtrans %} - - - - diff --git a/src/octoprint/server/__init__.py b/src/octoprint/server/__init__.py index f438c2538..2166898b6 100644 --- a/src/octoprint/server/__init__.py +++ b/src/octoprint/server/__init__.py @@ -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( diff --git a/src/octoprint/server/api/__init__.py b/src/octoprint/server/api/__init__.py index 392ec8626..5499a0463 100644 --- a/src/octoprint/server/api/__init__.py +++ b/src/octoprint/server/api/__init__.py @@ -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()) diff --git a/src/octoprint/server/api/access.py b/src/octoprint/server/api/access.py index c88c33883..0090940a0 100644 --- a/src/octoprint/server/api/access.py +++ b/src/octoprint/server/api/access.py @@ -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/