fix(docker): fix docker user permission#98
Conversation
|
There's not a standard for device ownership groups across all Linux distros. I think a better solution is to run a shell script that sources |
|
There's a problem with that approach: we don't really know user's distro during build time. Script will always read Debian because that's the base image's distro. If we set it at runtime, then another problem: we're running non privileged user, whom do not have the permission to set it's own group. If we use root, then we don't really need to set permission because we can already access everything. |
|
Did a bit more research on this topic, and permission management is just a naughty little bastard. Checked a few of the most popular distros out there including debian, arch, RHEL/fedora, gentoo and such, and I only find debian and arch have proper documentations on these system groups, no mention on other distros' wikis, only some sparse info here and there. With these limited knowledge, it seems like most distros use Oh and these groups might have different group ids under the hood. So it's simply impossible to support all. So I can think of three options to solve this:
Personally I still prefer option 2. Because for option 1, given how obscure it is to set cgroups rules or udev rules, most people probably will just use root user anyways because it's way simpler, and now it's as insecure as option 3. Option 2 is a middle ground providing safer option for the most popular distro family. |
In the previous dockerfile fix (#82), I made an oopsie and didn't properly set user's permission. When connected to external devices such as an AIOC, it would complain about no permission to access unless I run the service in root.
So this PR fixes the problem by including the user in audio (access audio devices like
/dev/snd), dialout (access serial ports like/dev/ttyUSB*) and plugdev (access removable devices like/dev/hidraw*) group.(More info on system groups: https://wiki.debian.org/SystemGroups)
On Linux systems, the best practice is usually using udev rules to dynamically enable user's permission to access certain devices, because adding user to system groups would mean permission to access all devices in that category. However udev isn't available in docker, and since only target devices are passed in anyways, I think adding user to these groups is reasonable from a security standpoint.
At this moment, including these three groups (audio,dialout,plugdev) is enough for my use case, but I'm not sure if others would need more. I guess we can add more if someone complains.
Also there's a potential problem I stumbled upon in this stackoverflow answer, where devices can be owned by different groups in different distro, so this fix can only guarantee to work on debian family distros, others like arch might break. (uucp group has different gid between arch and debian, so we can't just simply include that.) I would say this is probably good enough for now, let's fix this when someone complains in the future.