LFCS 4.4: Application and service constraints
Open-file limits for a service, what a running program uses, cgroup caps, login limits, and a privileged port for a non-root service.
Before you start
The lab installs nginx (running, on port 80) and lsof, and creates user
alice (password Lab-Pass-1). It adds heartbeat.service, a small
looping service like the one you wrote in 4.2, and webapp.service, which
should serve /srv/webapp on port 81 as system user webapp but fails to
start. Write answers to the files in /root/lab-answers/.
Tasks
- Give nginx a limit of 65536 open files that survives package updates and reboots.
- List every file, port and library the running nginx is using, and save
the list in
/root/lab-answers/2(command output is fine). - Cap
heartbeat.serviceat 200 MiB of memory and 20% of one CPU. - Give user
alicea hard limit of 200 processes. - Make
webapp.servicerun as the non-root userwebappbut listen on port 81, a privileged port (nginx already has port 80), also after a reboot.
Hints
systemctl edit nginx,LimitNOFILE=,grep 'open files' /proc/$(pgrep -o nginx)/limits.lsof -p,ss -tlnp,ldd,ls -l /proc/PID/fd.systemctl set-property,MemoryMax=,CPUQuota=,systemctl show -p MemoryMax -p CPUQuotaPerSecUSec./etc/security/limits.d/;ulimit -Huin a new login as alice (su - alice).journalctl -u webapp,AmbientCapabilities=CAP_NET_BIND_SERVICE,ss -tlnp 'sport = :81'.