Geavanceerd
Zoeken inLabs
Zo zoek je
  • Zoek een taak of een tool (lvm, selinux, @podman); filter op niveau en op boek of cursus.
  • Met een leeg zoekvak toont een filter alleen al de labs — bijvoorbeeld alle moeilijke labs van één cursus.
  • "twee woorden" vindt precies die zin.
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken
Probeer:

Lab 9.1IBM and ISC2 Cybersecurity Specialist, Hoofdstuk 9

Least privilege on a Linux server: roles, sudo rules, ACLs and an access review

Niveau
Gemiddeld
45 min
Machines
a Linux VM where you are root (RHEL family or Ubuntu)
Status
Nog niet begonnen

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

Doel

Turn the access control ideas of the ISC2 course (least privilege, separation of duties, RBAC, DAC vs MAC, account lifecycle) into real settings on one server. Three people need different access: a web developer, a database admin and an auditor. You give each one exactly what the role needs — no more — and finish with an access review that proves it.

Voordat je begint

  • A practice VM where you are root. Make the folders: mkdir -p /srv/web /srv/db-backups /var/log/app.
  • The roles: webdev (change the web files, restart nginx), dba (read and write DB backups, restart the database), auditor (read logs only, change nothing).

Taken

  1. Make the groups webdev, dba, auditors and the users amal (webdev), badr (dba) and carla (auditor). Force a password change at the first login and an account expiry date for the contractor carla in 90 days.
  2. DAC: /srv/web belongs to the group webdev (setgid, others no access); /srv/db-backups to dba (mode 2770).
  3. ACLs: give auditors read-only access to /var/log/app, also for files made later (default ACL).
  4. sudo by role: webdev may only run systemctl reload nginx and systemctl restart nginx; dba only the same for postgresql. No ALL, no shell escapes.
  5. Separation of duties: make sure the auditor can read the logs but can not delete them, and the developers can not read the DB backups.
  6. Lock the account of a person who left (amal changes jobs): lock it, expire it, and keep the files for the hand-over.
  7. Access review: produce a list of every user with a shell, their groups, their sudo rights and their password age.

Controleer je werk

sudo -l -U amal
su - carla -c 'cat /var/log/app/app.log >/dev/null && echo can-read; rm -f /var/log/app/app.log || echo cannot-delete'
su - badr -c 'ls /srv/web' ; su - amal -c 'ls /srv/db-backups'
getfacl /var/log/app
chage -l carla | grep -i "account expires"
passwd -S amal
  • amal may run only the two nginx commands with sudo.
  • carla prints can-read and cannot-delete.
  • badr can not list /srv/web; amal can not list /srv/db-backups (Permission denied).
  • getfacl shows group:auditors:r-x and default:group:auditors:r-x.
  • carla has an expiry date in 90 days; amal shows L / LK (locked).

Hints

Toon de hints

Oplossing

Toon de oplossing
  1. Groups, users, lifecycle.
    groupadd webdev; groupadd dba; groupadd auditors
    useradd -m -G webdev amal; useradd -m -G dba badr; useradd -m -G auditors carla
    for u in amal badr carla; do echo "$u:Start-Pass-2026!" | chpasswd; chage -d 0 $u; done
    chage -E $(date -d '+90 days' +%F) carla
  2. Folders with the right owners (discretionary access control).
    chown root:webdev /srv/web && chmod 2770 /srv/web
    chown root:dba /srv/db-backups && chmod 2770 /srv/db-backups
    chmod 750 /var/log/app && echo "app started" > /var/log/app/app.log && chmod 640 /var/log/app/app.log
  3. Read-only ACL for the auditors, also for new files.
    setfacl -R -m g:auditors:rX /var/log/app
    setfacl -d -m g:auditors:rX /var/log/app
  4. sudo per role.
    /etc/sudoers.d/roles
    Cmnd_Alias NGINX_CTL = /usr/bin/systemctl reload nginx, /usr/bin/systemctl restart nginx
    Cmnd_Alias PG_CTL    = /usr/bin/systemctl reload postgresql, /usr/bin/systemctl restart postgresql
    %webdev ALL=(root) NGINX_CTL
    %dba    ALL=(root) PG_CTL
    visudo -cf /etc/sudoers.d/roles && chmod 440 /etc/sudoers.d/roles
    sudo -l -U amal
  5. Separation of duties is already in place: the auditors have r-x on the directory (they can not delete or create files there), and webdev is not in the group dba.
  6. The leaver.
    usermod -L -s /sbin/nologin amal && chage -E 0 amal
    pkill -KILL -u amal
    tar czf /root/handover-amal-$(date +%F).tgz /home/amal
  7. The access review.
    for u in $(awk -F: '$7 !~ /(nologin|false)$/ {print $1}' /etc/passwd); do echo "== $u: $(id -nG $u) | last pw change: $(chage -l $u | awk -F': ' '/Last password change/ {print $2}')"; sudo -l -U $u 2>/dev/null | sed -n '/may run/,$p' | tail -n +2; done

    Keep the output, sign it with the date, and repeat the review every quarter (and at every role change).

Mijn notities

Nog geen notities.

Lessen voor dit lab

Commando's in dit lab