tech:notes_selinux
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| tech:notes_selinux [2025/09/26 23:02] – Jean-Baptiste | tech:notes_selinux [2026/07/02 10:54] (Version actuelle) – Jean-Baptiste | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| + | < | ||
| + | {{tag> | ||
| + | |||
| + | # Notes SELinux | ||
| + | |||
| + | Voir : | ||
| + | * SELinux coloring book | ||
| + | * SELinux notebook | ||
| + | * `/ | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * http:// | ||
| + | * http:// | ||
| + | * ausearch | ||
| + | * SEtroubleshoot | ||
| + | * https:// | ||
| + | * Ansible https:// | ||
| + | * https:// | ||
| + | * setroubleshootd | ||
| + | * system-config-selinux | ||
| + | * https:// | ||
| + | |||
| + | |||
| + | ## Définition | ||
| + | |||
| + | Security-Enhanced Linux (SELinux) is a Linux kernel mechanism that label sever y process and every file system object on the system. A SELinux policy defines the rules on how labeled processes interact with label objects. | ||
| + | Source : https:// | ||
| + | |||
| + | ## Autoriser avec audit2allow | ||
| + | |||
| + | |||
| + | ~~~bash | ||
| + | sudo cat / | ||
| + | sudo cat / | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | / | ||
| + | ~~~ | ||
| + | |||
| + | Copier le contexte par défaut d'une arborescence | ||
| + | ~~~bash | ||
| + | # Example - podman - additional image stores | ||
| + | sudo semanage fcontext -a -e / | ||
| + | sudo restorecon -r / | ||
| + | ~~~ | ||
| + | |||
| + | ## Restaurer les autorisations SELinux | ||
| + | |||
| + | ~~~bash | ||
| + | # Voir les différences | ||
| + | restorecon -nv /etc/passwd | ||
| + | |||
| + | # Les remettre | ||
| + | restorecon -v /etc/passwd | ||
| + | |||
| + | # Exemple | ||
| + | restorecon -v / | ||
| + | restorecon -v / | ||
| + | restorecon -v /etc/hosts | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | |||
| + | Au démarrage du système | ||
| + | ~~~bash | ||
| + | touch / | ||
| + | ~~~ | ||
| + | |||
| + | Réétiquetés les fichiers lors du prochain redémarrage \\ | ||
| + | Cela crée le fichier `/ | ||
| + | ~~~bash | ||
| + | fixfiles -F onboot | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | Passez toujours en mode permissif avant d' | ||
| + | |||
| + | Voir aussi `/ | ||
| + | |||
| + | |||
| + | |||
| + | ## En vrac | ||
| + | |||
| + | ~~~bash | ||
| + | ls -z | ||
| + | ps -eZ | ||
| + | |||
| + | sestatus | ||
| + | |||
| + | setenforce 0 | ||
| + | getenforce | ||
| + | semanage login -l | ||
| + | chcon | ||
| + | seinfo | ||
| + | |||
| + | audit2allow | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | dnf install -y container-selinux | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | semodule --list-modules=full | ||
| + | |||
| + | chcon system_u: | ||
| + | chcon -t sudo_exec_t / | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | grep -w ' | ||
| + | ~~~ | ||
| + | |||
| + | Serveur Web | ||
| + | ~~~bash | ||
| + | setsebool -P httpd_can_network_connect 1 | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | ## Pb Exemple | ||
| + | |||
| + | Err `Permission denied` | ||
| + | |||
| + | Before: | ||
| + | ~~~ | ||
| + | # ls -lZ / | ||
| + | -rwxrwxrwx. 1 app_plop appgrp unconfined_u: | ||
| + | ~~~ | ||
| + | |||
| + | After: | ||
| + | ~~~ | ||
| + | # ls -lZ / | ||
| + | -rwxrwxrwx. 1 app_plop appgrp unconfined_u: | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | |||
| + | ### Service SystemD | ||
| + | |||
| + | ~~~bash | ||
| + | chmod 640 / | ||
| + | restorecon -v / | ||
| + | systemctl daemon-reload | ||
| + | chcon system_u: | ||
| + | chcon system_u: | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ## Containers | ||
| + | |||
| + | |||
| + | |||
| + | ~~~python | ||
| + | DEFAULT_CONTAINER_RUN_OPTIONS = [' | ||
| + | ~~~ | ||
| + | |||
| + | Voir : https:// | ||
| + | |||
| + | |||
| + | ### Autres | ||
| + | |||
| + | Checking / | ||
| + | ~~~bash | ||
| + | sudo semanage fcontext --add --type container_ro_file_t '/ | ||
| + | sudo semanage fcontext --add --type container_ro_file_t '/ | ||
| + | sudo semanage fcontext --add --type container_ro_file_t '/ | ||
| + | sudo semanage fcontext --add --type container_ro_file_t '/ | ||
| + | sudo semanage fcontext --add --type container_ro_file_t '/ | ||
| + | sudo semanage fcontext --add --type container_ro_file_t '/ | ||
| + | sudo semanage fcontext --add --type container_file_t | ||
| + | ~~~ | ||
| + | |||
| + | then, reapply them to the system: | ||
| + | ~~~bash | ||
| + | sudo restorecon -RvF / | ||
| + | ~~~ | ||
| + | |||
| + | Voir https:// | ||
| + | |||
| + | |||
| + | ## Autres | ||
| + | |||
| + | Voir : | ||
| + | * sealert | ||
| + | |||
| + | ~~~bash | ||
| + | ausearch -c ' | ||
| + | semodule -X 300 -i my-ssh.pp | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ~~~ | ||
| + | Dec 11 18:23:34 srv1 setroubleshoot[13728]: | ||
| + | sur le fichier / | ||
| + | Pour des messages SELinux exhaustifs, lancez sealert -l 4c092563-ff9e-461c-a202-f8b30a83315f | ||
| + | Dec 11 18:23:34 srv1 setroubleshoot[13728]: | ||
| + | sur le fichier / | ||
| + | ***** Le greffon restorecon (54.2 de confiance) suggère | ||
| + | Si vous souhaitez corriger l' | ||
| + | Alors vous pouvez lancer restorecon. La tentative d’accès pourrait avoir été stoppée due à des permissions insuffisantes d’accès au dossier parent, | ||
| + | auquel cas essayez de changer la commande suivante en conséquence. | ||
| + | Faire # / | ||
| + | ***** Le greffon file (16.6 de confiance) suggère | ||
| + | Ceci est dû à la création d'un nouveau système de fichiers. | ||
| + | Alors vous devez y ajouter des étiquettes. | ||
| + | Faire / | ||
| + | ***** Le greffon file (16.6 de confiance) suggère | ||
| + | Si vous pensez que ceci est dû à une machine mal étiquetée. Alors vous devez complètement ré-étiqueter. | ||
| + | Faire touch / | ||
| + | ***** Le greffon catchall_labels (3.18 de confiance) suggère | ||
| + | Si vous souhaitez autoriser bash à accéder à read sur libc.so.6 file | ||
| + | Alors l' | ||
| + | # semanage fcontext -a -t FILE_TYPE '/ | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ## SELinux PAM | ||
| + | |||
| + | `/ | ||
| + | ~~~ | ||
| + | # | ||
| + | ~~~ | ||
