feat(electron): add autonomous Electron runtime analysis (#464)
* feat: add autonomous Electron runtime analysis * feat(electron): add lifecycle and boundary telemetry * feat(electron): capture runtime boundary evidence * fix(electron): package boundary hook helper * feat(electron): report active capture coverage * fix(electron): account for bring-your-own runtime * feat(electron): expand agent-owned runtime scenarios * fix(ghidra): keep fixture credentials out of argv * perf(test): serialize local test and docs workloads * fix(electron): harden active runtime capture * fix(inspector): require exact runtime target authorization * fix(docs): make managed manifest host independent * fix(ci): make generated catalog portable * fix: unblock autonomous command and electron flows * fix(electron): close popup and detached helper gaps
This commit is contained in:
@@ -2,10 +2,44 @@ import { chmod, mkdtemp, rm } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
|
||||
import {
|
||||
windowsNativeCapabilities,
|
||||
type WindowsNativeCapability,
|
||||
} from "./WindowsAuthority.js";
|
||||
|
||||
/** Filesystem coordinates for one provider-owned private runtime directory. */
|
||||
export interface PrivateRuntimeRootOptions {
|
||||
readonly parent?: string;
|
||||
readonly prefix?: string;
|
||||
/** Platform override used by deterministic boundary tests. */
|
||||
readonly platform?: NodeJS.Platform;
|
||||
}
|
||||
|
||||
/** Provider-neutral security status for one runtime-root implementation. */
|
||||
export type PrivateRuntimeRootCapability =
|
||||
| WindowsNativeCapability
|
||||
| {
|
||||
readonly available: true;
|
||||
readonly reason: null;
|
||||
readonly proof: "posix-mode-0700";
|
||||
};
|
||||
|
||||
/** Report whether this process can establish a private runtime root. */
|
||||
export const privateRuntimeRootCapability = (
|
||||
platform: NodeJS.Platform = process.platform,
|
||||
): PrivateRuntimeRootCapability =>
|
||||
platform === "win32"
|
||||
? windowsNativeCapabilities(platform).private_runtime_dacl
|
||||
: { available: true, reason: null, proof: "posix-mode-0700" };
|
||||
|
||||
/** Expected failure when a runtime root's privacy boundary is unavailable. */
|
||||
export class PrivateRuntimeRootUnavailableError extends Error {
|
||||
readonly code = "private-runtime-root-authority-unavailable";
|
||||
|
||||
constructor(message: string) {
|
||||
super(message);
|
||||
this.name = "PrivateRuntimeRootUnavailableError";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -24,6 +58,10 @@ export class PrivateRuntimeRoot {
|
||||
static async create(
|
||||
options: PrivateRuntimeRootOptions = {},
|
||||
): Promise<PrivateRuntimeRoot> {
|
||||
const platform = options.platform ?? process.platform;
|
||||
const capability = privateRuntimeRootCapability(platform);
|
||||
if (!capability.available)
|
||||
throw new PrivateRuntimeRootUnavailableError(capability.reason);
|
||||
const path = await mkdtemp(
|
||||
join(options.parent ?? tmpdir(), options.prefix ?? "rea-provider-"),
|
||||
);
|
||||
|
||||
@@ -15,6 +15,8 @@ export interface OwnedProcessGroup {
|
||||
readonly expectedCommand?: string;
|
||||
/** Expected launcher parent, checked only while the leader exists. */
|
||||
readonly expectedParentPid?: number;
|
||||
/** Scan all live processes for this run token during cleanup. */
|
||||
readonly sweepTokenOwnedProcesses?: boolean;
|
||||
}
|
||||
|
||||
/** One entry from an operating-system process-table snapshot. */
|
||||
@@ -96,7 +98,8 @@ export type ProcessGroupObservation =
|
||||
* Terminate one Windows process tree through the platform utility.
|
||||
*
|
||||
* This is a bounded P0 cleanup mechanism, not Job Object ownership proof. The
|
||||
* caller-visible Windows limitations must preserve that distinction.
|
||||
* caller-visible Windows capability report remains unavailable until a native
|
||||
* authority verifies Job Object creation, membership, and cleanup semantics.
|
||||
*/
|
||||
export const cleanupWindowsProcessTree = async (
|
||||
rootPid: number,
|
||||
@@ -250,6 +253,24 @@ export const cleanupOwnedProcessGroup = async (
|
||||
return { cleaned: true, signaled };
|
||||
};
|
||||
|
||||
/** Verify that no live process still carries an owned capture run token. */
|
||||
export const verifyNoTokenOwnedProcesses = async (
|
||||
runId: string,
|
||||
host: ProcessOwnershipHost = systemHost,
|
||||
): Promise<ProcessCleanupResult> => {
|
||||
let processes: readonly ProcessTableEntry[];
|
||||
try {
|
||||
processes = liveProcesses(await host.listProcesses());
|
||||
} catch {
|
||||
return { cleaned: false, reason: "process table could not be inspected" };
|
||||
}
|
||||
const scan = await scanTokenOwnedProcesses(processes, runId, host);
|
||||
if (scan.failures.length > 0) return cleanupValidationFailure(scan.failures);
|
||||
return scan.owned.length === 0
|
||||
? { cleaned: true, signaled: false }
|
||||
: { cleaned: false, reason: "token-owned process remained after cleanup" };
|
||||
};
|
||||
|
||||
interface OwnedCleanupPlan {
|
||||
readonly signalOrder: readonly number[];
|
||||
}
|
||||
@@ -259,11 +280,24 @@ const createOwnedCleanupPlan = async (
|
||||
processes: readonly ProcessTableEntry[],
|
||||
host: ProcessOwnershipHost,
|
||||
): Promise<OwnedCleanupPlan | ProcessCleanupResult> => {
|
||||
const tokenOwned =
|
||||
ownership.sweepTokenOwnedProcesses === true
|
||||
? await scanTokenOwnedProcesses(processes, ownership.runId, host)
|
||||
: { owned: [], failures: [] };
|
||||
if (tokenOwned.failures.length > 0)
|
||||
return cleanupValidationFailure(tokenOwned.failures);
|
||||
const tokenOwnedGroupIds = new Set(
|
||||
tokenOwned.owned.map(({ processGroupId }) => processGroupId),
|
||||
);
|
||||
const launcher = processes.find(({ pid }) => pid === ownership.leaderPid);
|
||||
const rootMembers = processes.filter(
|
||||
({ processGroupId }) => processGroupId === ownership.processGroupId,
|
||||
);
|
||||
if (launcher === undefined && rootMembers.length === 0)
|
||||
if (
|
||||
launcher === undefined &&
|
||||
rootMembers.length === 0 &&
|
||||
tokenOwned.owned.length === 0
|
||||
)
|
||||
return { cleaned: true, signaled: false };
|
||||
let descendants: readonly ProcessTableEntry[] = [];
|
||||
if (launcher !== undefined) {
|
||||
@@ -276,13 +310,18 @@ const createOwnedCleanupPlan = async (
|
||||
const processGroupIds = new Set<number>([ownership.processGroupId]);
|
||||
for (const descendant of descendants)
|
||||
processGroupIds.add(descendant.processGroupId);
|
||||
for (const process of tokenOwned.owned)
|
||||
processGroupIds.add(process.processGroupId);
|
||||
for (const processGroupId of processGroupIds) {
|
||||
if (processGroupId === ownership.processGroupId) continue;
|
||||
const groupLeader = processes.find(
|
||||
({ pid, processGroupId: observedGroupId }) =>
|
||||
pid === processGroupId && observedGroupId === processGroupId,
|
||||
);
|
||||
if (groupLeader === undefined || !descendantPids.has(groupLeader.pid))
|
||||
if (
|
||||
(groupLeader === undefined || !descendantPids.has(groupLeader.pid)) &&
|
||||
!tokenOwnedGroupIds.has(processGroupId)
|
||||
)
|
||||
return {
|
||||
cleaned: false,
|
||||
reason:
|
||||
@@ -360,7 +399,8 @@ const revalidateOwnedProcessGroup = async (
|
||||
if (
|
||||
processGroupId !== ownership.processGroupId &&
|
||||
members.length > 0 &&
|
||||
!members.some(({ pid }) => pid === processGroupId)
|
||||
!members.some(({ pid }) => pid === processGroupId) &&
|
||||
ownership.sweepTokenOwnedProcesses !== true
|
||||
)
|
||||
return {
|
||||
cleaned: false,
|
||||
@@ -401,6 +441,33 @@ const processOwnershipFailures = async (
|
||||
return failures;
|
||||
};
|
||||
|
||||
interface TokenOwnedProcessScan {
|
||||
readonly owned: readonly ProcessTableEntry[];
|
||||
readonly failures: readonly ProcessOwnershipValidationFailure[];
|
||||
}
|
||||
|
||||
const scanTokenOwnedProcesses = async (
|
||||
processes: readonly ProcessTableEntry[],
|
||||
runId: string,
|
||||
host: ProcessOwnershipHost,
|
||||
): Promise<TokenOwnedProcessScan> => {
|
||||
const owned: ProcessTableEntry[] = [];
|
||||
const failures: ProcessOwnershipValidationFailure[] = [];
|
||||
for (const process of processes) {
|
||||
try {
|
||||
if ((await host.environment(process.pid)).REA_PROCESS_RUN_ID === runId)
|
||||
owned.push(process);
|
||||
} catch {
|
||||
try {
|
||||
const live = liveProcesses(await host.listProcesses());
|
||||
if (!live.some(({ pid }) => pid === process.pid)) continue;
|
||||
} catch {}
|
||||
failures.push({ pid: process.pid, reason: "environment-unreadable" });
|
||||
}
|
||||
}
|
||||
return { owned, failures };
|
||||
};
|
||||
|
||||
/** Observe one group without signaling it, failing closed on identity doubt. */
|
||||
export const observeOwnedProcessGroup = async (
|
||||
ownership: OwnedProcessGroup,
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
/**
|
||||
* Provider-neutral security controls that require a verified Windows native
|
||||
* authority. Runtime probes and POSIX permissions do not satisfy these
|
||||
* controls.
|
||||
*/
|
||||
export type WindowsNativeCapability =
|
||||
| {
|
||||
readonly available: true;
|
||||
readonly reason: null;
|
||||
readonly proof: "native-authority";
|
||||
}
|
||||
| {
|
||||
readonly available: false;
|
||||
readonly reason: string;
|
||||
readonly proof: "not-proven" | "not-applicable";
|
||||
};
|
||||
|
||||
/** Security controls required before REA may claim Windows isolation. */
|
||||
export interface WindowsNativeCapabilitySet {
|
||||
readonly job_object_process_ownership: WindowsNativeCapability;
|
||||
readonly private_runtime_dacl: WindowsNativeCapability;
|
||||
readonly reparse_safe_path_admission: WindowsNativeCapability;
|
||||
}
|
||||
|
||||
/** Stable explanation used whenever the native Windows authority is absent. */
|
||||
export const WINDOWS_NATIVE_AUTHORITY_UNAVAILABLE_REASON =
|
||||
"Verified Windows native authority is unavailable: Job Object process ownership, private runtime DACL enforcement, and reparse-safe path admission are not implemented; chmod(0700) is insufficient for Windows private DACL proof, and taskkill is not a Job Object security proof";
|
||||
|
||||
/**
|
||||
* Describe native Windows controls without inferring them from taskkill,
|
||||
* chmod, symlink creation, or a numeric POSIX open flag.
|
||||
*/
|
||||
export const windowsNativeCapabilities = (
|
||||
platform: NodeJS.Platform,
|
||||
): WindowsNativeCapabilitySet => {
|
||||
if (platform !== "win32") {
|
||||
const notApplicable = {
|
||||
available: false,
|
||||
reason: "Windows native authority is not applicable on this host",
|
||||
proof: "not-applicable",
|
||||
} as const;
|
||||
return {
|
||||
job_object_process_ownership: notApplicable,
|
||||
private_runtime_dacl: notApplicable,
|
||||
reparse_safe_path_admission: notApplicable,
|
||||
};
|
||||
}
|
||||
|
||||
const notProven = {
|
||||
available: false,
|
||||
reason: WINDOWS_NATIVE_AUTHORITY_UNAVAILABLE_REASON,
|
||||
proof: "not-proven",
|
||||
} as const;
|
||||
return {
|
||||
job_object_process_ownership: notProven,
|
||||
private_runtime_dacl: notProven,
|
||||
reparse_safe_path_admission: notProven,
|
||||
};
|
||||
};
|
||||
|
||||
/** Whether every native control needed for Windows isolation is proven. */
|
||||
export const hasWindowsNativeAuthority = (platform: NodeJS.Platform): boolean =>
|
||||
Object.values(windowsNativeCapabilities(platform)).every(
|
||||
({ available }) => available,
|
||||
);
|
||||
Reference in New Issue
Block a user