Merge remote-tracking branch 'origin/main'
This commit is contained in:
@@ -2,7 +2,6 @@ import { randomUUID } from "node:crypto";
|
||||
import { AnalysisError } from "../domain/analysisErrorBase.js";
|
||||
import {
|
||||
AnalysisCancelledError,
|
||||
AnalysisCapabilityUnavailableError,
|
||||
AnalysisProtocolError,
|
||||
AnalysisResourceConstraintError,
|
||||
AnalysisTimeoutError,
|
||||
@@ -19,6 +18,7 @@ import {
|
||||
windowsBatchCommand,
|
||||
WindowsBatchCommandError,
|
||||
} from "../process/WindowsBatchCommand.js";
|
||||
import { pcapToolUnavailable } from "./PcapConfiguration.js";
|
||||
|
||||
export interface PcapCommandLimits {
|
||||
readonly timeoutMs: number;
|
||||
@@ -168,8 +168,7 @@ export const runPcapCommand = async (options: {
|
||||
"code" in cause &&
|
||||
(cause.code === "ENOENT" || cause.code === "EACCES"))
|
||||
)
|
||||
throw new AnalysisCapabilityUnavailableError(
|
||||
"pcap",
|
||||
throw pcapToolUnavailable(
|
||||
operation,
|
||||
`Cannot run selected tool ${command}: ${cause.message}`,
|
||||
details,
|
||||
@@ -181,8 +180,7 @@ export const runPcapCommand = async (options: {
|
||||
? cause.message
|
||||
: String(cause);
|
||||
if (options.inputPath === undefined)
|
||||
throw new AnalysisCapabilityUnavailableError(
|
||||
"pcap",
|
||||
throw pcapToolUnavailable(
|
||||
operation,
|
||||
`The selected tool ${command} cannot report its version: ${diagnostic}`,
|
||||
details,
|
||||
|
||||
@@ -2,12 +2,31 @@ import { isAbsolute } from "node:path";
|
||||
|
||||
import type { ProviderAvailability } from "../application/AnalysisProvider.js";
|
||||
import type { ProviderRejectionCode } from "../contracts/providerSelection.js";
|
||||
import type { AnalysisErrorOptions } from "../domain/analysisErrorBase.js";
|
||||
import { AnalysisCapabilityUnavailableError } from "../domain/analysisErrorCore.js";
|
||||
import type { JsonValue } from "../domain/jsonValue.js";
|
||||
|
||||
/** Environment keys selecting the caller's tshark and capinfos binaries. */
|
||||
export const TSHARK_COMMAND_ENV = "REA_TSHARK_COMMAND";
|
||||
export const CAPINFOS_COMMAND_ENV = "REA_CAPINFOS_COMMAND";
|
||||
|
||||
const TOOL_REMEDIATION = `Supply Wireshark 4.x tshark and capinfos on PATH or through absolute ${TSHARK_COMMAND_ENV} and ${CAPINFOS_COMMAND_ENV}; REA does not install them.`;
|
||||
|
||||
/**
|
||||
* Host-tool refusals concern the caller's Wireshark installation, not the
|
||||
* target, so they carry their own guidance instead of the generic advice to
|
||||
* choose another target.
|
||||
*/
|
||||
export const pcapToolUnavailable = (
|
||||
operation: string,
|
||||
reason: string,
|
||||
options?: AnalysisErrorOptions,
|
||||
): AnalysisCapabilityUnavailableError =>
|
||||
new AnalysisCapabilityUnavailableError("pcap", operation, reason, {
|
||||
...options,
|
||||
userMessage: `${/[.!?]$/u.test(reason) ? reason : `${reason}.`} ${TOOL_REMEDIATION}`,
|
||||
});
|
||||
|
||||
/** How each tool was selected for this provider instance. */
|
||||
export interface PcapToolSelection {
|
||||
readonly tshark: { command: string; source: "environment" | "path" };
|
||||
|
||||
@@ -6,6 +6,8 @@ import { AnalysisCapabilityUnavailableError } from "../domain/analysisErrorCore.
|
||||
import type { ArtifactAnalysisResources } from "../process/ArtifactAnalysisResources.js";
|
||||
import type { runPcapCommand } from "./PcapCommand.js";
|
||||
|
||||
const PRLIMIT_COMMAND_ENV = "REA_TSHARK_PRLIMIT_COMMAND";
|
||||
|
||||
/** Own native capture admission and the exact enforced resource profile. */
|
||||
export const preparePcapNativeBound = async (
|
||||
environment: Readonly<Record<string, string | undefined>>,
|
||||
@@ -22,17 +24,20 @@ export const preparePcapNativeBound = async (
|
||||
],
|
||||
};
|
||||
}
|
||||
if (process.platform !== "linux")
|
||||
if (process.platform !== "linux") {
|
||||
const reason =
|
||||
"Packet summaries require an enforceable native memory bound: Linux with util-linux prlimit, or Windows with owned Job Objects. This host's capture boundary remains unsupported.";
|
||||
throw new AnalysisCapabilityUnavailableError(
|
||||
"pcap",
|
||||
"inspect_pcap_capture",
|
||||
"Packet summaries require an enforceable native memory bound: Linux with util-linux prlimit, or Windows with owned Job Objects. This host's capture boundary remains unsupported.",
|
||||
reason,
|
||||
{ userMessage: reason },
|
||||
);
|
||||
const configured =
|
||||
environment.REA_TSHARK_PRLIMIT_COMMAND ?? "/usr/bin/prlimit";
|
||||
}
|
||||
const configured = environment[PRLIMIT_COMMAND_ENV] ?? "/usr/bin/prlimit";
|
||||
try {
|
||||
if (!isAbsolute(configured))
|
||||
throw new Error("REA_TSHARK_PRLIMIT_COMMAND must be absolute.");
|
||||
throw new Error(`${PRLIMIT_COMMAND_ENV} must be absolute.`);
|
||||
const limiter = await realpath(configured);
|
||||
await access(limiter, constants.X_OK);
|
||||
const limits = await resources.readLimits({
|
||||
@@ -58,11 +63,16 @@ export const preparePcapNativeBound = async (
|
||||
return { nativeBound, limitations };
|
||||
} catch (cause) {
|
||||
if (cause instanceof AnalysisError) throw cause;
|
||||
const reason =
|
||||
"Cannot establish the selected Linux resource limiter before processing capture bytes.";
|
||||
throw new AnalysisCapabilityUnavailableError(
|
||||
"pcap",
|
||||
"inspect_pcap_capture",
|
||||
"Cannot establish the selected Linux resource limiter before processing capture bytes.",
|
||||
{ cause },
|
||||
reason,
|
||||
{
|
||||
cause,
|
||||
userMessage: `${reason} (${cause instanceof Error ? cause.message : String(cause)}) Check that ${PRLIMIT_COMMAND_ENV} (default /usr/bin/prlimit) names an absolute, executable util-linux prlimit.`,
|
||||
},
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -25,6 +25,7 @@ import {
|
||||
inspectPcapClient,
|
||||
resolvePcapTools,
|
||||
pcapConfigurationAvailability,
|
||||
pcapToolUnavailable,
|
||||
type PcapToolSelection,
|
||||
} from "./PcapConfiguration.js";
|
||||
import {
|
||||
@@ -346,12 +347,9 @@ export class PcapProvider {
|
||||
: signal?.aborted
|
||||
? new AnalysisCancelledError(request.operation, { cause })
|
||||
: cause instanceof PcapConfigurationFailure
|
||||
? new AnalysisCapabilityUnavailableError(
|
||||
"pcap",
|
||||
request.operation,
|
||||
cause.message,
|
||||
{ cause },
|
||||
)
|
||||
? pcapToolUnavailable(request.operation, cause.message, {
|
||||
cause,
|
||||
})
|
||||
: new AnalysisProtocolError(
|
||||
`Packet-capture analysis failed: ${cause instanceof Error ? cause.message : String(cause)}`,
|
||||
{ cause },
|
||||
|
||||
@@ -43,7 +43,7 @@ export class PcapSnapshot {
|
||||
"pcap",
|
||||
OPERATION,
|
||||
cause.message,
|
||||
{ cause },
|
||||
{ cause, retryable: cause.retryable },
|
||||
);
|
||||
throw new AnalysisResourceConstraintError(
|
||||
OPERATION,
|
||||
|
||||
Reference in New Issue
Block a user