Skip to content

dockerd-rootless.sh: avoid /run/xtables.lock EACCES on SELinux hosts#42199

Merged
cpuguy83 merged 1 commit intomoby:masterfrom
AkihiroSuda:rootless-selinux-xtables-workaround
Jun 3, 2021
Merged

dockerd-rootless.sh: avoid /run/xtables.lock EACCES on SELinux hosts#42199
cpuguy83 merged 1 commit intomoby:masterfrom
AkihiroSuda:rootless-selinux-xtables-workaround

Conversation

@AkihiroSuda
Copy link
Member

@AkihiroSuda AkihiroSuda commented Mar 25, 2021

- What I did
Fix #41230

- How I did it

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

- How to verify it

  • Install Rootless Docker to Fedora 34, without disabling SELinux
  • Make sure the daemon starts up without can't open lock file /run/xtables.lock: Permission denied error

- Description for the changelog

dockerd-rootless.sh: avoid can't open lock file /run/xtables.lock: Permission denied errorSELinux hosts

- A picture of a cute animal (not mandatory but encouraged)
🐧

Copy link
Member Author

@AkihiroSuda AkihiroSuda Mar 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: I also tried /run/dockerd-rootless-xtables.lock, $(mktemp -d /tmp/dir.XXXXXXXX)/xtables.lock, ${ROOTLESSKIT_STATE_DIR}/xtables.lock, $HOME/.docker/run/xtables.lock, but none of them could satisfy SELinux😅

It seems only a file under /tmp can work.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@giuseppe Do you happen to know whether this is by design?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no idea :) what error do you see?

Could you force a system_u:object_r:iptables_var_run_t:s0 label on the file?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't open lock file /run/user/1000/dockerd-rootless-xtables.lock: Permission denied error.

I tried touch /run/user/1000/dockerd-rootless-xtables.lock && chcon system_u:object_r:iptables_var_run_t:s0 /run/user/1000/dockerd-rootless-xtables.lock but same error

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to use chcon system_u:object_r:iptables_var_run_t:s0 /run.

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 <[email protected]>
@AkihiroSuda AkihiroSuda force-pushed the rootless-selinux-xtables-workaround branch from 54b4466 to cdaf82b Compare April 28, 2021 09:21
Comment on lines 113 to +120
rm -f /run/docker /run/containerd /run/xtables.lock

if [ -n "$_DOCKERD_ROOTLESS_SELINUX" ]; then
# iptables requires /run in the child to be relabeled. The actual /run in the parent is unaffected.
# https://github.com/containers/podman/blob/e6fc34b71aa9d876b1218efe90e14f8b912b0603/libpod/networking_linux.go#L396-L401
# https://github.com/moby/moby/issues/41230
chcon system_u:object_r:iptables_var_run_t:s0 /run
fi
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering; should this be seen as a temporary approach (and ultimately be handled by rootlesskit or dockerd itself?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally this could be fixed on the selinux policy package of RHEL/Fedora, however, given that even Podman has the same workaround, this workaround is likely to be permanent.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ach, missed your reply; meant to say; if we'll need this, would it be possible to move this step into the go code (dockerd or rootless kit) so that the bash script can be simplified (ideally the script would only have to do minimal steps to configure the daemon to run in rootless mode)

It's ok for now to use the script, but just rather would have the script small (if possible)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to keep this in the script.

Other distros/versions may have different policies for SELinux, and may require different chcon workarounds. The script is intended to be modifiable for such workarounds.

@AkihiroSuda AkihiroSuda requested a review from thaJeztah May 4, 2021 09:38
Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

but left a question (for a follow up?)

@AkihiroSuda
Copy link
Member Author

Cherry-pick to 20.10: #42462

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rootless mode doesn't start on Fedora 32 with SELinux enabled (but works on CentOS 8.2): "can't open lock file /run/xtables.lock: Permission denied"

4 participants