Topic 332: Host Security
332.3 Resource Control (weight: 3)
Weight 3 Description Candidates should be able to restrict the resources services and programs can consume.
Key Knowledge Areas:
Understand and configure ulimits
Understand cgroups, including classes, limits and accounting
Manage cgroups and process cgroup association
Understand systemd slices, scopes and services
Use systemd units to limit the system resources processes can consume
Awareness of cgmanager and libcgroup utilities
Partial list of the used files, terms and utilities:
ulimit
/etc/security/limits.conf
pam_limits.so
/sys/fs/group/
/proc/cgroups
systemd-cgls
systemd-cgtop
limits
El archivo /etc/security/limits.conf
proporciona la configuración para el módulo PAM pam_limits.so
, que establece límites en los recursos del sistema
las limitaciones hard solo las podrá escribir el usuario root desde el archivo de configuración, las limitaciones soft las podrá modificar el usuario pero nunca superando los limites que impone una linea hard.
las configuraciones en el directorio /etc/security/limits.d/*.conf
se aplican por orden alfabetico sobrescribiendo las concidencias anteriores
domain pueden ser tipo: user, @grupo, * por defecto, min_uid:max:uid, @min_gid:max:gid
type:
- soft: es el valor predeterminado, el usuario podra modificar el valor hasta llegar al valor de hard
- hard: el usuario no podra superar nunca los valores incluidos
-
para hacer cumplir los límites de recursos soft y hard.
item:
- core - limits the core file size (KB)
- data - max data size (KB)
- fsize - maximum filesize (KB)
- memlock - max locked-in-memory address space (KB)
- nofile - max number of open file descriptors
- rss - max resident set size (KB)
- stack - max stack size (KB)
- cpu - max CPU time (MIN)
- nproc - max number of processes
- as - address space limit (KB)
- maxlogins - max number of logins for this user
- maxsyslogins - max number of logins on the system
- priority - the priority to run user process with
- locks - max number of file locks the user can hold
- sigpending - max number of pending signals
- msgqueue - max memory used by POSIX message queues (bytes)
- nice - max nice priority allowed to raise to values: [-20, 19]
- rtprio - max realtime priority
Ejemplo de sintaxis en archivo /etc/security/limits.conf
#<domain> <type> <item>
@student hard maxlogins 4
ftp hard nproc 0
:123 hard cpu 5000
@500: soft cpu 10000
600:700 hard locks 10
La orden ulimit
sirve para poner límites a nivel de todo el sistema
ulimit # limites blandos del usuario actual
ulimit -a # ver los limites del sistema blandos
ulimit -aS # igual al anterior
ulimit -aH # ver limites duros actuales
ulimit -f 500 # cambiar valor soft y hard de tamañom max ficheros
ulimit -Sf 500
ulimit -Hf 500
ulimit -s unlimited
-b # tamaño máximo de búfer de socket
-f # tamaño máximo de archivos escritor por el shell
-l # tamaño máximo que se puede bloquear en memoria
-v # cantidad máxima de memoria virtual
-u # número máximo de procesos disponibles para el usuario
-m # maximo tamaño mmemoria disponibles para el usuario