Skycoder42 / QtService

A platform independent library to easily create system services and use some of their features

Home Page:https://skycoder42.github.io/QtService/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Security policies

arietto opened this issue · comments

commented

Hello. I am experimenting with QtService in Linux Mint. Please, consider the following error message:
hwmon_system_service[306]: qtservice.servicebackends.systemd: org.freedesktop.DBus.Error.AccessDenied: Connection ":1.159" is not allowed to own the service "hwmon_system_service.systemd-service" due to security policies in the configuration file.

How this error can be fixed?

As you can see from the error messages, some security policies on your system do for whatever reason not allow the systemd service to register the specified service name.

The way to fix this is to first investigate why these policies prevent the service from registering the D-BUS interface under the given name. The first ideas that come to mind are (preferrebly in that order):

  1. Set the BusName field of the .service file. Maybe your distro requires this to be set to allow the service to register the name.
  2. Create an exception for the service name in the security policy (See https://stackoverflow.com/a/4561515/3767076 for a concrete example, or just google for dbus security policies...)
  3. Try a different service name. It is possible that only certain name patterns are forbidden. Maybe specify an organization domain or change the name (See systemdservicebackend.cpp to learn how the service name is generated)
  4. Try to run the service as root/non-root and see if that makes a difference

Your distro propably has a strict policy that prevents registration of services unless explicitly allowed. There is nothing I can do in code of this library to detect/prevent/work around those limitations, it has to be done on your system.

commented

Thank your, sir. The problem was in absent *.conf file with explicit policies.
BTW, can you name benefits of using QtService in Linux as an intermediate layer between systemd and a console program? In other words, what drawbacks do we have in case of ordinary program<=>systemd link (without QtService)? My main goal is to to make small crossplatform autorestartable server.

The main advantages of QtService are:

  1. Abstraction of the concrete service backend (i.e. systemd, launchd, windows, android, ...)
  2. "Full" implementations of the service backend with support for most features
  3. Simple C++-API

The first point becomes irrelevant if you only develop for a single platform. The others are still valid, but depends on the backend you are using. Systemd in particular is not very complicated (in contrast: The windows backend is a mess to look at...). However, QtService makes shure those APIs are used correctly and takes care of stuff like logging, signals, status-control, etc.

All that stuff kinda works with systemd, even if you only create an ordinary console application, but just not quite as well. For example, you will have no logging categories, no way to track the state while starting or stopping, no socket activation and no way to reload the service.

In summary, not using this library limits what you can do by default. If you don't need any of those "extended" features, there is no real downside to not using the library. But if you want an application that integrates fully with systemd, then using this library is easier than implementing all that stuff yourself - at least in my opinion.

If you want to go without the library, check https://github.com/Skycoder42/QtService/tree/master/src/plugins/servicebackends/systemd if you need some of those features for inspiration.

commented

OK, thank you for your detailed answer!