You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor(detection-emulation): factory for per-family command tools
Creates createRunFamilyCommandTool factory that builds the schema,
confirmation, and handler from a FamilyToolConfig object. All four
per-family tools (process, file, network, execution) are now config-only
modules (~50 lines each) delegating to the factory.
Eliminates ~400 lines of duplicated handler/schema/confirmation logic.
Adding a new family (e.g. registry) is now a one-file, config-only
addition.
emulationId: z.string().min(1).describe('Unique identifier for the emulation run.'),
49
+
agentType: z
50
+
.enum(['endpoint'])
51
+
.default('endpoint')
52
+
.describe(
53
+
'EDR agent type. Currently only `endpoint` (Elastic Defend) is wired. Omit; defaults to `endpoint`.'
54
+
),
55
+
endpointIds: z
56
+
.array(z.string().min(1))
57
+
.min(1)
58
+
.max(MAX_ENDPOINT_FANOUT,{
59
+
message: `endpointIds must contain at most ${MAX_ENDPOINT_FANOUT} entries (MAX_ENDPOINT_FANOUT)`,
60
+
})
61
+
.describe(
62
+
`Endpoint agent IDs to dispatch the action against (1–${MAX_ENDPOINT_FANOUT}). The fanout cap exists so a single call cannot N-multiply the per-host EDR rate budget by accident; if a user asks to dispatch against more than ${MAX_ENDPOINT_FANOUT} endpoints, split the request into sequential calls.`
'Command-specific parameters (strictly validated server-side per command). See `command` description for the required shape. Every command additionally accepts an optional `{ comment: string }` attached to the response-action audit trail.'
Copy file name to clipboardExpand all lines: x-pack/solutions/security/plugins/security_solution/server/agent_builder/skills/detection_emulation/run_execution_command_tool.ts
* Tool boundary schema for the execution-family commands. See the
27
-
* process-family tool docstring for why the boundary keeps
28
-
* `parameters` opaque and the handler re-parses with the strict
29
-
* discriminated union.
30
-
*/
31
-
construnExecutionCommandSchema=z.object({
32
-
emulationId: z.string().min(1).describe('Unique identifier for the emulation run.'),
33
-
agentType: z
34
-
.enum(['endpoint'])
35
-
.default('endpoint')
36
-
.describe(
37
-
'EDR agent type. Currently only `endpoint` (Elastic Defend) is wired. Omit; defaults to `endpoint`.'
38
-
),
39
-
endpointIds: z
40
-
.array(z.string().min(1))
41
-
.min(1)
42
-
.max(MAX_ENDPOINT_FANOUT,{
43
-
message: `endpointIds must contain at most ${MAX_ENDPOINT_FANOUT} entries (MAX_ENDPOINT_FANOUT)`,
44
-
})
45
-
.describe(
46
-
`Endpoint agent IDs to dispatch the action against (1–${MAX_ENDPOINT_FANOUT}). The fanout cap exists so a single call cannot N-multiply the per-host EDR rate budget by accident; if a user asks to dispatch against more than ${MAX_ENDPOINT_FANOUT} endpoints, split the request into sequential calls.`
`Execution-family command (HIGHEST IMPACT — runs arbitrary code on the endpoint):
50
-
- \`execute\` — \`{ command: string, timeout?: number }\` — run a shell command/executable
51
-
- \`runscript\` — \`{ scriptId: string, scriptInput?: string, timeout?: number }\` — run a script-library entry
52
-
- \`cancel\` — \`{ id: string }\` — cancel a previously-dispatched response action by id
53
-
54
-
Every command in this family ALSO accepts an optional \`comment: string\` in \`parameters\` — recorded against the response-action audit trail. Strongly recommended for \`execute\` and \`runscript\` so an auditor can see *why* the code ran (e.g. \`{ command: 'whoami', comment: 'verify hostname for rule X validation' }\`).`
55
-
),
56
-
parameters: z
57
-
.record(z.string(),z.unknown())
58
-
.optional()
59
-
.describe(
60
-
'Command-specific parameters (strictly validated server-side per command). See `command` description for the required shape. Every command additionally accepts an optional `{ comment: string }` attached to the response-action audit trail.'
`Emulation command [${command}] for emulation [${emulationId}] rejected: invalid parameters for command (${strictParseResult.error.message})`
129
-
);
130
-
returntoolError.invalidParameters({
131
-
emulation_id: emulationId,
132
-
agent_type: agentType,
133
-
command,
134
-
});
135
-
}
46
+
Every command in this family ALSO accepts an optional \`comment: string\` in \`parameters\` — recorded against the response-action audit trail. Strongly recommended for \`execute\` and \`runscript\` so an auditor can see *why* the code ran (e.g. \`{ command: 'whoami', comment: 'verify hostname for rule X validation' }\`).`,
0 commit comments