I launched named service with unprivileged account on my debian with:
useradd named
chown -R named:named /etc/bind/
named -u named
which is supported and it works. But i started to wonder how can normal user "named" listen on port 53 without being a root?
What I checked already on my debian:
please let me know how does it work as i cant listen on privileged port on normal account in my debian.
With setcap
, it's possible to add capabilities like CAP_NET_BIND
to be able to bind on port 53 as user.
That's what is used in bind9
aka named
:
git clone https://github.com/isc-projects/bind9.git
cd bind9
ack CAP_NET
gives:
bin/named/os.c
152: SET_CAP(CAP_NET_BIND_SERVICE);
213: SET_CAP(CAP_NET_BIND_SERVICE);
from man 7 capabilities
:
CAP_NET_BIND_SERVICE
Bind a socket to Internet domain privileged ports (port numbers less than 1024).
Linux kernel capabilities are a feature of the operating system that allow the traditional superuser (root) privileges to be broken down into smaller, more manageable units, which can be assigned individually to processes. Instead of granting a process all the privileges by giving it the UID (User ID) 0 (root), you can assign only the specific capabilities it needs to operate properly. This reduces the security risk associated with running processes with full superuser privileges.
The Linux kernel divides privileges into a set of distinct capabilities, each controlling a specific aspect of the system. For example, the capability CAP_NET_BIND_SERVICE
allows a process to bind to a network port numbered below 1024, and CAP_DAC_OVERRIDE
allows overriding discretionary access controls like file permissions.
Capabilities can be assigned in several ways:
setcap
or by a init system that supports capability assignments.setcap
, you can assign capabilities directly to an executable file. When the file is executed, the process inherits the assigned capabilities.execve
system calls, making it easier to use capabilities in environments where binaries need to maintain their privileges after being launched by non-privileged users.Capabilities thus provide a more granular and secure method of privilege management on modern Linux systems, allowing for better control and limitation of process rights.