tech:notes_linux_kernel_namespaces_espace_de_noms
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_linux_kernel_namespaces_espace_de_noms [2025/10/03 10:15] – Jean-Baptiste | tech:notes_linux_kernel_namespaces_espace_de_noms [2026/06/07 19:12] (Version actuelle) – modification externe 127.0.0.1 | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| + | < | ||
| + | {{tag> | ||
| + | |||
| + | # Notes Linux kernel namespaces espace de noms | ||
| + | |||
| + | ** Brouillon** | ||
| + | |||
| + | Voir : | ||
| + | * [[Network Namespaces - netns - /etc/hosts que pour une appli spécifique]] | ||
| + | * [Manage containers in namespaces by using nsenter](https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | |||
| + | |||
| + | Sécurité - échappement : | ||
| + | * https:// | ||
| + | |||
| + | |||
| + | ## Commandes unshare nsenter | ||
| + | |||
| + | Voir : | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | |||
| + | |||
| + | ~~~bash | ||
| + | yum install util-linux | ||
| + | ~~~ | ||
| + | |||
| + | Voir : | ||
| + | * unshare | ||
| + | * share | ||
| + | * runc | ||
| + | * / | ||
| + | |||
| + | ~~~ | ||
| + | jb@vmdeb1: | ||
| + | jb@vmdeb1: | ||
| + | root@vmdeb1:/ | ||
| + | UID PID PPID C STIME TTY TIME CMD | ||
| + | root | ||
| + | root | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | unshare -m -u -i -n -p -f --mount-proc bash | ||
| + | sudo $(which runc) run test1 | ||
| + | |||
| + | ip netns | ||
| + | lsns | ||
| + | nsenter | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | Trouver les processus présents dans des namespaces | ||
| + | ~~~bash | ||
| + | dirname $(grep -l libpod / | ||
| + | |||
| + | lsns -t pid | ||
| + | |||
| + | sudo ps --no-headers -e -o pidns, | ||
| + | ~~~ | ||
| + | |||
| + | is-container is-docker | ||
| + | ~~~bash | ||
| + | grep -Eq " | ||
| + | grep -Eq " | ||
| + | ~~~ | ||
| + | |||
| + | Voir / | ||
| + | |||
| + | |||
| + | paramètre noyau | ||
| + | `user_namespace.enable=1` | ||
| + | |||
| + | Red Hat / CentOS | ||
| + | ~~~bash | ||
| + | #grubby --args=" | ||
| + | grubby --args=" | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | cat / | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | |||
| + | ## Docker userns-remap namespace | ||
| + | |||
| + | Voir : | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | |||
| + | |||
| + | |||
| + | ## userns-remap=utilisateur | ||
| + | |||
| + | `/ | ||
| + | ~~~javascript | ||
| + | { | ||
| + | " | ||
| + | } | ||
| + | ~~~ | ||
| + | |||
| + | " | ||
| + | |||
| + | Pour ` / | ||
| + | |||
| + | `user: | ||
| + | |||
| + | Voir `/ | ||
| + | |||
| + | La valeur du count doit logiquement être supérieur ou égale à l'UID max du conteneur (normalement l' | ||
| + | ~~~bash | ||
| + | docker run -ti --rm alpine cat /etc/passwd | cut -d: -f 3 | sort -n | tail -1 | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | Autres | ||
| + | |||
| + | ~~~bash | ||
| + | sudo usermod --add-subuids 10000-75535 USERNAME | ||
| + | sudo usermod --add-subgids 10000-75535 USERNAME | ||
| + | ~~~ | ||
| + | |||
| + | `/ | ||
| + | ~~~ | ||
| + | plop:1000:1 | ||
| + | plop: | ||
| + | ~~~ | ||
| + | |||
| + | `/ | ||
| + | ~~~ | ||
| + | plop:982:1 | ||
| + | plop: | ||
| + | ~~~ | ||
| + | |||
| + | La 1ere ligne : tous les fichiers crées par root appartiendrons à l'UID 1000 et au GID 982 | ||
| + | |||
| + | `/ | ||
| + | |||
| + | Exemple | ||
| + | ~~~bash | ||
| + | sudo usermod --add-subuids 200000-265535 --add-subgids 200000-265535 demisto | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | Voir `podman system migrate` | ||
| + | |||
| + | |||
| + | |||
| + | ## kernel.unprivileged_userns_clone | ||
| + | |||
| + | ~~~bash | ||
| + | echo kernel.unprivileged_userns_clone = 1 | sudo tee / | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | |||
| + | ## userns-remap=default dockremap | ||
| + | |||
| + | |||
| + | `/ | ||
| + | ~~~javascript | ||
| + | { | ||
| + | " | ||
| + | } | ||
| + | ~~~ | ||
| + | Si vous définisez le champ `userns-remap` à `default` Docker créera lui-même l’utilisateur `dockremap` sur l' | ||
| + | |||
| + | `/ | ||
| + | ~~~ | ||
| + | dockremap: | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | `/ | ||
| + | ~~~ | ||
| + | dockremap: | ||
| + | ~~~ | ||
| + | |||
| + | `/ | ||
| + | ~~~ | ||
| + | dockremap: | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ## Exemple process Dockers | ||
| + | |||
| + | ~~~ | ||
| + | $ sudo lsns -t pid | ||
| + | NS TYPE NPROCS | ||
| + | 4026531836 pid | ||
| + | 4026532223 pid | ||
| + | 4026532287 pid 2 21609 root / | ||
| + | 4026532298 pid 1 20919 root / | ||
| + | 4026532410 pid 3 31582 root tini -g -- start-notebook.sh --NotebookApp.token=` --NotebookApp.password=` | ||
| + | 4026532477 pid | ||
| + | |||
| + | $ pstree -p 1717 | ||
| + | sh(1717)───sshd(14400) | ||
| + | |||
| + | $ lsns 4026532477 | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ~~~bash | ||
| + | ps -e -o pidns, | ||
| + | ~~~ | ||
| + | |||
| + | ~~~ | ||
| + | # lsns -t pid | ||
| + | NS TYPE NPROCS | ||
| + | 4026531836 pid | ||
| + | 4026533558 pid | ||
| + | 4026533561 pid | ||
| + | 4026533565 pid | ||
| + | ~~~ | ||
| + | |||
| + | ~~~ | ||
| + | # lsns 4026533558 | ||
| + | PID PPID USER | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | Voir aussi la commande **systemd-cgtop** | ||
| + | |||
| + | ## nsenter | ||
| + | |||
| + | ~~~bash | ||
| + | nerdctl inspect --format {{.State.Pid}} kind-control-plane | ||
| + | nsenter --target 6491 --mount --uts --ipc --net --pid | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ## Réseau | ||
| + | |||
| + | Voir : | ||
| + | * https:// | ||
| + | |||
| + | ~~~bash | ||
| + | podman unshare --rootless-netns ip addr | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ## FS Mount | ||
| + | |||
| + | ~~~bash | ||
| + | man 7 mount_namespaces | ||
| + | lsns -t mnt | ||
| + | findmnt -o TARGET, | ||
| + | ~~~ | ||
| + | |||
| + | Voir : | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * http:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * http:// | ||
| + | * https:// | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | ## Autres | ||
| + | |||
| + | ~~~bash | ||
| + | dockerd --userns-remap=" | ||
| + | ~~~ | ||
| + | |||
| + | To disable user namespaces for a specific container, add the `--userns=host` flag | ||
| + | |||
| + | ~~~bash | ||
| + | ls -l / | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ## Pb | ||
| + | |||
| + | ### Err unshare failed: Operation not permitted | ||
| + | |||
| + | ~~~ | ||
| + | $ unshare -f --mount-proc -m bash | ||
| + | unshare: unshare failed: Operation not permitted | ||
| + | ~~~ | ||
| + | |||
| + | Solution | ||
| + | ~~~ | ||
| + | $ unshare -U -r -m --mount-proc -f -p | ||
| + | root@vivabelo: | ||
| + | ~~~ | ||
| + | |||
