8 Eylül 2016 Perşembe

setcap komutu

Giriş
setcap komutu ile belirtilen ayarlar dosya ile birlikte saklanıyor. Yani kalıcılar. Açıklaması şöyle
Since kernel 2.6.24, the kernel supports associating capability sets with an executable file using setcap(8). The file capability sets are stored in an extended attribute (see setxattr(2)) named security.capability.
cap_net_bind
Uygulamanın privileged port'lara bağlanabilmesini sağlar. Açıklaması şöyle
... CAP_NET_BIND_SERVICE which is about binding to a privileged port (<1024).
Açıklaması şöyle. Yani bu imtiyaz ile artık uygulamanın root olmasına gerek yok
Nowadays, users are recommended to set CAP_NET_BIND_SERVICE on the server binary and avoid root altogether
Açıklaması şöyle. Privileged port üst sınırı değiştirilebilir.
The Linux kernel tuning parameter net.ipv4.ip_unprivileged_port_start defines which ports are privileged. All ports between 0 and net.ipv4.ip_unprivileged_port_start are privileged.

Privileged ports can only used by processes either started by the root user or with root privileges or by processes that are assigned the capability CAP_NET_BIND_SERVICE with for example sudo setcap cap_net_bind_service=ep /path/bin/application

All other ports are unprivileged and can be used by any user, as longs the ports are not already in use.
Örnek
Şöyle yaparız
sudo /sbin/setcap 'cap_net_bind_service=ep' /usr/lib/jvm/java-8-openjdk/jre/bin/java
Örnek
Şöyle yaparız
setcap 'cap_net_bind_service=+ep' /path/to/program
cap_net_raw
Şöyle yaparız.
setcap cap_net_raw=eip myapp
cap_sys_chroot
Şöyle yaparız
sudo setcap cap_sys_chroot+ep /usr/sbin/chroot 
cap_sys_nice
Şöyle yaparız.
setcap cap_sys_nice myapp

Hiç yorum yok:

Yorum Gönder