nonroot.xml 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <PAGE>
  2. <INCLUDE file="inc/header.tmpl" />
  3. <VAR match="VAR_SEL_FEATURES" replace="selected" />
  4. <VAR match="VAR_SEL_FEATURE_NONROOT" replace="selected" />
  5. <PARSE file="menu1.xml" />
  6. <PARSE file="menu2-features.xml" />
  7. <INCLUDE file="inc/content.tmpl" />
  8. <h1>Running as non-root user</h1>
  9. <p>Under normal circumstances OpenConnect needs to be run as the root user.
  10. If it cannot create the local <tt>tun</tt> network interface, you will see
  11. an error such as:
  12. <pre> Failed to bind (TUNSETIFF) tun device: Operation not permitted</pre>
  13. or in older versions, "<tt>TUNSETIFF failed: Operation not permitted</tt>".
  14. The simple fix for this problem is, of course, to run OpenConnect as root.
  15. </p>
  16. <p>For security reasons, it is better if network-facing code can run
  17. without root privileges — and there are a few options which allow OpenConnect
  18. to run as an unprivileged user instead.</p>
  19. <h2>Pre-configured <tt>tun</tt> device</h2>
  20. <p>On Linux, it's possible to create its <tt>tun</tt> device in advance.
  21. For example:</p>
  22. <pre>
  23. # ip tuntap add vpn0 mode tun user dwmw2
  24. </pre>
  25. <p>This creates a device <tt>vpn0</tt> which can be opened by user <tt>dwmw2</tt>
  26. who can pass traffic to/from it without needing any elevated privileges. You
  27. can now tell OpenConnect to use that device by adding "<tt>-i vpn0</tt>" to
  28. its command-line arguments. Note that the <tt>/dev/net/tun</tt> device node
  29. should be readable and writeable by everyone. <i>(Some distributions misconfigure
  30. that, so if it isn't world-writeable then please file a bug against your
  31. distribution.)</i></p>
  32. <p>Of course, something does also need to <em>configure</em> the IP addresses
  33. and routing. You could either add "<tt>-s /bin/true</tt>" to OpenConnect's
  34. command line to stop it trying to run vpnc-script for itself, and manually
  35. configure the network as root too. Or you could use
  36. "<tt>-s 'sudo -E /etc/vpnc/vpnc-script'</tt>" so that OpenConnect itself
  37. runs without elevated privileges but can still invoke <tt>vpnc-script</tt>
  38. as root. Note the <tt>-E</tt> part which ensures the environment variables
  39. with the configuration are actually passed through to <tt>vpnc-script</tt>.</p>
  40. <p>NetworkManager usually has a dedicated unprivileged user <tt>nm-openconnect</tt>
  41. and runs OpenConnect as that user, having pre-created the <tt>tun</tt> device for it.
  42. OpenConnect then invokes a "vpnc-script" provided by NetworkManager which just
  43. passes all the configuration back to NetworkManager over DBus.</p>
  44. <h2>SOCKS / port-forwarding proxy</h2>
  45. <p>An alternative option which doesn't require any root access
  46. at all, is simply <em>not</em> to create the <tt>tun</tt> device and
  47. modify the system's network configuration. Instead, OpenConnect can
  48. spawn a user-supplied program, passing all data traffic through a UNIX
  49. socket to that program.</p>
  50. <p>This option can be used in conjunction with a userspace TCP stack
  51. such as <a href="https://savannah.nongnu.org/projects/lwip/">lwip</a>
  52. to provide SOCKS access to the VPN, without requiring root privileges
  53. at all.</p>
  54. <p>SOCKS proxy implementions suitable for being used from OpenConnect
  55. include:</p>
  56. <ul>
  57. <li><a href="https://github.com/cernekee/ocproxy">ocproxy</a></li>
  58. <li><a href="https://github.com/russdill/tunsocks">tunsocks</a></li>
  59. </ul>
  60. <INCLUDE file="inc/footer.tmpl" />
  61. </PAGE>