mirror of
https://github.com/libracoder/kiri.git
synced 2026-12-06 23:32:31 +09:00
* Linux: enforce SELinux container_t + MCS confinement, :z/:Z relabelling, and --security-opt label=...
On Linux hosts with SELinux active (`/sys/fs/selinux` `SELINUX_MAGIC`) and `container-selinux` installed (`/etc/selinux/<type>/contexts/lxc_contexts`), confine containers and `docker exec` processes under `container_t` with a unique reference-counted MCS category pair (`s0:cX,cY`), label container overlayfs roots, `/dev`, `/dev/pts`, `/dev/shm`, masked `tmpfs` directories, and `--tmpfs` mounts via `context="<mount_label>"`, label `/etc/{hosts,resolv.conf,hostname}`, shared `IpcMode::Shareable` shm, and local volumes with `container_file_t:s0`, and transition threads via `/proc/thread-self/attr/selinux/exec` (`current` for `--init` PID 1) after verifying `PROC_SUPER_MAGIC`.
Support `--security-opt label=disable|user:...|role:...|type:...|level:...|filetype:...` (`label=` and `label:`) with strict character validation preventing `context="..."` mount-option injection, persist `process_label` and `mount_label` on `Spec` for `GET /containers/{id}/json` (`ProcessLabel`, `MountLabel`) and restarts, expose `name=selinux` in `GET /info` `SecurityOptions`, support `:z` and `:Z` bind-mount relabelling via an iterative non-symlink-following `relabel_tree` with top-level system path guards while rejecting `:z,Z`, degrade cleanly when SELinux or `container-selinux` is absent, and add `Recommends: container-selinux` to `packaging/linux/rpm/kiri.spec`.
* Linux: gate SELinux relabel path guards on active confinement
Match Docker 29 and opencontainers/selinux semantics so :z and :Z remain a non-breaking no-op on non-SELinux hosts (macOS, Windows/WSL 2, Ubuntu, Debian) and when MountLabel is empty (--privileged or --security-opt label=disable), while enforcing excludePaths (including /etc/passwd, /etc/pki, /etc/shadow, /media, /srv, /var/log) and bottom-up directory relabelling whenever SELinux confinement is active.