I am trying to give permission to a user to perform the same operations as root on the network device can0, such as bringing it up or down. My first idea was to set the group and/or owner of the device to my user and a group I belong to.
Here's what udevadm info -ap $(udevadm info -q path -p /sys/class/net/can0) shows before setting a udev rule:
$ udevadm info -ap $(udevadm info -q path -p /sys/class/net/can0)
looking at device '/devices/platform/soc/3f204000.spi/spi_master/spi0/spi0.0/net/can0':
KERNEL=="can0"
SUBSYSTEM=="net"
DRIVER==""
ATTR{netdev_group}=="0"
...
looking at parent device '/devices/platform/soc/3f204000.spi/spi_master/spi0/spi0.0':
KERNELS=="spi0.0"
SUBSYSTEMS=="spi"
DRIVERS=="mcp251x"
And here's the rule I tried (in /etc/udev/rules.d/50-can.rules):
KERNELS=="spi0.0", SUBSYSTEMS=="spi", DRIVERS=="mcp251x", GROUP="can", OWNER="<myuser>"
A udevadm test $(udevadm info -q path -p /sys/class/net/can0) reports the owner and group should be set correctly:
...
OWNER 1001 /etc/udev/rules.d/50-can.rules:7
GROUP 1003 /etc/udev/rules.d/50-can.rules:7
...
However after reloading the rules (udevadm control -R) and a reboot, I still cannot bring can0 up or down as a user:
$ ip link set can0 down
RTNETLINK answers: Operation not permitted
I know this rule is matched correctly because I can change the name of the interface by setting the NAME property.
I suspect the problem might have to do with the fact that I can't find a can0 interface under /dev, which might indicate that there is no character/block device for it and programs (such as ip) don't access the device through traditional unix ownership/permissions. If that's correct, how can I accomplish this with udev (namely, giving my user full permissions to can0)?
Note: I saw similar questions such as how can I give a normal user write access to a network interface?, but their solution is to use sudo. I'd rather do this with udev only, but I'll use this as a last resort.
sudo setcap cap_net_admin+ie /bin/ip(which seemed to work), but I still gotOperation not permitted. More research needed I guess.