Retour au cours

securisation des services systemd

Réduisez l’impact d’un service compromis en limitant ses permissions.

objectifs d’apprentissage

  • Activer ProtectSystem/PrivateTmp.
  • Limiter les capabilities.
  • Lire les logs d’accès refusé.

prérequis

  • Accès root.
  • Service de test.

notions clés

  • ProtectSystem=full.
  • NoNewPrivileges=yes.
  • CapabilityBoundingSet=.

démonstration guidée

étape 1

Ajout d’options de sandboxing à une unit.

sudo mkdir -p /etc/systemd/system/hello.service.d
printf '%s
' '[Service]' 'ProtectSystem=full' 'PrivateTmp=yes' 'NoNewPrivileges=yes' | sudo tee /etc/systemd/system/hello.service.d/hardening.conf >/dev/null
sudo systemctl daemon-reload && sudo systemctl restart hello.service || true

étape 2

Limiter les capabilities.

printf '%s
' '[Service]' 'CapabilityBoundingSet=' 'AmbientCapabilities=' | sudo tee -a /etc/systemd/system/hello.service.d/hardening.conf >/dev/null
sudo systemctl daemon-reload && sudo systemctl restart hello.service || true

exercice

Ajoutez ProtectHome=read-only et testez l’accès au $HOME depuis le service.

correction

Option supplémentaire.

printf '%s
' '[Service]' 'ProtectHome=read-only' | sudo tee -a /etc/systemd/system/hello.service.d/hardening.conf >/dev/null
sudo systemctl daemon-reload && sudo systemctl restart hello.service || true

quiz éclair

  1. Quelle option empêche l’élévation de privilèges ?
  • a) NoNewPrivileges=yes
  • b) PrivateTmp=yes
  • c) ProtectSystem=full

ressources

Sujets abordés