fix(agent): run the setup package install as fake root (#2539)

This commit is contained in:
MaxsTechReview authored and GitHub committed 2026-11-13 08:48:23 -05:00
1 parent d058bab64f
commit 33dbd8755f
7 files changed
+110 -9

No files matched your search

@@ -139,15 +139,26 @@ public final class LinuxRuntime {
public static List<String> command(Context context, File sessionRoot, File runtimeDir,
File externalStorage, List<String> extraBinds,
List<String> guestCommand) {
return command(context, sessionRoot, runtimeDir, externalStorage, extraBinds, guestCommand, false);
}
public static List<String> command(Context context, File sessionRoot, File runtimeDir,
File externalStorage, List<String> extraBinds,
List<String> guestCommand, boolean fakeRoot) {
File root = rootDir(context);
List<String> binds = binds(context, sessionRoot, runtimeDir, externalStorage, extraBinds);
if (sessionRoot != null) lastBinds = binds;
return commandWithBinds(context, root, binds, guestCommand);
return commandWithBinds(context, root, binds, guestCommand, fakeRoot);
}
public static List<String> commandWithBinds(Context context, File root, List<String> binds,
List<String> guestCommand) {
List<String> cmd = prootPrefix(context, root, "/root");
return commandWithBinds(context, root, binds, guestCommand, false);
}
public static List<String> commandWithBinds(Context context, File root, List<String> binds,
List<String> guestCommand, boolean fakeRoot) {
List<String> cmd = fakeRoot ? rootPrefix(context, root, "/root") : prootPrefix(context, root, "/root");
for (String spec : binds) bind(cmd, spec);
cmd.addAll(guestCommand);
return cmd;
@@ -170,6 +181,12 @@ public final class LinuxRuntime {
return prootPrefix(context, root, cwd, false);
}
public static List<String> rootPrefix(Context context, File root, String cwd) {
List<String> cmd = prootPrefix(context, root, cwd, true);
cmd.add(1, "--link2symlink");
return cmd;
}
public static List<String> prootPrefix(Context context, File root, String cwd, boolean fakeRoot) {
List<String> cmd = new ArrayList<>();
cmd.add(prootBinary(context).getPath());
@@ -120,8 +120,7 @@ object RootSpawner {
val builder = if (NativeGuest.forSession(context)) {
NativeGuest.processBuilder(context, root, binds, guest, cwd)
} else {
val cmd = LinuxRuntime.prootPrefix(context, root, cwd, true)
cmd.add(1, "--link2symlink")
val cmd = LinuxRuntime.rootPrefix(context, root, cwd)
binds.forEach { cmd.add("-b"); cmd.add(it) }
cmd.addAll(guest)
ProcessBuilder(cmd).directory(root).also { b ->