Score:0

Allow a systemd service access to /sys/…/energy_uj - udev rule changing owner having no effect?

fr flag

I'd like to collect the my CPU power usage on some "plain" linux boxes (i.e. no fancy things like VMs or let alone K8s) via scaphandre or prometheus_node_exporter, running as systemd service and not as root.

The problem: The /sys/…/energy_uj exposed by the kernel module intel_rapl_common are by default owned by root and mode 0400.

My first approach was to

ExecStartPre=-+/usr/bin/modprobe intel_rapl_common
ExecStartPre=+/usr/bin/find /sys/devices/virtual/powercap -name energy_uj -exec chmod g+r -R {} + -exec chown root:powercap {} +
DynamicUser=yes
Group=powercap

While this does work (systemd apparently "creates" an ephemeral (primary) group just based on the existence of this service file, which is usable by chmod), I'd like a cleaner approach.

So, I created the necessary entries in /usr/lib/sysusers.d/, /usr/lib/modules-load.d/ to have a group powercap and load the kernel module automatically, and I also added an udev rule:

ENV{SUBSYSTEM}=="powercap", ACTION=="add|change", MODE="0440", OWNER="root", GROUP="powercap"

but this rule seems to have no effect, the permissions and owner of all related folders are as before. However, it seems that the rule is properly applied, because when I do:

ENV{SUBSYSTEM}=="powercap", ACTION=="add|change", OWNER="root", PROGRAM+="/usr/bin/find /sys$env{DEVPATH} -name energy_uj -exec chmod g+r -R {} + -exec chown root:powercap {} +"

that rule works. But it feels like I've regressed towards the original systemd/ExecStartPre based solution.

So, sorry, I'm asking two questions as one:

  • Is there a way to make the "clean" udev rule without PROGRAM change permissions and ownership?
  • Or, alternatively, is there another similarly "clean" way to get read permissions?
meuh avatar
in flag
Perhaps your GROUP setting is being overridden by a later udev rule. Did you name your file `99-something.rules`?
fr flag
Changing the name to `99-zzzomg.rules` did not have any effect. :/
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.