Skip to content

Commit 7542f5f

Browse files
committed
cmd/initContainer: Avoid RPM failures due to unexpected file owners
When running rootless, files and directories bind mounted from the host operating system can have their ownership listed as nobody:nobody. This is because the UIDs and GIDs that actually own those locations are not available inside the container. Some distribution packages are particular about the file ownerships of some of these locations. eg., Fedora's filesystem, flatpak and libvirt-libs RPMs. Encountering nobody:nobody as the owner can fail package management transactions involving such packages leading to unforeseen consequences. Therefore, configure RPM to leave these locations alone. #640
1 parent 55f944c commit 7542f5f

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

‎src/cmd/initContainer.go‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,24 @@ func initContainer(cmd *cobra.Command, args []string) error {
264264
}
265265
}
266266

267+
if utils.PathExists("/usr/lib/rpm/macros.d") {
268+
logrus.Debug("Configuring RPM to ignore bind mounts")
269+
270+
var builder strings.Builder
271+
fmt.Fprintf(&builder, "# Written by Toolbox\n")
272+
fmt.Fprintf(&builder, "# https://github.com/containers/toolbox\n")
273+
fmt.Fprintf(&builder, "\n")
274+
fmt.Fprintf(&builder, "%%_netsharedpath /dev:/media:/mnt:/proc:/sys:/tmp:/var/lib/flatpak:/var/lib/libvirt\n")
275+
276+
rpmConfigString := builder.String()
277+
rpmConfigBytes := []byte(rpmConfigString)
278+
if err := ioutil.WriteFile("/usr/lib/rpm/macros.d/macros.toolbox",
279+
rpmConfigBytes,
280+
0644); err != nil {
281+
return fmt.Errorf("failed to configure RPM to ignore bind mounts: %w", err)
282+
}
283+
}
284+
267285
logrus.Debug("Setting up daily ticker")
268286

269287
daily, err := time.ParseDuration("24h")

0 commit comments

Comments
 (0)