====== Apparmor ====== ===== Liens ===== * [[http://wiki.apparmor.net/|Wiki Apparmor]] * [[https://www.suse.com/documentation/sles-12/singlehtml/book_security/book_security.html#part.apparmor|SLES12]] * [[https://debian-handbook.info/browse/fr-FR/stable/sect.apparmor.html|Exemples]] ===== Description ===== AppArmor permet à l'administrateur système d'associer à chaque programme un profil de sécurité qui restreint ses accès au système d'exploitation. Il complète le traditionnel modèle d'Unix du contrôle d'accès discrétionnaire (DAC, Discretionary access control) en permettant d'utiliser le contrôle d'accès obligatoire (MAC, Mandatory access control). ====== Type de permission ====== * [[http://wiki.apparmor.net/index.php/AppArmor_Core_Policy_Reference|Exemple site officiel]] * **r** : Read mode * **w** : Write mode (mutually exclusive to a) * **a** : Append mode (mutually exclusive to w) * **k** : File locking mode * **x** : Execute * **ux** : Execute unconfined (preserve environment) -- WARNING: should only be used in very special cases * **Ux** : Execute unconfined (scrub the environment) * **px** : Execute under a specific profile (preserve the environment) -- WARNING: should only be used in special cases * **Px** : Execute under a specific profile (scrub the environment) * **pix** : as px but fallback to inheriting the current profile if the target profile is not found * **Pix** : as Px but fallback to inheriting the current profile if the target profile is not found * **pux** : as px but fallback to executing unconfined if the target profile is not found * **Pux** : as Px but fallback to executing unconfined if the target profile is not found * **ix** : Execute and inherit the current profile * **cx** : Execute and transition to a child profile (preserve the environment) * **Cx** : Execute and transition to a child profile (scrub the environment) * **cix** : as cx but fallback to inheriting the current profile if the target profile is not found * **Cix** : as Cx but fallback to inheriting the current profile if the target profile is not found * **cux** : as cx but fallback to executing unconfined if the target profile is not found * **Cux** : as Cx but fallback to executing unconfined if the target profile is not found * **m** : Allow PROT_EXEC with mmap(2) calls * **l** : Link mode * **audit** : force logging * **deny** : explicitly deny, without logging * **audit deny** : combination to explicitly deny, but log * **quiet** : clears audit qualifier off of rules. Does it take precedence over audit like deny over allow /profile { /path/to/file* r, # allow read to /path/to/file* /path/to/file1 w, # allow write to /path/to/file1 deny /path/to/file2, w, # deny write to /path/to/file2, without logging audit /path/to/file3 w, # allow write to /path/to/file3, with logging audit deny /path/to/file4 r, # deny read to /path/to/file4, with logging } * **alias** : crée un mapping alias /home/ -> /mnt/users/ * **owner** : autorise seulement si le propriétaire de la tache est le même que celui du fichier : owner /foo r, owner=fred owner=1001 owner=(fred) owner=(fred george) owner=(fred 1001) * **Child profile (cx)** : /parent/profile { /path/to/child1 cx -> child1, /path/to/child2 cx, /path/to/* cx, # for * matching child3 will transition to child3, # child4, child5, ... will transition to /path/to/child* # if matching child profile does not exist will fail /another/path/to/* cx -> child1, # send all matching execs to child1 profile child1 { } profile /path/to/child2 { } profile /path/to/child3 { } # generic fall back profile profile /path/to/child* { } } ====== Activer apparmor ====== $ chkconfig boot.apparmor on $ chkconfig boot.apparmor boot.apparmor on ====== Commandes ====== ===== aa-status ===== Voir le status de apparmor : $ aa-status La commande //**apparmor_status**// permet de faire la même chose. ===== aa-enforce ===== Activer un profile existant, par exemple firefox : $ aa-enforce firefox Ou $ aa-enforce /usr/bin/firefox Ou charger tous les profils : $ aa-enforce /etc/apparmor.d/* ===== aa-complain ===== Permet de ne pas bloquer les accès mais log toutes les violation de la politique : s'utilise de la même manière que [[#aa-enforce]]. Par défaut les profils sont en mode **enforced**. $ aa-complain firefox ===== aa-genprof ===== AppArmor détectera automatiquement les accès faits par l'application, générera le fichier profil approprié et le placera dans le répertoire ''/etc/apparmor.d''. Attention ce mode est fait pour les process à durée de vite limité, pour les daemon il faut utiliser [[#aa-autodep]] ===== aa-autodep ===== On crée d'abord un profil temporaire à l'aide de la commande **//aa-autodep//**. On laisse tourner le processus à confiner durant le temps nécessaire, puis on corrige le fichier de profil à l'aide des messages laissés dans les fichiers log, grâce à la commande [[#aa-logprof]]. Au besoin, on continue à laisser tourner le processus et on relance la commande aa-logprof, jusqu'à ce que le fichier de profil soit adéquat. On peut alors placer ce fichier en mode ''enforced''. ===== aa-logprof ===== * Pour voir les fichiers que aa-logprof scan : $ grep logfiles /etc/apparmor/logprof.conf logfiles = /var/log/audit/audit.log /var/log/syslog /var/log/messages * Ajoute ce qui a été interdit dans les fichiers aux règles adéquates : $ aa-logprof * Ajoute ce qui correspond à ''17:04:21'' aux règles adéquates : $ aa-logprof -m "17:04:21" * Ajoute ce qu'il y a dans le fichier gigix : $ grep firefox /var/log/audit/audit.log > gigix $ aa-logprof -f gigix ===== apparmor_parser ===== * Voir ce qu'il y a de charger dans le profil apache2 : $ apparmor_parser -Q --debug /etc/apparmor.d/usr.sbin.apache2 $ apparmor_parser -p /etc/apparmor.d/usr.sbin.apache2 * Recharger le profile ping : $ apparmor_parser -r /etc/apparmor.d/bin.ping