diff --git a/.github/workflows/trigger_docker.yml b/.github/workflows/trigger_docker.yml index 0b4553545..1a86bb0c6 100644 --- a/.github/workflows/trigger_docker.yml +++ b/.github/workflows/trigger_docker.yml @@ -19,7 +19,7 @@ jobs: with: token: ${{ secrets.DOCKER_ACCESS_TOKEN }} repository: ${{ github.repository_owner }}/octoprint-docker - event-type: ${{ github.event_name }} + event-type: ${{ github.event.action }} client-payload: '{"tag_name": "${{ github.event.release.tag_name }}"}' dispatch_canary: @@ -32,7 +32,7 @@ jobs: token: ${{ secrets.DOCKER_ACCESS_TOKEN }} repository: ${{ github.repository_owner }}/octoprint-docker event-type: "canary" - client-payload: '{"tag_name": "${{ github.sha }}"}' + client-payload: '{"tag_name": "maintenance"}' dispatch_bleeding: runs-on: ubuntu-latest @@ -44,4 +44,4 @@ jobs: token: ${{ secrets.DOCKER_ACCESS_TOKEN }} repository: ${{ github.repository_owner }}/octoprint-docker event-type: "bleeding" - client-payload: '{"tag_name": "${{ github.sha }}"}' + client-payload: '{"tag_name": "devel"}' diff --git a/AUTHORS.md b/AUTHORS.md index a0da5b375..e201eacc2 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -131,6 +131,7 @@ date of first contribution): * [Manuel McLure](https://github.com/ManuelMcLure) * ["j7126"](https://github.com/j7126) * ["MichaIng"](https://github.com/MichaIng) + * ["jasonbcox"](https://github.com/jasonbcox) 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 diff --git a/docs/configuration/config_yaml.rst b/docs/configuration/config_yaml.rst index 7b8a949eb..56a0a5fce 100644 --- a/docs/configuration/config_yaml.rst +++ b/docs/configuration/config_yaml.rst @@ -30,7 +30,7 @@ Use the following settings to enable access control: userManager: octoprint.access.users.FilebasedUserManager # The YAML user file to use. If left out defaults to users.yaml in the default configuration folder. - userFile: /path/to/users.yaml + userfile: /path/to/users.yaml # If set to true, will automatically log on clients originating from any of the networks defined in # "localNetworks" as the user defined in "autologinAs". Defaults to false. diff --git a/docs/features/accesscontrol.rst b/docs/features/accesscontrol.rst index ca035d699..23bf90b75 100644 --- a/docs/features/accesscontrol.rst +++ b/docs/features/accesscontrol.rst @@ -3,7 +3,7 @@ Access Control ============== -.. versionchanged:: 1.4.0 +.. versionchanged:: 1.5.0 OctoPrint's bundled access control feature allows granular permission control over which users or user groups are allowed to access which parts of OctoPrint. @@ -17,8 +17,17 @@ users out of the box. thus also cannot limit access to it. If an anonymous user correctly guesses the webcam URL, they will thus be able to see it. -If read-only access for anonymous users is enabled, anonymous users will have -read-only access to the following parts of the UI: +Upon first start a configuration wizard is provided which allows configuration +of the first administrator account to be used for OctoPrint. After initial setup, +you can then create more users and groups under Settings > Access Control for +customisation of the granular permission system. + +The predefined "Guests" group can be used to configure default permissions of anonymous +users, that is those who have not logged in. By default, no permissions are granted to +these users. + +A predefined "Read-only Access" group with no users is configured which by default grants +read-only access to the following parts of the UI to any users assigned to this group: * printer state * available gcode files and stats (upload is disabled) @@ -30,29 +39,195 @@ read-only access to the following parts of the UI: * any components provided through plugins which are enabled for anonymous users -Logged in users without admin flag will be allowed to access everything besides the -Settings and System Commands, which are admin-only. +Another predefined "Operator" group is the default group for newly created users and +by default gives access to all aspects of OctoPrint that involve regular printer +operation. It matches the old "user" role from OctoPrint prior to 1.4.0. -If Access Control is disabled, everything is directly accessible. **That also -includes all administrative functionality as well as full control over the -printer**, and without the need for an :ref:`API key `! - -Upon first start a configuration wizard is provided which allows configuration -of the first administrator account or alternatively disabling Access Control -(which is **NOT** recommended for systems that are directly accessible via the -internet or other untrusted networks!). +Finally, the predefined "Admins" group gives full admin access to the platform. You should +be careful of who you put into that. It matches the old "admin" role from OctoPrint prior +to 1.4.0. .. hint:: If you plan to have your OctoPrint instance accessible over the internet, - **always enable Access Control** and ideally **don't make it accessible to + **please use additional security measures** and ideally **don't make it accessible to everyone over the internet but instead use a VPN** or at the very least - HTTP basic authentication on a layer above OctoPrint. + HTTP basic authentication on a layer above OctoPrint. Unless you are using a VPN + **please do not** enable any permissions for the Guest group or the auto-login feature + described below. A physical device that includes heaters and stepper motors really should not be publicly reachable by everyone with an internet connection, even with access control enabled. +.. _sec-features-access_control-autologin: + +Autologin +--------- + +While access control cannot be disabled as of OctoPrint 1.5+, the Autologin feature can +be used to bypass authentication for hosts on the network(s) that you trust. + +Starting with OctoPrint 1.5.0, OctoPrint makes enabled access control mandatory. This +might be an inconvience for some who run OctoPrint in an isolated setup where a login is +not required to ensure security, at a benefit for a huge number of users out there who +continue to underestimate or simply ignore the risk of keeping their OctoPrint instance +unsecured and then happily exposing it on the public internet. + +That being said, even as far back as OctoPrint 1.0.0 (released in 2013) there has existed +a way to have OctoPrint automatically log you in, if you connect from a trusted local +network address. This functionality has not been exposed on the UI, and for now also won't +be (to make it a bit harder to once again create an insecure setup for those who simply +won't listen to common sense), but it's easy to set up with a bit of configuration +editing. + +When set up properly, it will make sure to automatically log you in as a configured user +whenever you connect from a device on your local network. To get back pretty much the same +behaviour as with disabled access control, you'll only need to create a single (admin) +account and then set up autologin for it. + + +.. warning:: + + **Do not do this if you cannot trust EVERYONE on your local network.** And that really + means mean everyone. If you ignore this and then someone takes over your OctoPrint + instance, installs malware on it and makes your printer print an endless stream of + benchies, that's on you. + +.. _sec-features-access_control-autologin-gather_config_info: + +Gather configuration information +................................ + +You can configure Autologin via a plugin (the easy way), or manually (the hard way), but +in either case you will need to specify which user should be automatically logged in, and +which hosts are permitted access this way. + +**Improperly setting this subnet option can lead to the compromise of your system, or even +your entire network. Proceed with extreme caution.** + +The subnet to use is usually the IP address range of your LAN, which sounds scary but +actually isn't. Just `figure out your PC's IP address and subnet mask `_ +and then combine both with a / in between. + +On OctoPi (or another Linux distribution) you can use the follwing command: + +.. code-block:: + + ip route | grep -P 'eth0|wlan0' | awk '{print $1}' + +Or, for IPv6, use this: + +.. code-block:: + + ip -6 route | grep -P 'eth0|wlan0' | awk '{print $1}' + +This will be what you set as the subnet in the plugin, or where it says +```` below on the manual configuration instructions. + +Example: Your PC has an IP address of ``192.168.23.42`` and a subnet mask of +``255.255.255.0``. Your address range is ``192.168.23.42/255.255.255.0``. + +.. _sec-features-access_control-autologin-plugin: + +The easy way: Using the OctoPrint-AutoLoginConfig plugin +........................................................ + +The easist way to configure AutoLogin is to install the +`OctoPrint-AutoLoginConfig plugin `_ +via the plugin manager. + +Open its settings and follow the instructions on the screen. + +.. _sec-features-access_control-autologin-manual: + +The hard way: Manual editing of config.yaml +........................................... + +Preparation +*********** + +First of all, read :ref:`the YAML primer `. You +will have to edit OctoPrint's main configuration file, and thus should make sure +you understand at least roughly how things work and that you should keep your +hands off the Tab key. If you don't, you might break your config file, and +while the steps include making a backup, this still can be easily avoided by +learning about the DOs and DONTs first. + +Then, take a look at :ref:`the docs on config.yaml ` +on where to find that central configuration file of OctoPrint. + +Configuration +************* + +Ready? Let's do some editing then. I'll outline what to do and where first, and then +further down there's also a dedicated list of steps for OctoPi specifically. + +1. Shutdown OctoPrint +2. Make a backup of your config.yaml +3. Open it in a text editor (e.g. nano). Right at the very top it'll say something like + this: + + .. code-block:: yaml + + accessControl: + salt: aabbccddee1234523452345 + + Edit this, adding lines so it looks like this (making absolutely sure not to touch the + salt line): + + .. code-block:: yaml + accessControl: + salt: aabbccddee1234523452345 + autologinLocal: true + autologinAs: "" + localNetworks: + - "127.0.0.0/8" + - "" + +4. Restart OctoPrint, check that everything works. + +This will automatically log you in as the user you specified whenver you connect to +OctoPrint from an address in the address range (e.g. a device on your local network). + +OctoPi specific steps +********************* + +If you are running OctoPi you will have to SSH into your Raspberry Pi. Then issue +the following commands: + +1. ``sudo service octoprint stop`` +2. ``cp ~/.octoprint/config.yaml ~/.octoprint/config.yaml.back`` +3. ``nano ~/.octoprint/config.yaml, make the edits as described above`` +4. ``sudo service octoprint start`` + +If something went wrong, you can restore the config backup with + +.. code-block:: + + cp ~/.octoprint/config.yaml.back ~/.octoprint/config.yaml + + +If you are using a VPN and your setup ABSOLUTELY REQUIRES disabling internal OctoPrint access controls +...................................................................................................... + +.. warning:: + + You probably shouldn't do this, EVER. There are usually other options. Don't even + THINK about it, unless you have a VPN layer for security. Only consider proceeding + with this configuration after exhausting ALL other possibilities, and even then, you + should think long and hard about whether this is a good idea. You almost certainly + don't need or want to do this. + +While access controls can no longer be disabled in OctoPrint 1.5+, this can be +approximated by an Autologin configuration that automatically logs in all users, that is +by using subnets that match all possible IP addresses. By specifying the ``0.0.0.0/0`` +subnet (for IPv4) and ``::/0`` for IPv6 in the AutoLogin configuration, you can achieve +this. This configuration is permitted, but highly, highly discouraged. + +Please don't do this. You will almost certainly regret it. You alone are responsible for +your actions. + .. _sec-features-access_control-hooks: Available Extension Hooks @@ -71,42 +246,7 @@ See :ref:`here `. .. _sec-features-access_control-hooks-loginui: -octoprint.plugin.loginui.theming -................................ +octoprint.theming.login +....................... -See :ref:`here `. - -.. _sec-features-access_control-rerunning_wizard: - -Rerunning the wizard --------------------- - -In case Access Control was disabled in the configuration wizard, it is -possible to re-run it by editing ``config.yaml`` [#f1]_ and setting ``firstRun`` -in the ``server`` section and ``enabled`` in the ``accessControl`` section to -``true``: - -.. code-block-ext:: yaml - - accessControl: - enabled: true - # ... - server: - firstRun: true - -Then restart the server and connect to the web interface - the wizard should -be shown again. - -.. note:: - - If user accounts were created prior to disabling Access Control and those - user accounts are not to be used any more, remove ``.octoprint/users.yaml``. - If you don't remove this file, the above changes won't lead to the - configuration being shown again, instead Access Control will just be - enabled using the already existing login data. This is to prevent you from - resetting access control by accident. - -.. rubric:: Footnotes - -.. [#f1] For Linux that will be ``~/.octoprint/config.yaml``, for Windows it will be ``%APPDATA%/OctoPrint/config.yaml`` and for - Mac ``~/Library/Application Support/OctoPrint/config.yaml`` +See :ref:`here `. diff --git a/docs/plugins/hooks.rst b/docs/plugins/hooks.rst index 5863c034b..eb52fbec4 100644 --- a/docs/plugins/hooks.rst +++ b/docs/plugins/hooks.rst @@ -1173,15 +1173,6 @@ octoprint.plugin.backup.additional_excludes See :ref:`here `. -.. _sec-plugins-hook-plugin-loginui-theming: - -octoprint.plugin.loginui.theming -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -.. versionadded:: 1.4.0 - -See :ref:`here `. - .. _sec-plugins-hook-plugin-pluginmanager-reconnect: octoprint.plugin.pluginmanager.reconnect_hooks diff --git a/scripts/octoprint.service b/scripts/octoprint.service index 14f5d7f4b..ae5405c34 100644 --- a/scripts/octoprint.service +++ b/scripts/octoprint.service @@ -6,7 +6,7 @@ Wants=network-online.target [Service] Environment="LC_ALL=C.UTF-8" Environment="LANG=C.UTF-8" -Type=simple +Type=exec User=pi ExecStart=/home/pi/OctoPrint/venv/bin/octoprint diff --git a/src/octoprint/plugins/action_command_prompt/templates/action_command_prompt_navbar.jinja2 b/src/octoprint/plugins/action_command_prompt/templates/action_command_prompt_navbar.jinja2 index 0a9d041e5..c9f903f73 100644 --- a/src/octoprint/plugins/action_command_prompt/templates/action_command_prompt_navbar.jinja2 +++ b/src/octoprint/plugins/action_command_prompt/templates/action_command_prompt_navbar.jinja2 @@ -1,3 +1,3 @@ diff --git a/src/octoprint/plugins/announcements/static/js/announcements.js b/src/octoprint/plugins/announcements/static/js/announcements.js index 2e015853f..75720f39a 100644 --- a/src/octoprint/plugins/announcements/static/js/announcements.js +++ b/src/octoprint/plugins/announcements/static/js/announcements.js @@ -31,7 +31,7 @@ $(function () { 5 ); - self.unread = ko.observable(); + self.unread = ko.observable(false); self.hiddenChannels = []; self.channelNotifications = {}; diff --git a/src/octoprint/plugins/pluginmanager/__init__.py b/src/octoprint/plugins/pluginmanager/__init__.py index 0da508497..15cb8e013 100644 --- a/src/octoprint/plugins/pluginmanager/__init__.py +++ b/src/octoprint/plugins/pluginmanager/__init__.py @@ -47,6 +47,8 @@ from octoprint.util.version import ( is_python_compatible, ) +from . import exceptions + try: from os import scandir except ImportError: @@ -378,28 +380,43 @@ class PluginManagerPlugin( ) ext = exts[0] + archive = tempfile.NamedTemporaryFile(delete=False, suffix=ext) + archive.close() + shutil.copy(upload_path, archive.name) - archive = tempfile.NamedTemporaryFile( - delete=False, suffix="{ext}".format(**locals()) - ) - try: - archive.close() - shutil.copy(upload_path, archive.name) - return self.command_install( - path=archive.name, - name=upload_name, - force="force" in flask.request.values - and flask.request.values["force"] in valid_boolean_trues, - ) - finally: + def perform_install(source, name, force=False): try: - os.remove(archive.name) - except Exception as e: - self._logger.warning( - "Could not remove temporary file {path} again: {message}".format( - path=archive.name, message=str(e) - ) + self.command_install( + path=source, + name=name, + force=force, ) + finally: + try: + os.remove(archive.name) + except Exception as e: + self._logger.warning( + "Could not remove temporary file {path} again: {message}".format( + path=archive.name, message=str(e) + ) + ) + + with self._install_lock: + if self._install_task is not None: + return make_response("There's already a plugin being installed", 409) + + self._install_task = threading.Thread( + target=perform_install, + args=(archive.name, upload_name), + kwargs={ + "force": "force" in flask.request.values + and flask.request.values["force"] in valid_boolean_trues + }, + ) + self._install_task.daemon = True + self._install_task.start() + + return jsonify(in_progress=True) @octoprint.plugin.BlueprintPlugin.route("/export", methods=["GET"]) @no_firstrun_access @@ -536,7 +553,7 @@ class PluginManagerPlugin( with self._install_lock: if self._install_task is not None: - return make_response("There's always a plugin being installed", 409) + return make_response("There's already a plugin being installed", 409) self._install_task = threading.Thread( target=self.command_install, @@ -634,7 +651,7 @@ class PluginManagerPlugin( # determine type of path if self._is_archive(path): - return self._command_install_archive( + result = self._command_install_archive( path, source=source, source_type=source_type, @@ -644,31 +661,60 @@ class PluginManagerPlugin( ) elif self._is_pythonfile(path): - return self._command_install_pythonfile( + result = self._command_install_pythonfile( path, source=source, source_type=source_type, name=name ) else: - self._logger.error( - "{} is neither an archive nor a python file, can't install that.".format( - source - ) + raise exceptions.InvalidPackageFormat() + + except requests.exceptions.HTTPError as e: + self._logger.error("Could not fetch plugin from server, got {}".format(e)) + result = { + "result": False, + "source": source, + "source_type": source_type, + "reason": "Could not fetch plugin from server, got {}".format(e), + } + self._send_result_notification("install", result) + + except exceptions.InvalidPackageFormat: + self._logger.error( + "{} is neither an archive nor a python file, can't install that.".format( + source ) - result = { - "result": False, - "source": source, - "source_type": source_type, - "reason": "Could not install plugin from {}, was neither " - "a plugin archive nor a single file plugin".format(source), - } - self._send_result_notification("install", result) - return result + ) + result = { + "result": False, + "source": source, + "source_type": source_type, + "reason": "Could not install plugin from {}, was neither " + "a plugin archive nor a single file plugin".format(source), + } + self._send_result_notification("install", result) + + except Exception: + error_msg = ( + "Unexpected error while trying to install plugin from {}".format( + source + ) + ) + self._logger.exception(error_msg) + result = { + "result": False, + "source": source, + "source_type": source_type, + "reason": error_msg, + } + self._send_result_notification("install", result) finally: if folder is not None: folder.cleanup() self._install_task = None + return result + # noinspection DuplicatedCode def _command_install_archive( self, @@ -687,11 +733,19 @@ class PluginManagerPlugin( and not self._settings.get_boolean(["ignore_throttled"]) ): # currently throttled, we refuse to run - return make_response( - "System is currently throttled, refusing to install " - "anything due to possible stability issues", - 409, + error_msg = ( + "System is currently throttled, refusing to install anything" + " due to possible stability issues" ) + self._logger.error(error_msg) + result = { + "result": False, + "source": source, + "source_type": source_type, + "reason": error_msg, + } + self._send_result_notification("install", result) + return result try: # Py3 @@ -761,11 +815,20 @@ class PluginManagerPlugin( "Looks like the plugin was already installed. Forcing a reinstall." ) force = True - except Exception: - self._logger.exception("Could not install plugin from %s" % source) - return make_response( - "Could not install plugin from URL, see the log for more details", 500 - ) + except Exception as e: + self._logger.exception("Could not install plugin from {}".format(source)) + self._logger.exception("Reason: {}".format(repr(e))) + result = { + "result": False, + "source": source, + "source_type": source_type, + "reason": "Could not install plugin from {}, see the log for more details".format( + source + ), + } + self._send_result_notification("install", result) + return result + else: if force: # We don't use --upgrade here because that will also happily update all our dependencies - we'd rather @@ -773,16 +836,21 @@ class PluginManagerPlugin( pip_args += ["--ignore-installed", "--force-reinstall", "--no-deps"] try: returncode, stdout, stderr = self._call_pip(pip_args) - except Exception: + except Exception as e: self._logger.exception( "Could not install plugin from {}".format(source) ) - return make_response( - "Could not install plugin from source {}, see the log for more details".format( + self._logger.exception("Reason: {}".format(repr(e))) + result = { + "result": False, + "source": source, + "source_type": source_type, + "reason": "Could not install plugin from source {}, see the log for more details".format( source ), - 500, - ) + } + self._send_result_notification("install", result) + return result try: result_line = list( diff --git a/src/octoprint/plugins/pluginmanager/exceptions.py b/src/octoprint/plugins/pluginmanager/exceptions.py new file mode 100644 index 000000000..0b4256018 --- /dev/null +++ b/src/octoprint/plugins/pluginmanager/exceptions.py @@ -0,0 +1,9 @@ +# -*- coding: utf-8 -*- +from __future__ import absolute_import, division, print_function, unicode_literals + +__license__ = "GNU Affero General Public License http://www.gnu.org/licenses/agpl.html" +__copyright__ = "Copyright (C) 2020 The OctoPrint Project - Released under terms of the AGPLv3 License" + + +class InvalidPackageFormat(Exception): + pass diff --git a/src/octoprint/plugins/pluginmanager/static/js/pluginmanager.js b/src/octoprint/plugins/pluginmanager/static/js/pluginmanager.js index 5b5bd9552..b0a72ccfe 100644 --- a/src/octoprint/plugins/pluginmanager/static/js/pluginmanager.js +++ b/src/octoprint/plugins/pluginmanager/static/js/pluginmanager.js @@ -435,23 +435,30 @@ $(function () { }, done: function (e, data) { var response = data.result; - if (response.result) { - self._markDone(); - } else { - self._markDone(response.reason); + if (!response.in_progress) { + if (response.result) { + self._markDone(); + } else { + self._markDone(response.reason); + } } self.uploadButton.unbind("click"); self.uploadFilename(undefined); }, fail: function (e, data) { - new PNotify({ - title: gettext("Something went wrong"), - text: gettext("Please consult octoprint.log for details"), - type: "error", - hide: false - }); - self._markDone("Could not install plugin, unknown error."); + if (data && data.errorThrown === "CONFLICT") { + // there's already a plugin being installed + self._markDone("There's already another plugin install in progress."); + } else { + new PNotify({ + title: gettext("Something went wrong"), + text: gettext("Please consult octoprint.log for details"), + type: "error", + hide: false + }); + self._markDone("Could not install plugin, unknown error."); + } self.uploadButton.unbind("click"); self.uploadFilename(undefined); } @@ -823,16 +830,23 @@ $(function () { var onSuccess = function (response) { self.installUrl(""); }, - onError = function () { - self._markDone( - "Could not install plugin, unknown error, please consult octoprint.log for details" - ); - new PNotify({ - title: gettext("Something went wrong"), - text: gettext("Please consult octoprint.log for details"), - type: "error", - hide: false - }); + onError = function (jqXHR) { + if (jqXHR.status === 409) { + // there's already a plugin being installed + self._markDone( + "There's already another plugin install in progress." + ); + } else { + self._markDone( + "Could not install plugin, unknown error, please consult octoprint.log for details" + ); + new PNotify({ + title: gettext("Something went wrong"), + text: gettext("Please consult octoprint.log for details"), + type: "error", + hide: false + }); + } }; if (reinstall) { diff --git a/src/octoprint/plugins/tracking/__init__.py b/src/octoprint/plugins/tracking/__init__.py index 077b23855..5543d60a2 100644 --- a/src/octoprint/plugins/tracking/__init__.py +++ b/src/octoprint/plugins/tracking/__init__.py @@ -241,7 +241,8 @@ class TrackingPlugin( return uptime = int(monotonic_time() - self._startup_time) - self._track("ping", octoprint_uptime=uptime) + printer_state = self._printer.get_state_id() + self._track("ping", octoprint_uptime=uptime, printer_state=printer_state) def _track_pong(self): if not self._settings.get_boolean(["events", "pong"]): diff --git a/src/octoprint/plugins/tracking/templates/tracking_wizard.jinja2 b/src/octoprint/plugins/tracking/templates/tracking_wizard.jinja2 index e5874b6c3..a8c0b3838 100644 --- a/src/octoprint/plugins/tracking/templates/tracking_wizard.jinja2 +++ b/src/octoprint/plugins/tracking/templates/tracking_wizard.jinja2 @@ -9,8 +9,14 @@