From aeae18920bec8a0d148ffa716a8bc3839f9bb4bd Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Tue, 7 Mar 2023 16:13:04 +0100 Subject: [PATCH] cmd/initContainer: Bind mount locations regardless of /run/host/etc Bind mounting the locations at runtime doesn't really have anything to do with whether /run/host/etc is present inside the Toolbx container. The only possible exception could have been /etc/machine-id, but it isn't, because the bind mount is only performed if the source at /run/host/etc/machine-id is present. This is a historical mistake that has persisted for a long time, since, in practice, /run/host/etc will almost always exist inside the Toolbx container. It's time to finally correct it. Fallout from 9436bbece01d7aa4dc91b4013ed9f80d0b8d34f4 https://github.com/containers/toolbox/pull/1255 --- src/cmd/initContainer.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/cmd/initContainer.go b/src/cmd/initContainer.go index a457cf3..222aa42 100644 --- a/src/cmd/initContainer.go +++ b/src/cmd/initContainer.go @@ -206,18 +206,6 @@ func initContainer(cmd *cobra.Command, args []string) error { return err } } - - for _, mount := range initContainerMounts { - if err := mountBind(mount.containerPath, mount.source, mount.flags); err != nil { - return err - } - } - - if utils.PathExists("/sys/fs/selinux") { - if err := mountBind("/sys/fs/selinux", "/usr/share/empty", ""); err != nil { - return err - } - } } if initContainerFlags.mediaLink { @@ -236,6 +224,18 @@ func initContainer(cmd *cobra.Command, args []string) error { } } + for _, mount := range initContainerMounts { + if err := mountBind(mount.containerPath, mount.source, mount.flags); err != nil { + return err + } + } + + if utils.PathExists("/sys/fs/selinux") { + if err := mountBind("/sys/fs/selinux", "/usr/share/empty", ""); err != nil { + return err + } + } + if _, err := user.Lookup(initContainerFlags.user); err != nil { if err := configureUsers(initContainerFlags.uid, initContainerFlags.user,