Running ratbagd As Non root In Development - hipnoizz/libratbag GitHub Wiki

Introduction

This document describes how to run ratbagd as a non-root, which may be helpful during development, especially if one wants to run and debug the code from an IDE.

This approach was verified on Ubuntu 18.04. Achieving the same under other distributions may need some adjustments.

Description

There are two issues with running ratbagd as a non-root user:

  • lack of proper permissions to the hidraw device,
  • lack of permissions to a D-Bus service that ratbagd tries to own.

Allowing Access to the Device

  1. Identify the vendor identifier and product identifier of your mouse using lsusb command, e.g. if the output of the lsusb is

     ...
     Bus 003 Device 011: ID 1e7d:2dc2 ROCCAT
     ...
    

    then the vendor id is 1e7d and the product id is 2dc2.

  2. Create a new udev rule file in /etc/udev/rules.d/ with the following content:

     SUBSYSTEM=="hidraw", ATTRS{idVendor}=="1e7d", ATTRS{idProduct}=="2dc2", MODE="0666"
    

    Replace the vendor id and product id with identifiers of your mouse. The file should have *.rules extensions, e.g. 99-roccat-kone-pure.rules.

  3. Reload udev rules using following commands:

     sudo udevadm control --reload-rules
     sudo udevadm trigger
    

After that you use can ratbag-command to check if you have required permission, i.e. issuing ./ratbag-command without sudo should not display any messages like error opening hidraw node (Permission denied).

It is generally a good idea to remove the *.rules file if it isn't needed anymore, as it gives everyone full access to the device.

Allowing to Own D-Bus Service

  1. Copy org.freedesktop.ratbag1.conf D-Bus policy file from the build directory to /etc/dbus-1/system.d/.
  2. Edit the file and replace root in <policy user="root"> with the name of you user.

After that you should be able to run ratbagd as a non-root user without getting ratbagd error: Failed to start ratbagd: Permission denied. You can also use ratbagctl to communicate with a running instance of ratbagd.

As for udev rules file you should remove the D-Bus policy file when it isn't needed anymore.

Notes

  1. This approach does not allow running ratbagd.devel nor ratbagctl.devel as a non-root user as they need a slightly different D-Bus policy file.
  2. This approach may clash with libratbag installed from DEB/RPM/etc. due to overriding D-Bus policy file.

Links

  1. https://github.com/libratbag/libratbag/issues/136 - a general idea with slightly different udev rules file.
  2. https://github.com/libratbag/libratbag/issues/421#issuecomment-344443188 - some information what is needed to run ratbagd as a non-root user.
  3. https://github.com/libratbag/libratbag/wiki/Developers - general information for developers, especially different between *.devel and non-devel binaries.