brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: capsh shows which capabilities a process has beyond normal permissions

Permissions
~/tips/tip-permissions-capsh-print

capsh --print

Lists the Linux capabilities of the current shell, including inside a container.

Root is not all or nothing on Linux. Its powers are split into capabilities, and a process can have some of them without being root, or be root without most of them. capsh --print shows the set you are working with.

Run it in any shell, or inside a container:

capsh --print
docker run --rm --cap-drop ALL --cap-add NET_BIND_SERVICE IMAGE capsh --print | head -2

The second command runs any image that has capsh with only one capability; its output shows just cap_net_bind_service. The Current: line lists the capabilities in effect, like cap_chown, cap_net_bind_service or cap_sys_admin. Bounding set is the maximum this process and its children can ever get. The Securebits line also shows whether no-new-privs is set.

I find this explains a lot of container puzzles. In a default Docker container as root, the list is short. There’s cap_chown, cap_dac_override and cap_net_bind_service, but no cap_sys_admin or cap_net_admin. That’s why some things fail in a container even as root: the permission bits say yes, but a missing capability says no.

To read the same information for another process, look at its status file and decode it:

grep Cap /proc/1234/status
capsh --decode=00000000a80425fb

On Ubuntu and Debian, capsh comes in the libcap2-bin package. Many slim container images don’t have it, so the /proc method is the one that works everywhere.

Further reading: capsh(1) manual page, capabilities(7) manual page

More Permissions tips sudo su -s /bin/bash www-data sudo setfacl -R -d -m g:media:rwX /srv/media sudo cp -r /srv/site /srv/site.r ls -ln /srv/data newgrp media All Permissions tips (30) All topics

Link