2
0

serve.rst 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. .. include:: serve.rst.inc
  2. Examples
  3. ~~~~~~~~
  4. borg serve has special support for ssh forced commands (see ``authorized_keys``
  5. example below): it will detect that you use such a forced command and extract
  6. the value of the ``--restrict-to-path`` option(s).
  7. It will then parse the original command that came from the client, makes sure
  8. that it is also ``borg serve`` and enforce path restriction(s) as given by the
  9. forced command. That way, other options given by the client (like ``--info`` or
  10. ``--umask``) are preserved (and are not fixed by the forced command).
  11. Environment variables (such as BORG_XXX) contained in the original
  12. command sent by the client are *not* interpreted, but ignored. If BORG_XXX environment
  13. variables should be set on the ``borg serve`` side, then these must be set in system-specific
  14. locations like ``/etc/environment`` or in the forced command itself (example below).
  15. ::
  16. # Allow an SSH keypair to only run borg, and only have access to /path/to/repo.
  17. # Use key options to disable unneeded and potentially dangerous SSH functionality.
  18. # This will help to secure an automated remote backup system.
  19. $ cat ~/.ssh/authorized_keys
  20. command="borg serve --restrict-to-path /path/to/repo",restrict ssh-rsa AAAAB3[...]
  21. # Set a BORG_XXX environment variable on the "borg serve" side
  22. $ cat ~/.ssh/authorized_keys
  23. command="export BORG_XXX=value; borg serve [...]",restrict ssh-rsa [...]
  24. .. note::
  25. The examples above use the ``restrict`` directive. This does automatically
  26. block potential dangerous ssh features, even when they are added in a future
  27. update. Thus, this option should be preferred.
  28. If you're using openssh-server < 7.2, however, you have to explicitly specify
  29. the ssh features to restrict and cannot simply use the restrict option as it
  30. has been introduced in v7.2. We recommend to use
  31. ``no-port-forwarding,no-X11-forwarding,no-pty,no-agent-forwarding,no-user-rc``
  32. in this case.
  33. SSH Configuration
  34. ~~~~~~~~~~~~~~~~~
  35. ``borg serve``'s pipes (``stdin``/``stdout``/``stderr``) are connected to the ``sshd`` process on the server side. In the event that the SSH connection between ``borg serve`` and the client is disconnected or stuck abnormally (for example, due to a network outage), it can take a long time for ``sshd`` to notice the client is disconnected. In the meantime, ``sshd`` continues running, and as a result so does the ``borg serve`` process holding the lock on the repository. This can cause subsequent ``borg`` operations on the remote repository to fail with the error: ``Failed to create/acquire the lock``.
  36. In order to avoid this, it is recommended to perform the following additional SSH configuration:
  37. Either in the client side's ``~/.ssh/config`` file, or in the client's ``/etc/ssh/ssh_config`` file:
  38. ::
  39. Host backupserver
  40. ServerAliveInterval 10
  41. ServerAliveCountMax 30
  42. Replacing ``backupserver`` with the hostname, FQDN or IP address of the borg server.
  43. This will cause the client to send a keepalive to the server every 10 seconds. If 30 consecutive keepalives are sent without a response (a time of 300 seconds), the ssh client process will be terminated, causing the borg process to terminate gracefully.
  44. On the server side's ``sshd`` configuration file (typically ``/etc/ssh/sshd_config``):
  45. ::
  46. ClientAliveInterval 10
  47. ClientAliveCountMax 30
  48. This will cause the server to send a keep alive to the client every 10 seconds. If 30 consecutive keepalives are sent without a response (a time of 300 seconds), the server's sshd process will be terminated, causing the ``borg serve`` process to terminate gracefully and release the lock on the repository.
  49. If you then run borg commands with ``--lock-wait 600``, this gives sufficient time for the borg serve processes to terminate after the SSH connection is torn down after the 300 second wait for the keepalives to fail.
  50. You may, of course, modify the timeout values demonstrated above to values that suit your environment and use case.