Просмотр исходного кода

fix: only let guests run harmless actions in the example config (#1180)

James Read 1 день назад
Родитель
Сommit
93348a756c

+ 66 - 12
config.yaml

@@ -25,9 +25,14 @@ actions:
   # Lots of people also use OliveTin to monitor their servers, like checking
   # disk space, or checking logs. `onclick: execution-dialog` shows output.
   - title: Check disk space
+    acls: [guest_actions]
     icon: disk
-    shell: df -h /
+    exec: ["df", "-h", "/"]
     onclick: execution-dialog
+    # Second webhook example: POST /webhooks?demo=disk-space
+    execOnWebhook:
+      - matchQuery:
+          demo: disk-space
 
   # This uses `onclick: execution-dialog` to show a dialog with more
   # information about the command that was run.
@@ -46,6 +51,7 @@ actions:
   # If you are running OliveTin in a container remember to pass through the
   # docker socket! https://docs.olivetin.app/solutions/container-control-panel/index.html
   - title: Ping the Internet
+    acls: [guest_actions]
     shell: ping -c 3 1.1.1.1
     icon: ping
     onclick: execution-dialog
@@ -54,6 +60,7 @@ actions:
 
   # You can also rate-limit actions too.
   - title: Sync Disks
+    acls: [guest_actions]
     shell: sync
     id: syncdisks
     icon: disk
@@ -77,6 +84,7 @@ actions:
     # execOnCalendarFile: examples/demo-olivetin-calendar.yaml
 
   - title: Verify backup archive
+    acls: [guest_actions]
     shell: sleep 3 && echo "Backup archive verified"
     groups: [ backup-jobs ]
     timeout: 30
@@ -88,16 +96,12 @@ actions:
   #
   # Docs: https://docs.olivetin.app/action_examples/ping.html
   - title: Ping host
+    acls: [guest_actions]
     id: ping_host
     shell: ping {{ host }} -c {{ count }}
     icon: ping
     timeout: 100
     onclick: history
-    # https://docs.olivetin.app/action_execution/onwebhook.html — POST to /webhooks
-    # with header X-OliveTin-Demo: ping-host (path and payload rules are documented).
-    execOnWebhook:
-      - matchHeaders:
-          X-OliveTin-Demo: ping-host
     arguments:
       - name: host
         title: Host
@@ -111,6 +115,22 @@ actions:
         default: 3
         description: How many times to do you want to ping?
 
+  # Actions can be started by a webhook, as well as from the web UI. Webhook
+  # actions must use `exec:`, not `shell:`. This one takes no arguments, so a
+  # webhook request can only start it, not change what it runs. Replace the
+  # command with your own script.
+  #
+  # Docs: https://docs.olivetin.app/action_execution/onwebhook.html
+  # POST to /webhooks with the header X-OliveTin-Demo: run-script
+  - title: Run script on webhook
+    id: run_script_on_webhook
+    icon: '🔗'
+    exec: ["echo", "Webhook received. Replace this with your own script."]
+    onclick: execution-dialog
+    execOnWebhook:
+      - matchHeaders:
+          X-OliveTin-Demo: run-script
+
   # OliveTin can control containers - docker is just a command line app.
   #
   # However, if you are running in a container you will need to do some setup,
@@ -150,6 +170,7 @@ actions:
   #
   # Docs: https://docs.olivetin.app/args/input_checklist.html
   - title: Backup selected directories
+    acls: [guest_actions]
     icon: backup
     shell: 'echo "Backing up: {{ directories }}"'
     arguments:
@@ -198,10 +219,6 @@ actions:
     icon: ssh
     shell: olivetin-setup-easy-ssh
     onclick: execution-dialog
-    # Second webhook example: POST /webhooks?demo=setup-ssh
-    execOnWebhook:
-      - matchQuery:
-          demo: setup-ssh
 
   # Here's how to use SSH with the "easy" config, to restart a service on
   # another server.
@@ -233,32 +250,40 @@ actions:
   # you have these referenced in a dashboard, they will not show up in the
   # `actions` view.
   - title: Ping hypervisor1
+    acls: [guest_actions]
     shell: echo "hypervisor1 online"
 
   - title: Ping hypervisor2
+    acls: [guest_actions]
     shell: echo "hypervisor2 online"
 
   - title: Ping hypervisor3
+    acls: [guest_actions]
     shell: echo "hypervisor3 online"
 
   - title: Ping hypervisor4
+    acls: [guest_actions]
     shell: echo "hypervisor4 online"
 
   - title: "{{ server.name }} Wake on Lan"
+    acls: [guest_actions]
     shell: echo "Sending Wake on LAN to {{ server.hostname }}"
     icon: <iconify-icon icon="carbon:awake"></iconify-icon>
     entity: server
 
   - title: "{{ server.name }} Power Off"
+    acls: [guest_actions]
     shell: "echo 'Power Off Server: {{ server.hostname }}'"
     icon: <iconify-icon icon="carbon:flash-off"></iconify-icon>
     entity: server
 
   - title: "{{ server.name }} Print server name"
+    acls: [guest_actions]
     shell: 'echo "Server name: {{ server.name }}"'
     entity: server
 
   - title: Ping All Servers
+    acls: [guest_actions]
     shell: "echo 'Ping all servers'"
     icon: ping
     # https://docs.olivetin.app/action_execution/onfilecreated.html
@@ -279,6 +304,7 @@ actions:
     triggers: ["Update container entity file"]
 
   - title: Long running action
+    acls: [guest_actions]
     shell: sleep 300
     timeout: 300
     icon: logs
@@ -449,23 +475,51 @@ defaultPolicy:
   showLogList: true
 
 # Permissions affect actions (eg: ability to view a specific log).
+#
+# Guests can see every action, but can only run the harmless demo actions that
+# carry `acls: [guest_actions]`. Everything else needs a user in the "admins"
+# usergroup. Only give guests actions that you are happy for anyone who can
+# reach OliveTin to run.
 # Docs: https://docs.olivetin.app/security/acl.html
 defaultPermissions:
   view: true
-  exec: true
-  logs: true
+  exec: false
+  logs: false
+  kill: false
 
 # OliveTin uses access control lists to match up policy and permissions to users.
 # Docs: https://docs.olivetin.app/security/acl.html
 accessControlLists:
+  # Admins can do everything with every action.
   - name: admin_acl
     matchUsergroups: ["admins"]
+    addToEveryAction: true
     policy:
       showDiagnostics: true
     permissions:
       view: true
       exec: true
       logs: true
+      kill: true
+
+  # Guests can run the demo actions that list this ACL. Add your own
+  # usergroups here to let logged in users run them too.
+  - name: guest_actions
+    matchUsergroups: ["guest"]
+    permissions:
+      view: true
+      exec: true
+      logs: true
+      kill: true
+
+  # Actions started by execOnStartup, execOnCron, execOnWebhook and the other
+  # triggers run as the "system" usergroup. Triggers only start the actions
+  # you configured them on.
+  - name: system_triggers
+    matchUsergroups: ["system"]
+    addToEveryAction: true
+    permissions:
+      exec: true
 
 # OliveTin contains many more configuration options not in this default config.
 # Check out docs.olivetin.app for a setting if you feel like you're missing something.

+ 19 - 0
docs/modules/ROOT/pages/security/acl.adoc

@@ -116,6 +116,25 @@ accessControlLists:
     addToEveryAction: true
 ```
 
+[#acls-for-triggers]
+=== ACLs for triggers (startup, cron, webhooks)
+
+Actions started by a trigger, such as `execOnStartup`, `execOnCron`, `execOnCalendarFile`, `execOnFileCreatedInDir` or `execOnWebhook`, run as a user in the `system` usergroup, and the same ACL checks apply. If you set `defaultPermissions.exec` to `false`, give the `system` usergroup `exec`, or your triggered actions will be blocked:
+
+[source,yaml]
+.`config.yaml`
+```yaml
+accessControlLists:
+  - name: system_triggers
+    matchUsergroups:
+      - system
+    permissions:
+      exec: true
+    addToEveryAction: true
+```
+
+Triggers only start the actions that you configured them on, so adding this ACL to every action does not let anyone else run those actions.
+
 == ACLs and Dashboards
 
 Root dashboards can also list `acls`. This controls whether the **whole dashboard page** is visible (including `display` widgets and entity fieldsets), not just action buttons.

+ 2 - 0
docs/modules/ROOT/pages/security/example_some_admin_actions.adoc

@@ -8,6 +8,8 @@ OliveTin ACLs are *allow lists*, not deny lists. Each action starts with `defaul
 
 The default `defaultPermissions` allow guests to view and execute every action. To restrict some actions to logged-in admins while leaving others open to guests, set `defaultPermissions` to deny access by default, then use ACLs to explicitly grant access on each action.
 
+If any actions use triggers such as `execOnStartup`, `execOnCron` or `execOnWebhook`, also grant `exec` to the `system` usergroup. See xref:security/acl.adoc#acls-for-triggers[ACLs for triggers].
+
 See xref:security/acl.adoc[Access Control Lists] for the full ACL reference.
 
 == Full example configuration

+ 8 - 2
docs/modules/ROOT/pages/upgrade/upgrade_notes.adoc

@@ -5,6 +5,13 @@ OliveTin releases are published to GitHub, and the release notes are contained t
 
 == Next release (unreleased)
 
+[#example-config-guest-actions]
+=== The example config only lets guests run harmless demo actions
+
+The example `config.yaml` shipped with OliveTin (including the container image and the macOS example) used to let guests run, see logs for, and kill every example action. It now sets `defaultPermissions` to only let guests view actions. A `guest_actions` ACL lets guests run the harmless demo actions, `admin_acl` gives users in the `admins` usergroup access to every action, and a `system_triggers` ACL lets startup, cron and webhook triggers keep working. The "Setup easy SSH" and "Ping host" actions no longer have webhook triggers. The webhook examples are now "Check disk space" and a new "Run script on webhook" action, which both use `exec:` and take no arguments.
+
+Upgrading does not change your existing `config.yaml`. If your config started from the example and still has its example actions, review which of them guests can run. This is particularly important for actions that change the system, run scripts, or take a URL or other input from the user, such as "Get OliveTin Theme", "Setup easy SSH", "Delete old backups" and "Restart Docker Container". Either remove the actions you do not use, or set up permissions like the new example config. See xref:security/example_some_admin_actions.adoc[Some actions require admin] and xref:security/acl.adoc#acls-for-triggers[ACLs for triggers].
+
 [#webhook-trigger-chains-exec-only]
 === Actions triggered from webhooks can no longer use `shell:`
 
@@ -34,7 +41,7 @@ This was a bit cumbersome, because OliveTin treats the content of the "webui" di
 
 Now themes are stored in the "configdir" (wherever OliveTin finds it's config file, eg `/config` in containers), under the subdirectory `custom-webui/themes`. OliveTin will try to create the `custom-webui` folder in your configdir if it doesn't find it.
 
-The advantage of this change is that themes are stored with your config, as part of your data. 
+The advantage of this change is that themes are stored with your config, as part of your data.
 
 To upgrade, simply move any themes you might have into your configdir, under `custom-webui/themes/`. eg:
 
@@ -73,4 +80,3 @@ The new behavior is that OliveTin will always try to load `http://yourServer:133
 Internally, OliveTin maps `http://yourServer:1337/theme.css` to the `theme.css` of whatever the theme is set to with `themeName`, for example, it could map to `themes/myTheme/theme.css`.
 
 As a theme developer, normally you would reference a background image, or similar using `./background.png`, but OliveTin is loading the theme.css as the directory root, and the themes' assets from the custom-webui theme directory. Therefore you need to update paths to be like; `background-image: "/custom-webui/themes/myTheme/background.png`.
-

+ 38 - 3
var/macos/config.yaml

@@ -32,6 +32,7 @@ actions:
   # The simplest possible action: run a command, flash the button for status.
   # `ping` works identically on macOS and Linux.
   - title: Ping the Internet
+    acls: [guest_actions]
     shell: ping -c 3 1.1.1.1
     icon: ping
     popupOnStart: execution-dialog-stdout-only
@@ -44,6 +45,7 @@ actions:
   # mount under /Volumes. `df -h /` shows the boot disk; drop the path to list
   # every mounted volume.
   - title: Check disk space
+    acls: [guest_actions]
     icon: disk
     shell: df -h /
     popupOnStart: execution-dialog-stdout-only
@@ -62,6 +64,7 @@ actions:
   # A mini button that links to the logs, with rate limiting and an hourly cron.
   # `date` is identical across platforms.
   - title: date
+    acls: [guest_actions]
     shell: date
     id: date
     timeout: 6
@@ -98,6 +101,7 @@ actions:
 
   # Battery / power summary using the built-in `pmset`.
   - title: Power & battery status
+    acls: [guest_actions]
     icon: '&#128267;'   # battery
     shell: pmset -g batt
     popupOnStart: execution-dialog-stdout-only
@@ -107,6 +111,7 @@ actions:
   # Prompt the user for input with `arguments`. `ping` again works as-is.
   # Docs: https://docs.olivetin.app/action_examples/ping.html
   - title: Ping host
+    acls: [guest_actions]
     id: ping_host
     shell: ping {{ host }} -c {{ count }}
     icon: ping
@@ -244,20 +249,50 @@ defaultPolicy:
   showLogList: true
 
 # Permissions affect individual actions.
+#
+# Guests can see every action, but can only run the harmless demo actions that
+# carry `acls: [guest_actions]`. Everything else needs a user in the "admins"
+# usergroup. Only give guests actions that you are happy for anyone who can
+# reach OliveTin to run.
+# Docs: https://docs.olivetin.app/security/acl.html
 defaultPermissions:
   view: true
-  exec: true
-  logs: true
+  exec: false
+  logs: false
+  kill: false
 
-# ACLs match policy/permissions to users.
+# OliveTin uses access control lists to match up policy and permissions to users.
+# Docs: https://docs.olivetin.app/security/acl.html
 accessControlLists:
+  # Admins can do everything with every action.
   - name: admin_acl
     matchUsergroups: ["admins"]
+    addToEveryAction: true
     policy:
       showDiagnostics: true
     permissions:
       view: true
       exec: true
       logs: true
+      kill: true
+
+  # Guests can run the demo actions that list this ACL. Add your own
+  # usergroups here to let logged in users run them too.
+  - name: guest_actions
+    matchUsergroups: ["guest"]
+    permissions:
+      view: true
+      exec: true
+      logs: true
+      kill: true
+
+  # Actions started by execOnStartup, execOnCron, execOnWebhook and the other
+  # triggers run as the "system" usergroup. Triggers only start the actions
+  # you configured them on.
+  - name: system_triggers
+    matchUsergroups: ["system"]
+    addToEveryAction: true
+    permissions:
+      exec: true
 
 # OliveTin has many more options not shown here. See docs.olivetin.app.