fix: agent inherits UID/GID from the parent process

This commit is contained in:
Igor Ramazanov
2025-07-27 03:28:34 +00:00
committed by Aarnav Tale
parent 344901d38c
commit 8a9235836a
+7 -1
View File
@@ -8,7 +8,7 @@ import {
readFile, readFile,
writeFile, writeFile,
} from 'node:fs/promises'; } from 'node:fs/promises';
import { exit } from 'node:process'; import { exit, geteuid, getegid } from 'node:process';
import { createInterface } from 'node:readline'; import { createInterface } from 'node:readline';
import { setTimeout } from 'node:timers/promises'; import { setTimeout } from 'node:timers/promises';
import { type } from 'arktype'; import { type } from 'arktype';
@@ -114,6 +114,8 @@ class AgentManager {
private spawnProcess: ChildProcess | null; private spawnProcess: ChildProcess | null;
private agentId: string | null; private agentId: string | null;
private uid: number | null;
private gid: number | null;
constructor( constructor(
cache: TimedCache<HostInfo>, cache: TimedCache<HostInfo>,
@@ -126,6 +128,8 @@ class AgentManager {
this.spawnProcess = null; this.spawnProcess = null;
this.agentId = null; this.agentId = null;
this.startAgent(); this.startAgent();
this.uid = geteuid ? geteuid() : null;
this.gid = getegid ? getegid() : null;
process.on('SIGINT', () => { process.on('SIGINT', () => {
this.spawnProcess?.kill(); this.spawnProcess?.kill();
@@ -183,6 +187,8 @@ class AgentManager {
this.restartCounter, this.restartCounter,
); );
this.spawnProcess = spawn(this.config.executable_path, [], { this.spawnProcess = spawn(this.config.executable_path, [], {
...(this.uid ? { uid: this.uid } : {}),
...(this.gid ? { gid: this.gid } : {}),
detached: false, detached: false,
stdio: ['pipe', 'pipe', 'pipe', 'pipe', 'pipe'], stdio: ['pipe', 'pipe', 'pipe', 'pipe', 'pipe'],
env: { env: {