Previously, running dockerd-rootless.sh on SELinux-enabled hosts
was failing with "can't open lock file /run/xtables.lock: Permission denied" error.
(issue 41230).
This commit avoids hitting the error by relabeling /run in the RootlessKit child.
The actual /run on the parent is unaffected.
https://github.com/containers/podman/blob/e6fc34b71aa9d876b1218efe90e14f8b912b0603/libpod/networking_linux.go#L396-L401
Tested on Fedora 34
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
(cherry picked from commit cdaf82ba3fe97eda242488ec70f400b9b345e16a)
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
| ... | ... |
@@ -84,6 +84,12 @@ if [ -z $_DOCKERD_ROOTLESS_CHILD ]; then |
| 84 | 84 |
echo "This script must be executed as a non-privileged user" |
| 85 | 85 |
exit 1 |
| 86 | 86 |
fi |
| 87 |
+ # `selinuxenabled` always returns false in RootlessKit child, so we execute `selinuxenabled` in the parent. |
|
| 88 |
+ # https://github.com/rootless-containers/rootlesskit/issues/94 |
|
| 89 |
+ if command -v selinuxenabled > /dev/null 2>&1 && selinuxenabled; then |
|
| 90 |
+ _DOCKERD_ROOTLESS_SELINUX=1 |
|
| 91 |
+ export _DOCKERD_ROOTLESS_SELINUX |
|
| 92 |
+ fi |
|
| 87 | 93 |
# Re-exec the script via RootlessKit, so as to create unprivileged {user,mount,network} namespaces.
|
| 88 | 94 |
# |
| 89 | 95 |
# --copy-up allows removing/creating files in the directories by creating tmpfs and symlinks |
| ... | ... |
@@ -105,5 +111,12 @@ else |
| 105 | 105 |
# remove the symlinks for the existing files in the parent namespace if any, |
| 106 | 106 |
# so that we can create our own files in our mount namespace. |
| 107 | 107 |
rm -f /run/docker /run/containerd /run/xtables.lock |
| 108 |
+ |
|
| 109 |
+ if [ -n "$_DOCKERD_ROOTLESS_SELINUX" ]; then |
|
| 110 |
+ # iptables requires /run in the child to be relabeled. The actual /run in the parent is unaffected. |
|
| 111 |
+ # https://github.com/containers/podman/blob/e6fc34b71aa9d876b1218efe90e14f8b912b0603/libpod/networking_linux.go#L396-L401 |
|
| 112 |
+ # https://github.com/moby/moby/issues/41230 |
|
| 113 |
+ chcon system_u:object_r:iptables_var_run_t:s0 /run |
|
| 114 |
+ fi |
|
| 108 | 115 |
exec dockerd $@ |
| 109 | 116 |
fi |