non-root-user.rst 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. .. include:: ../global.rst.inc
  2. .. highlight:: none
  3. .. _non_root_user:
  4. ================================
  5. Backing up using a non-root user
  6. ================================
  7. This section shows how to run borg as a non-root user and still be able to
  8. backup every file on the system.
  9. Normally borg is run as the root user to bypass all filesystem permission and
  10. be able to read all files. But in theory this also allows borg to modify or
  11. delete files on you system, incase of a bug for example.
  12. To remove this possible we can run borg as a non-root user and give it readonly
  13. permissions to all files on the system.
  14. Using linux capabilities inside a systemd service
  15. =================================================
  16. One way to do so, is to use linux `capabilities
  17. <https://man7.org/linux/man-pages/man7/capabilities.7.html>`_ within a systemd
  18. service.
  19. Linux capabilities allow us to give parts of the privileges the root user has to
  20. a non-root user. This works on a per-thread level and does not give the permission
  21. to the non-root user as a whole.
  22. For this we need to run our backup script from a systemd service and use the `AmbientCapabilities
  23. <https://www.freedesktop.org/software/systemd/man/latest/systemd.exec.html#AmbientCapabilities=>`_
  24. option added in systemd 229.
  25. A very basic unit file would look like this:
  26. ::
  27. [Unit]
  28. Description=Borg Backup
  29. [Service]
  30. Type=oneshot
  31. User=borg
  32. ExecStart=/usr/local/sbin/backup.sh
  33. AmbientCapabilities=CAP_DAC_READ_SEARCH
  34. The CAP_DAC_READ_SEARCH capability gives borg readonly access to all files and directories on the system.
  35. This service can then be started manually using ``systemctl start`` or regularly with a systemd timer.