@@ -85108,14 +85108,28 @@ function getRunnerUser() {
8510885108 return undefined;
8510985109 }
8511085110}
85111- function chownForFolder(newOwner, target) {
85111+ function getPrivilegeMode() {
85112+ try {
85113+ if (external_os_.userInfo().uid === 0) {
85114+ return "root";
85115+ }
85116+ }
85117+ catch (_a) {
85118+ // fall through to sudo
85119+ }
85120+ return "sudo";
85121+ }
85122+ function chownForFolder(newOwner, target, useDirectPrivileges = false) {
8511285123 if (!newOwner) {
8511385124 console.log(`Unable to determine runner user; skipping chown of ${target}`);
8511485125 return;
8511585126 }
85116- let cmd = "sudo";
85117- let args = ["chown", "-R", newOwner, target];
85118- external_child_process_.execFileSync(cmd, args);
85127+ if (useDirectPrivileges) {
85128+ external_child_process_.execFileSync("chown", ["-R", newOwner, target]);
85129+ }
85130+ else {
85131+ external_child_process_.execFileSync("sudo", ["chown", "-R", newOwner, target]);
85132+ }
8511985133}
8512085134function isAgentInstalled(platform) {
8512185135 switch (platform) {
@@ -85678,8 +85692,8 @@ function installAgent(isTLS, configStr) {
8567885692 return true;
8567985693 });
8568085694}
85681- function installAgentBravo(configStr ) {
85682- return install_agent_awaiter(this, void 0 , void 0, function* () {
85695+ function installAgentBravo(configStr_1 ) {
85696+ return install_agent_awaiter(this, arguments , void 0, function* (configStr, useDirectPrivileges = false ) {
8568385697 // Note: to avoid github rate limiting
8568485698 const token = lib_core.getInput("token", { required: true });
8568585699 const auth = `token ${token}`;
@@ -85693,11 +85707,14 @@ function installAgentBravo(configStr) {
8569385707 external_child_process_.execSync("chmod +x /home/agent/agent");
8569485708 external_fs_.writeFileSync("/home/agent/agent.json", configStr);
8569585709 const logStream = external_fs_.openSync("/home/agent/agent.stdout", "a");
85696- const agentProcess = external_child_process_.spawn("sudo", ["/home/agent/agent"], {
85710+ const spawnOptions = {
8569785711 cwd: "/home/agent",
8569885712 detached: true,
8569985713 stdio: ["ignore", logStream, logStream],
85700- });
85714+ };
85715+ const agentProcess = useDirectPrivileges
85716+ ? external_child_process_.spawn("/home/agent/agent", [], spawnOptions)
85717+ : external_child_process_.spawn("sudo", ["/home/agent/agent"], spawnOptions);
8570185718 agentProcess.unref();
8570285719 const agentStatus = "/home/agent/agent.status";
8570385720 const deadline = Date.now() + 10000;
@@ -86140,7 +86157,7 @@ process.on("unhandledRejection", (reason) => {
8614086157 return;
8614186158 }
8614286159 case "linux":
86143- yield installAgentForBravo(github.context.repo.owner, bravoConfigStr);
86160+ yield installAgentForBravo(github.context.repo.owner, bravoConfigStr, thirdPartyProvider );
8614486161 return;
8614586162 }
8614686163 }
@@ -86384,7 +86401,7 @@ function installAgentForSelfHosted(owner, confg) {
8638486401 }
8638586402 });
8638686403}
86387- function installAgentForBravo(owner, bravoConfigStr) {
86404+ function installAgentForBravo(owner, bravoConfigStr, provider ) {
8638886405 return setup_awaiter(this, void 0, void 0, function* () {
8638986406 try {
8639086407 console.log("Installing Harden Runner bravo agent for third-party runner");
@@ -86393,9 +86410,17 @@ function installAgentForBravo(owner, bravoConfigStr) {
8639386410 console.log("TLS is not enabled for this organization. Bravo agent installation skipped.");
8639486411 return;
8639586412 }
86396- external_child_process_.execSync("sudo mkdir -p /home/agent");
86397- chownForFolder(getRunnerUser(), "/home/agent");
86398- yield installAgentBravo(bravoConfigStr);
86413+ const privilegeMode = getPrivilegeMode();
86414+ if (isDocker() && privilegeMode !== "root") {
86415+ console.log("Running inside a container without root privileges. Bravo agent installation skipped.");
86416+ return;
86417+ }
86418+ // CodeBuild containers run as root without a sudo binary; other
86419+ // providers keep the existing sudo-based install.
86420+ const useDirectPrivileges = provider === "codebuild" && privilegeMode === "root";
86421+ external_child_process_.execSync(useDirectPrivileges ? "mkdir -p /home/agent" : "sudo mkdir -p /home/agent");
86422+ chownForFolder(getRunnerUser(), "/home/agent", useDirectPrivileges);
86423+ yield installAgentBravo(bravoConfigStr, useDirectPrivileges);
8639986424 }
8640086425 catch (error) {
8640186426 console.log(`Failed to install bravo agent: ${error.message}`);
0 commit comments