From dcab4501f929ad77032f8b74206fd4c23ce55359 Mon Sep 17 00:00:00 2001 From: Mika Ayenson Date: Fri, 20 Nov 2026 20:57:53 -0600 Subject: [PATCH 1/7] Add terminate-genai-process template --- .../terminate-genai-process.yaml | 238 ++++++++++++++++++ 1 file changed, 238 insertions(+) create mode 100644 library/workflows/terminate-genai-process/terminate-genai-process.yaml diff --git a/library/workflows/terminate-genai-process/terminate-genai-process.yaml b/library/workflows/terminate-genai-process/terminate-genai-process.yaml new file mode 100644 index 00000000..099ebcb3 --- /dev/null +++ b/library/workflows/terminate-genai-process/terminate-genai-process.yaml @@ -0,0 +1,238 @@ +template-metadata: + slug: terminate-genai-process + version: "1.0.0" + availability: ">=9.5.0" + name: "Terminate GenAI Process Activity" + description: >- + Terminate a process attributed to a known AI agent or its descendants + (process.ai_agent.name / is_descendant) with Elastic Defend + kill_process. Requires process.ai_agent fields from Elastic Endpoint + (Linux 9.5+; macOS and Windows 9.6+) with AI event enrichment enabled + (Linux on by default in 9.5; use Defend AI data collection / advanced + genai_observability on other OS or older policies). Alert or manual. + Prefer process entity_id; PID only with live identity. Audit by + default; enable enforce to submit kill, poll completion, and verify. + Optional host isolate is a separate install toggle and runs only after + a verified kill. Enforce requires process.entity_id (PID-only + kill refused). Needs Defend kill_process (and isolate if enabled). + Refuses targets without AI-agent attribution. + solutions: [security] + categories: [response] + install: + form: + - name: enable-enforce + label: "Enforce process kill" + description: >- + When true, submit Defend kill_process for a verified target. Leave false + for audit-only. + inputType: boolean + required: true + default: false + - name: enable-isolate + label: "Optional host isolate after kill" + description: >- + When true and enforce is enabled, also submit Defend isolate. Leaves the + host network-cut; use only on disposable or approved hosts. + inputType: boolean + required: true + default: false + +name: Terminate GenAI Process Activity +description: >- + Terminate a process attributed to a known AI agent or its descendants via + process.ai_agent.name / process.ai_agent.is_descendant. Needs those fields + from Elastic Endpoint (Linux 9.5+; macOS and Windows 9.6+) with AI event + enrichment enabled (Linux on by default in 9.5; Defend AI data collection / + advanced genai_observability elsewhere). Alert or manual. Prefer process + entity_id; PID only with live identity. Audit by default; enforce submits + Defend kill_process, polls completion, and logs verification. Optional isolate runs only after a verified kill. Enforce requires + process.entity_id (PID-only kill refused). Needs Defend kill_process + (and isolate if enabled). Targets without AI-agent attribution are + skipped. +enabled: true +tags: + - security + - elastic-defend + - hunting + - response + - genai +settings: + timeout: 15m + concurrency: + key: "{{ workflow.id }}-{{ inputs.agent_id | default: '' }}-{{ event.alerts[0].agent.id | default: event.alerts[0].elastic.agent.id | default: '' }}" + strategy: drop + max: 1 +consts: + enable_enforce: __install__.enable-enforce + enable_isolate: __install__.enable-isolate + kill_descendants: false + action_poll_limit: 36 +triggers: + - type: alert + - type: manual + inputs: + - name: agent_id + type: string + required: true + description: Elastic Defend agent.id / endpoint id + - name: entity_id + type: string + required: false + default: "" + description: process.entity_id (preferred) + - name: pid + type: number + required: false + default: 0 + description: Process PID when entity_id unavailable + - name: process_name + type: string + required: false + default: "" + - name: host_name + type: string + required: false + default: "" + - name: ai_agent_name + type: string + required: false + default: "" + description: >- + process.ai_agent.name when running manually without an alert (e.g. + cursor, claude_code, copilot) + - name: ai_agent_is_descendant + type: boolean + required: false + default: false + description: >- + Set true on manual runs when the target is a descendant of a known + AI-agent process (process.ai_agent.is_descendant) +steps: + - name: set_context + type: data.set + with: + agent_id: "{% if event.alerts[0].agent.id != '' and event.alerts[0].agent.id != null %}{{ event.alerts[0].agent.id }}{% elsif event.alerts[0].elastic.agent.id != '' and event.alerts[0].elastic.agent.id != null %}{{ event.alerts[0].elastic.agent.id }}{% else %}{{ inputs.agent_id }}{% endif %}" + entity_id: "{% if event.alerts[0].process.entity_id != '' and event.alerts[0].process.entity_id != null %}{{ event.alerts[0].process.entity_id }}{% elsif inputs.entity_id != '' and inputs.entity_id != null %}{{ inputs.entity_id }}{% else %}{% endif %}" + process_pid: "{% if event.alerts[0].process.pid != '' and event.alerts[0].process.pid != null %}{{ event.alerts[0].process.pid }}{% elsif inputs.pid and inputs.pid != 0 %}{{ inputs.pid }}{% else %}{% endif %}" + process_name: "{% if event.alerts[0].process.name != '' and event.alerts[0].process.name != null %}{{ event.alerts[0].process.name }}{% elsif inputs.process_name != '' %}{{ inputs.process_name }}{% else %}{% endif %}" + host_name: "{% if event.alerts[0].host.name != '' and event.alerts[0].host.name != null %}{{ event.alerts[0].host.name }}{% elsif inputs.host_name != '' %}{{ inputs.host_name }}{% else %}{% endif %}" + ai_agent_name: "{% if event.alerts[0].process.ai_agent.name != '' and event.alerts[0].process.ai_agent.name != null %}{{ event.alerts[0].process.ai_agent.name }}{% elsif inputs.ai_agent_name != '' and inputs.ai_agent_name != null %}{{ inputs.ai_agent_name }}{% else %}{% endif %}" + ai_agent_is_descendant: "{% if event.alerts[0].process.ai_agent.is_descendant == true or event.alerts[0].process.ai_agent.is_descendant == 'true' %}true{% elsif inputs.ai_agent_is_descendant == true or inputs.ai_agent_is_descendant == 'true' %}true{% else %}false{% endif %}" + alert_id: "{% if event.alerts[0].kibana.alert.uuid != '' and event.alerts[0].kibana.alert.uuid != null %}{{ event.alerts[0].kibana.alert.uuid }}{% elsif event.alerts[0]._id != '' and event.alerts[0]._id != null %}{{ event.alerts[0]._id }}{% else %}{% endif %}" + rule_name: "{% if event.alerts[0].kibana.alert.rule.name != '' and event.alerts[0].kibana.alert.rule.name != null %}{{ event.alerts[0].kibana.alert.rule.name }}{% else %}manual{% endif %}" + run_mode: "{% if event.alerts[0]._id != '' and event.alerts[0]._id != null %}alert{% else %}manual{% endif %}" + - name: validate + type: if + condition: 'steps.set_context.output.agent_id: "" OR (steps.set_context.output.entity_id: "" AND steps.set_context.output.process_pid: "")' + steps: + - name: log_skip + type: console + with: + message: "skipped - need agent_id and entity_id or pid. outcome=skipped" + else: + - name: require_ai_agent + type: if + condition: 'steps.set_context.output.ai_agent_name: "" AND not steps.set_context.output.ai_agent_is_descendant: "true"' + steps: + - name: log_skip_not_ai_agent + type: console + with: + message: "skipped - need process.ai_agent.name or process.ai_agent.is_descendant=true (host={{ steps.set_context.output.host_name }} process={{ steps.set_context.output.process_name }} entity_id={{ steps.set_context.output.entity_id }} pid={{ steps.set_context.output.process_pid }}). outcome=skipped" + else: + - name: decide_enforce + type: data.set + with: + enforce: "{% if consts.enable_enforce %}true{% else %}false{% endif %}" + - name: audit_path + type: if + condition: 'steps.decide_enforce.output.enforce: "false"' + steps: + - name: log_audit + type: console + with: + message: "audited - would kill host={{ steps.set_context.output.host_name }} agent={{ steps.set_context.output.agent_id }} process={{ steps.set_context.output.process_name }} ai_agent={{ steps.set_context.output.ai_agent_name }} is_descendant={{ steps.set_context.output.ai_agent_is_descendant }} entity_id={{ steps.set_context.output.entity_id }} pid={{ steps.set_context.output.process_pid }} rule={{ steps.set_context.output.rule_name }} outcome=audited" + else: + - name: kill_by_entity + type: if + condition: 'not steps.set_context.output.entity_id: ""' + steps: + - name: kill_process_entity + type: kibana.request + on-failure: + continue: true + with: + method: POST + path: /api/endpoint/action/kill_process + headers: + kbn-xsrf: "true" + body: + agent_type: endpoint + endpoint_ids: + - "{{ steps.set_context.output.agent_id }}" + parameters: + entity_id: "{{ steps.set_context.output.entity_id }}" + kill_descendants: "{{ consts.kill_descendants }}" + comment: "terminate-genai-process ai_agent={{ steps.set_context.output.ai_agent_name }} alert={{ steps.set_context.output.alert_id }}" + - name: remember_kill_action + type: data.set + with: + kill_action_id: "{{ steps.kill_process_entity.output.data.id | default: steps.kill_process_entity.output.id | default: '' }}" + - name: init_poll + type: data.set + with: + kill_completed: false + kill_action_id: "{{ steps.remember_kill_action.output.kill_action_id | default: '' }}" + - name: poll_kill + type: while + condition: 'variables.kill_action_id: * and not variables.kill_action_id: "" and not variables.kill_completed: true' + max-iterations: + limit: 36 + on-limit: continue + steps: + - name: wait_kill + type: wait + with: + duration: 5s + - name: fetch_kill_details + type: kibana.request + on-failure: + continue: true + with: + method: GET + path: /api/endpoint/action/{{ variables.kill_action_id | url_encode }} + - name: mark_kill_completed + type: data.set + with: + kill_completed: "{%- assign d = steps.fetch_kill_details.output.data -%}{%- if variables.kill_action_id != '' and d.id == variables.kill_action_id and d.isCompleted -%}true{%- else -%}false{%- endif -%}" + if: 'variables.kill_action_id: * and not variables.kill_action_id: ""' + - name: summarize_kill + type: console + with: + message: "submitted kill_action_id={{ variables.kill_action_id }} completed={{ variables.kill_completed }} wasSuccessful={{ steps.fetch_kill_details.output.data.wasSuccessful }} agent={{ steps.set_context.output.agent_id }} ai_agent={{ steps.set_context.output.ai_agent_name }} is_descendant={{ steps.set_context.output.ai_agent_is_descendant }} entity_id={{ steps.set_context.output.entity_id }} pid={{ steps.set_context.output.process_pid }} outcome={% if variables.kill_action_id == '' %}failed{% elsif variables.kill_completed and steps.fetch_kill_details.output.data.wasSuccessful %}verified{% elsif variables.kill_completed %}failed{% else %}unknown{% endif %}" + - name: isolate_gate + type: if + condition: 'consts.enable_isolate: true AND variables.kill_completed: "true" AND steps.fetch_kill_details.output.data.wasSuccessful: true' + steps: + - name: isolate_host + type: kibana.request + on-failure: + continue: true + with: + method: POST + path: /api/endpoint/action/isolate + headers: + kbn-xsrf: "true" + body: + agent_type: endpoint + endpoint_ids: + - "{{ steps.set_context.output.agent_id }}" + comment: "terminate-genai-process optional isolate ai_agent={{ steps.set_context.output.ai_agent_name }} alert={{ steps.set_context.output.alert_id }}" + - name: log_isolate + type: console + with: + message: "isolate submitted agent={{ steps.set_context.output.agent_id }} error={{ steps.isolate_host.error }}" + else: + - name: log_refuse_pid_only + type: console + with: + message: "skipped - enforce requires process.entity_id (PID-only kill refused due to PID reuse risk). host={{ steps.set_context.output.host_name }} pid={{ steps.set_context.output.process_pid }} outcome=skipped" \ No newline at end of file From 64e273594fd18fe455749dd0f085cfc604fc826b Mon Sep 17 00:00:00 2001 From: Mika Ayenson Date: Fri, 20 Nov 2026 22:14:08 -0600 Subject: [PATCH 2/7] =?UTF-8?q?fix:=20address=20Libra=20review=20=E2=80=94?= =?UTF-8?q?=20description,=20concurrency,=20multi-alert,=20source=20isolat?= =?UTF-8?q?ion,=20outcome=20truthiness,=20isolate=20log?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../terminate-genai-process.yaml | 210 +++++++++--------- 1 file changed, 111 insertions(+), 99 deletions(-) diff --git a/library/workflows/terminate-genai-process/terminate-genai-process.yaml b/library/workflows/terminate-genai-process/terminate-genai-process.yaml index 099ebcb3..e8aa93b5 100644 --- a/library/workflows/terminate-genai-process/terminate-genai-process.yaml +++ b/library/workflows/terminate-genai-process/terminate-genai-process.yaml @@ -10,12 +10,13 @@ template-metadata: (Linux 9.5+; macOS and Windows 9.6+) with AI event enrichment enabled (Linux on by default in 9.5; use Defend AI data collection / advanced genai_observability on other OS or older policies). Alert or manual. - Prefer process entity_id; PID only with live identity. Audit by - default; enable enforce to submit kill, poll completion, and verify. - Optional host isolate is a separate install toggle and runs only after - a verified kill. Enforce requires process.entity_id (PID-only - kill refused). Needs Defend kill_process (and isolate if enabled). - Refuses targets without AI-agent attribution. + Requires process.entity_id — PID-only targets are always refused + (PID reuse risk). Audit by default; enable enforce to submit kill, + poll completion, and verify. Optional host isolate is a separate + install toggle and runs only after a verified kill. Needs Defend + kill_process (and isolate if enabled). Refuses targets without + AI-agent attribution. Multi-alert batches are rejected; configure + rule actions for per-alert mode. solutions: [security] categories: [response] install: @@ -43,12 +44,13 @@ description: >- process.ai_agent.name / process.ai_agent.is_descendant. Needs those fields from Elastic Endpoint (Linux 9.5+; macOS and Windows 9.6+) with AI event enrichment enabled (Linux on by default in 9.5; Defend AI data collection / - advanced genai_observability elsewhere). Alert or manual. Prefer process - entity_id; PID only with live identity. Audit by default; enforce submits - Defend kill_process, polls completion, and logs verification. Optional isolate runs only after a verified kill. Enforce requires - process.entity_id (PID-only kill refused). Needs Defend kill_process - (and isolate if enabled). Targets without AI-agent attribution are - skipped. + advanced genai_observability elsewhere). Alert or manual. Requires + process.entity_id — PID-only targets are always refused (PID reuse risk). + Audit by default; enforce submits Defend kill_process, polls completion, and + logs verification. Optional isolate runs only after a verified kill. Needs + Defend kill_process (and isolate if enabled). Multi-alert batches are + rejected; configure rule actions for per-alert mode. Targets without + AI-agent attribution are skipped. enabled: true tags: - security @@ -59,7 +61,7 @@ tags: settings: timeout: 15m concurrency: - key: "{{ workflow.id }}-{{ inputs.agent_id | default: '' }}-{{ event.alerts[0].agent.id | default: event.alerts[0].elastic.agent.id | default: '' }}" + key: "{{ workflow.id }}-{{ inputs.agent_id | default: event.alerts[0].agent.id | default: event.alerts[0].elastic.agent.id | default: '' }}-{{ inputs.entity_id | default: event.alerts[0].process.entity_id | default: inputs.pid | default: event.alerts[0].process.pid | default: '' }}" strategy: drop max: 1 consts: @@ -112,127 +114,137 @@ steps: type: data.set with: agent_id: "{% if event.alerts[0].agent.id != '' and event.alerts[0].agent.id != null %}{{ event.alerts[0].agent.id }}{% elsif event.alerts[0].elastic.agent.id != '' and event.alerts[0].elastic.agent.id != null %}{{ event.alerts[0].elastic.agent.id }}{% else %}{{ inputs.agent_id }}{% endif %}" - entity_id: "{% if event.alerts[0].process.entity_id != '' and event.alerts[0].process.entity_id != null %}{{ event.alerts[0].process.entity_id }}{% elsif inputs.entity_id != '' and inputs.entity_id != null %}{{ inputs.entity_id }}{% else %}{% endif %}" - process_pid: "{% if event.alerts[0].process.pid != '' and event.alerts[0].process.pid != null %}{{ event.alerts[0].process.pid }}{% elsif inputs.pid and inputs.pid != 0 %}{{ inputs.pid }}{% else %}{% endif %}" - process_name: "{% if event.alerts[0].process.name != '' and event.alerts[0].process.name != null %}{{ event.alerts[0].process.name }}{% elsif inputs.process_name != '' %}{{ inputs.process_name }}{% else %}{% endif %}" - host_name: "{% if event.alerts[0].host.name != '' and event.alerts[0].host.name != null %}{{ event.alerts[0].host.name }}{% elsif inputs.host_name != '' %}{{ inputs.host_name }}{% else %}{% endif %}" - ai_agent_name: "{% if event.alerts[0].process.ai_agent.name != '' and event.alerts[0].process.ai_agent.name != null %}{{ event.alerts[0].process.ai_agent.name }}{% elsif inputs.ai_agent_name != '' and inputs.ai_agent_name != null %}{{ inputs.ai_agent_name }}{% else %}{% endif %}" - ai_agent_is_descendant: "{% if event.alerts[0].process.ai_agent.is_descendant == true or event.alerts[0].process.ai_agent.is_descendant == 'true' %}true{% elsif inputs.ai_agent_is_descendant == true or inputs.ai_agent_is_descendant == 'true' %}true{% else %}false{% endif %}" + entity_id: "{% if event.alerts[0].process.entity_id != '' and event.alerts[0].process.entity_id != null %}{{ event.alerts[0].process.entity_id }}{% elsif event.alerts[0]._id == '' or event.alerts[0]._id == null %}{% if inputs.entity_id != '' and inputs.entity_id != null %}{{ inputs.entity_id }}{% endif %}{% endif %}" + process_pid: "{% if event.alerts[0].process.pid != '' and event.alerts[0].process.pid != null %}{{ event.alerts[0].process.pid }}{% elsif event.alerts[0]._id == '' or event.alerts[0]._id == null %}{% if inputs.pid and inputs.pid != 0 %}{{ inputs.pid }}{% endif %}{% endif %}" + process_name: "{% if event.alerts[0].process.name != '' and event.alerts[0].process.name != null %}{{ event.alerts[0].process.name }}{% elsif event.alerts[0]._id == '' or event.alerts[0]._id == null %}{% if inputs.process_name != '' %}{{ inputs.process_name }}{% endif %}{% endif %}" + host_name: "{% if event.alerts[0].host.name != '' and event.alerts[0].host.name != null %}{{ event.alerts[0].host.name }}{% elsif event.alerts[0]._id == '' or event.alerts[0]._id == null %}{% if inputs.host_name != '' %}{{ inputs.host_name }}{% endif %}{% endif %}" + ai_agent_name: "{% if event.alerts[0].process.ai_agent.name != '' and event.alerts[0].process.ai_agent.name != null %}{{ event.alerts[0].process.ai_agent.name }}{% elsif event.alerts[0]._id == '' or event.alerts[0]._id == null %}{% if inputs.ai_agent_name != '' and inputs.ai_agent_name != null %}{{ inputs.ai_agent_name }}{% endif %}{% endif %}" + ai_agent_is_descendant: "{% if event.alerts[0].process.ai_agent.is_descendant == true or event.alerts[0].process.ai_agent.is_descendant == 'true' %}true{% elsif event.alerts[0]._id == '' or event.alerts[0]._id == null %}{% if inputs.ai_agent_is_descendant == true or inputs.ai_agent_is_descendant == 'true' %}true{% else %}false{% endif %}{% else %}false{% endif %}" alert_id: "{% if event.alerts[0].kibana.alert.uuid != '' and event.alerts[0].kibana.alert.uuid != null %}{{ event.alerts[0].kibana.alert.uuid }}{% elsif event.alerts[0]._id != '' and event.alerts[0]._id != null %}{{ event.alerts[0]._id }}{% else %}{% endif %}" rule_name: "{% if event.alerts[0].kibana.alert.rule.name != '' and event.alerts[0].kibana.alert.rule.name != null %}{{ event.alerts[0].kibana.alert.rule.name }}{% else %}manual{% endif %}" run_mode: "{% if event.alerts[0]._id != '' and event.alerts[0]._id != null %}alert{% else %}manual{% endif %}" - - name: validate + alert_count: "{{ event.alerts | size | default: 0 }}" + - name: reject_multi_alert type: if - condition: 'steps.set_context.output.agent_id: "" OR (steps.set_context.output.entity_id: "" AND steps.set_context.output.process_pid: "")' + condition: 'steps.set_context.output.run_mode: "alert" AND not steps.set_context.output.alert_count: "0" AND not steps.set_context.output.alert_count: "1"' steps: - - name: log_skip + - name: log_multi_alert type: console with: - message: "skipped - need agent_id and entity_id or pid. outcome=skipped" + message: "skipped - received {{ steps.set_context.output.alert_count }} alerts; this workflow handles one alert per run. Configure the rule action for per-alert mode. outcome=skipped" else: - - name: require_ai_agent + - name: validate type: if - condition: 'steps.set_context.output.ai_agent_name: "" AND not steps.set_context.output.ai_agent_is_descendant: "true"' + condition: 'steps.set_context.output.agent_id: "" OR (steps.set_context.output.entity_id: "" AND steps.set_context.output.process_pid: "")' steps: - - name: log_skip_not_ai_agent + - name: log_skip type: console with: - message: "skipped - need process.ai_agent.name or process.ai_agent.is_descendant=true (host={{ steps.set_context.output.host_name }} process={{ steps.set_context.output.process_name }} entity_id={{ steps.set_context.output.entity_id }} pid={{ steps.set_context.output.process_pid }}). outcome=skipped" + message: "skipped - need agent_id and entity_id or pid. outcome=skipped" else: - - name: decide_enforce - type: data.set - with: - enforce: "{% if consts.enable_enforce %}true{% else %}false{% endif %}" - - name: audit_path + - name: require_ai_agent type: if - condition: 'steps.decide_enforce.output.enforce: "false"' + condition: 'steps.set_context.output.ai_agent_name: "" AND not steps.set_context.output.ai_agent_is_descendant: "true"' steps: - - name: log_audit + - name: log_skip_not_ai_agent type: console with: - message: "audited - would kill host={{ steps.set_context.output.host_name }} agent={{ steps.set_context.output.agent_id }} process={{ steps.set_context.output.process_name }} ai_agent={{ steps.set_context.output.ai_agent_name }} is_descendant={{ steps.set_context.output.ai_agent_is_descendant }} entity_id={{ steps.set_context.output.entity_id }} pid={{ steps.set_context.output.process_pid }} rule={{ steps.set_context.output.rule_name }} outcome=audited" + message: "skipped - need process.ai_agent.name or process.ai_agent.is_descendant=true (host={{ steps.set_context.output.host_name }} process={{ steps.set_context.output.process_name }} entity_id={{ steps.set_context.output.entity_id }} pid={{ steps.set_context.output.process_pid }}). outcome=skipped" else: - - name: kill_by_entity + - name: require_entity_id type: if - condition: 'not steps.set_context.output.entity_id: ""' + condition: 'steps.set_context.output.entity_id: ""' steps: - - name: kill_process_entity - type: kibana.request - on-failure: - continue: true - with: - method: POST - path: /api/endpoint/action/kill_process - headers: - kbn-xsrf: "true" - body: - agent_type: endpoint - endpoint_ids: - - "{{ steps.set_context.output.agent_id }}" - parameters: - entity_id: "{{ steps.set_context.output.entity_id }}" - kill_descendants: "{{ consts.kill_descendants }}" - comment: "terminate-genai-process ai_agent={{ steps.set_context.output.ai_agent_name }} alert={{ steps.set_context.output.alert_id }}" - - name: remember_kill_action - type: data.set + - name: log_refuse_pid_only + type: console with: - kill_action_id: "{{ steps.kill_process_entity.output.data.id | default: steps.kill_process_entity.output.id | default: '' }}" - - name: init_poll + message: "skipped - requires process.entity_id (PID-only refused due to PID reuse risk). host={{ steps.set_context.output.host_name }} pid={{ steps.set_context.output.process_pid }} outcome=skipped" + else: + - name: decide_enforce type: data.set with: - kill_completed: false - kill_action_id: "{{ steps.remember_kill_action.output.kill_action_id | default: '' }}" - - name: poll_kill - type: while - condition: 'variables.kill_action_id: * and not variables.kill_action_id: "" and not variables.kill_completed: true' - max-iterations: - limit: 36 - on-limit: continue - steps: - - name: wait_kill - type: wait - with: - duration: 5s - - name: fetch_kill_details - type: kibana.request - on-failure: - continue: true - with: - method: GET - path: /api/endpoint/action/{{ variables.kill_action_id | url_encode }} - - name: mark_kill_completed - type: data.set - with: - kill_completed: "{%- assign d = steps.fetch_kill_details.output.data -%}{%- if variables.kill_action_id != '' and d.id == variables.kill_action_id and d.isCompleted -%}true{%- else -%}false{%- endif -%}" - if: 'variables.kill_action_id: * and not variables.kill_action_id: ""' - - name: summarize_kill - type: console - with: - message: "submitted kill_action_id={{ variables.kill_action_id }} completed={{ variables.kill_completed }} wasSuccessful={{ steps.fetch_kill_details.output.data.wasSuccessful }} agent={{ steps.set_context.output.agent_id }} ai_agent={{ steps.set_context.output.ai_agent_name }} is_descendant={{ steps.set_context.output.ai_agent_is_descendant }} entity_id={{ steps.set_context.output.entity_id }} pid={{ steps.set_context.output.process_pid }} outcome={% if variables.kill_action_id == '' %}failed{% elsif variables.kill_completed and steps.fetch_kill_details.output.data.wasSuccessful %}verified{% elsif variables.kill_completed %}failed{% else %}unknown{% endif %}" - - name: isolate_gate + enforce: "{% if consts.enable_enforce %}true{% else %}false{% endif %}" + - name: audit_path type: if - condition: 'consts.enable_isolate: true AND variables.kill_completed: "true" AND steps.fetch_kill_details.output.data.wasSuccessful: true' + condition: 'steps.decide_enforce.output.enforce: "false"' steps: - - name: isolate_host + - name: log_audit + type: console + with: + message: "audited - would kill host={{ steps.set_context.output.host_name }} agent={{ steps.set_context.output.agent_id }} process={{ steps.set_context.output.process_name }} ai_agent={{ steps.set_context.output.ai_agent_name }} is_descendant={{ steps.set_context.output.ai_agent_is_descendant }} entity_id={{ steps.set_context.output.entity_id }} rule={{ steps.set_context.output.rule_name }} outcome=audited" + else: + - name: kill_process_entity type: kibana.request on-failure: continue: true with: method: POST - path: /api/endpoint/action/isolate + path: /api/endpoint/action/kill_process headers: kbn-xsrf: "true" body: agent_type: endpoint endpoint_ids: - "{{ steps.set_context.output.agent_id }}" - comment: "terminate-genai-process optional isolate ai_agent={{ steps.set_context.output.ai_agent_name }} alert={{ steps.set_context.output.alert_id }}" - - name: log_isolate + parameters: + entity_id: "{{ steps.set_context.output.entity_id }}" + kill_descendants: "{{ consts.kill_descendants }}" + comment: "terminate-genai-process ai_agent={{ steps.set_context.output.ai_agent_name }} alert={{ steps.set_context.output.alert_id }}" + - name: remember_kill_action + type: data.set + with: + kill_action_id: "{{ steps.kill_process_entity.output.data.id | default: steps.kill_process_entity.output.id | default: '' }}" + - name: init_poll + type: data.set + with: + kill_completed: false + kill_action_id: "{{ steps.remember_kill_action.output.kill_action_id | default: '' }}" + - name: poll_kill + type: while + condition: 'variables.kill_action_id: * and not variables.kill_action_id: "" and not variables.kill_completed: true' + max-iterations: + limit: "{{ consts.action_poll_limit }}" + on-limit: continue + steps: + - name: wait_kill + type: wait + with: + duration: 5s + - name: fetch_kill_details + type: kibana.request + on-failure: + continue: true + with: + method: GET + path: /api/endpoint/action/{{ variables.kill_action_id | url_encode }} + - name: mark_kill_completed + type: data.set + with: + kill_completed: "{%- assign d = steps.fetch_kill_details.output.data -%}{%- if variables.kill_action_id != '' and d.id == variables.kill_action_id and d.isCompleted -%}true{%- else -%}false{%- endif -%}" + if: 'variables.kill_action_id: * and not variables.kill_action_id: ""' + - name: summarize_kill type: console with: - message: "isolate submitted agent={{ steps.set_context.output.agent_id }} error={{ steps.isolate_host.error }}" - else: - - name: log_refuse_pid_only - type: console - with: - message: "skipped - enforce requires process.entity_id (PID-only kill refused due to PID reuse risk). host={{ steps.set_context.output.host_name }} pid={{ steps.set_context.output.process_pid }} outcome=skipped" \ No newline at end of file + message: "submitted kill_action_id={{ variables.kill_action_id }} completed={{ variables.kill_completed }} wasSuccessful={{ steps.fetch_kill_details.output.data.wasSuccessful }} agent={{ steps.set_context.output.agent_id }} ai_agent={{ steps.set_context.output.ai_agent_name }} is_descendant={{ steps.set_context.output.ai_agent_is_descendant }} entity_id={{ steps.set_context.output.entity_id }} pid={{ steps.set_context.output.process_pid }} outcome={% if variables.kill_action_id == '' %}failed{% elsif variables.kill_completed == 'true' and steps.fetch_kill_details.output.data.wasSuccessful %}verified{% elsif variables.kill_completed == 'true' %}failed{% else %}unknown{% endif %}" + - name: isolate_gate + type: if + condition: 'consts.enable_isolate: true AND variables.kill_completed: "true" AND steps.fetch_kill_details.output.data.wasSuccessful: true' + steps: + - name: isolate_host + type: kibana.request + on-failure: + continue: true + with: + method: POST + path: /api/endpoint/action/isolate + headers: + kbn-xsrf: "true" + body: + agent_type: endpoint + endpoint_ids: + - "{{ steps.set_context.output.agent_id }}" + comment: "terminate-genai-process optional isolate ai_agent={{ steps.set_context.output.ai_agent_name }} alert={{ steps.set_context.output.alert_id }}" + - name: log_isolate + type: console + with: + message: "isolate {% if steps.isolate_host.output.data.id != '' and steps.isolate_host.output.data.id != null %}submitted action_id={{ steps.isolate_host.output.data.id }}{% else %}rejected{% endif %} agent={{ steps.set_context.output.agent_id }} error={{ steps.isolate_host.error }}" \ No newline at end of file From f4f1ff1f05fc7a5ce8eaddb548b9b3fcde5b15b0 Mon Sep 17 00:00:00 2001 From: Mika Ayenson Date: Fri, 20 Nov 2026 23:20:47 -0600 Subject: [PATCH 3/7] fix: literal poll limit and entity_id help text --- .../terminate-genai-process/terminate-genai-process.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/library/workflows/terminate-genai-process/terminate-genai-process.yaml b/library/workflows/terminate-genai-process/terminate-genai-process.yaml index e8aa93b5..2551f69e 100644 --- a/library/workflows/terminate-genai-process/terminate-genai-process.yaml +++ b/library/workflows/terminate-genai-process/terminate-genai-process.yaml @@ -81,12 +81,12 @@ triggers: type: string required: false default: "" - description: process.entity_id (preferred) + description: Required process.entity_id (PID-only refused) - name: pid type: number required: false default: 0 - description: Process PID when entity_id unavailable + description: Display-only PID; kill always requires entity_id - name: process_name type: string required: false @@ -140,7 +140,7 @@ steps: - name: log_skip type: console with: - message: "skipped - need agent_id and entity_id or pid. outcome=skipped" + message: "skipped - need agent_id and process.entity_id (PID-only refused). outcome=skipped" else: - name: require_ai_agent type: if @@ -203,7 +203,7 @@ steps: type: while condition: 'variables.kill_action_id: * and not variables.kill_action_id: "" and not variables.kill_completed: true' max-iterations: - limit: "{{ consts.action_poll_limit }}" + limit: 36 on-limit: continue steps: - name: wait_kill From 078dcf0becbf99848e152cacd4d47e95d9f5a5ac Mon Sep 17 00:00:00 2001 From: Mika Ayenson Date: Mon, 30 Nov 2026 17:28:28 -0600 Subject: [PATCH 4/7] fix: document Response Actions History and surface kill errors Remove unused action_poll_limit after the literal poll limit change, note the history privilege needed for verification, and include kill_process errors in the summarize message. --- .../terminate-genai-process.yaml | 17 ++++++++++------- node_modules | 1 + 2 files changed, 11 insertions(+), 7 deletions(-) create mode 120000 node_modules diff --git a/library/workflows/terminate-genai-process/terminate-genai-process.yaml b/library/workflows/terminate-genai-process/terminate-genai-process.yaml index 2551f69e..c98d8baa 100644 --- a/library/workflows/terminate-genai-process/terminate-genai-process.yaml +++ b/library/workflows/terminate-genai-process/terminate-genai-process.yaml @@ -11,12 +11,14 @@ template-metadata: (Linux on by default in 9.5; use Defend AI data collection / advanced genai_observability on other OS or older policies). Alert or manual. Requires process.entity_id — PID-only targets are always refused - (PID reuse risk). Audit by default; enable enforce to submit kill, + (PID reuse risk). Audit by default; enable enforce to submit kill, poll completion, and verify. Optional host isolate is a separate install toggle and runs only after a verified kill. Needs Defend - kill_process (and isolate if enabled). Refuses targets without - AI-agent attribution. Multi-alert batches are rejected; configure - rule actions for per-alert mode. + kill_process (and isolate if enabled). Polling kill completion needs + Response Actions History privilege; without it the kill may still + run but ends outcome=unknown and isolate never runs. Refuses targets + without AI-agent attribution. Multi-alert batches are rejected; + configure rule actions for per-alert mode. solutions: [security] categories: [response] install: @@ -48,7 +50,9 @@ description: >- process.entity_id — PID-only targets are always refused (PID reuse risk). Audit by default; enforce submits Defend kill_process, polls completion, and logs verification. Optional isolate runs only after a verified kill. Needs - Defend kill_process (and isolate if enabled). Multi-alert batches are + Defend kill_process (and isolate if enabled). Polling action completion + also needs Response Actions History; without it the kill may still run but + ends outcome=unknown and isolate never runs. Multi-alert batches are rejected; configure rule actions for per-alert mode. Targets without AI-agent attribution are skipped. enabled: true @@ -68,7 +72,6 @@ consts: enable_enforce: __install__.enable-enforce enable_isolate: __install__.enable-isolate kill_descendants: false - action_poll_limit: 36 triggers: - type: alert - type: manual @@ -225,7 +228,7 @@ steps: - name: summarize_kill type: console with: - message: "submitted kill_action_id={{ variables.kill_action_id }} completed={{ variables.kill_completed }} wasSuccessful={{ steps.fetch_kill_details.output.data.wasSuccessful }} agent={{ steps.set_context.output.agent_id }} ai_agent={{ steps.set_context.output.ai_agent_name }} is_descendant={{ steps.set_context.output.ai_agent_is_descendant }} entity_id={{ steps.set_context.output.entity_id }} pid={{ steps.set_context.output.process_pid }} outcome={% if variables.kill_action_id == '' %}failed{% elsif variables.kill_completed == 'true' and steps.fetch_kill_details.output.data.wasSuccessful %}verified{% elsif variables.kill_completed == 'true' %}failed{% else %}unknown{% endif %}" + message: "submitted kill_action_id={{ variables.kill_action_id }} completed={{ variables.kill_completed }} wasSuccessful={{ steps.fetch_kill_details.output.data.wasSuccessful }} error={{ steps.kill_process_entity.error }} agent={{ steps.set_context.output.agent_id }} ai_agent={{ steps.set_context.output.ai_agent_name }} is_descendant={{ steps.set_context.output.ai_agent_is_descendant }} entity_id={{ steps.set_context.output.entity_id }} pid={{ steps.set_context.output.process_pid }} outcome={% if variables.kill_action_id == '' %}failed{% elsif variables.kill_completed == 'true' and steps.fetch_kill_details.output.data.wasSuccessful %}verified{% elsif variables.kill_completed == 'true' %}failed{% else %}unknown{% endif %}" - name: isolate_gate type: if condition: 'consts.enable_isolate: true AND variables.kill_completed: "true" AND steps.fetch_kill_details.output.data.wasSuccessful: true' diff --git a/node_modules b/node_modules new file mode 120000 index 00000000..0ba5700e --- /dev/null +++ b/node_modules @@ -0,0 +1 @@ +/Users/stryker/workspace/Elastic/workflows/node_modules \ No newline at end of file From 43782217ddc79be62b882370ae03d9e6c84848d6 Mon Sep 17 00:00:00 2001 From: Mika Ayenson Date: Mon, 30 Nov 2026 17:28:42 -0600 Subject: [PATCH 5/7] chore: stop tracking local node_modules symlink --- .gitignore | 2 +- node_modules | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) delete mode 120000 node_modules diff --git a/.gitignore b/.gitignore index 4b0506e5..5ac92512 100644 --- a/.gitignore +++ b/.gitignore @@ -32,4 +32,4 @@ workflows-library-*.tar.gz.sha256 .env .env.* *.key -*.pem \ No newline at end of file +*.pemnode_modules diff --git a/node_modules b/node_modules deleted file mode 120000 index 0ba5700e..00000000 --- a/node_modules +++ /dev/null @@ -1 +0,0 @@ -/Users/stryker/workspace/Elastic/workflows/node_modules \ No newline at end of file From 0d1bfb587971e3c03fadfd860fc78b266bec54de Mon Sep 17 00:00:00 2001 From: Mika Ayenson Date: Mon, 30 Nov 2026 19:35:05 -0600 Subject: [PATCH 6/7] fix: restore standalone *.pem gitignore rule --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 5ac92512..f19ede28 100644 --- a/.gitignore +++ b/.gitignore @@ -32,4 +32,4 @@ workflows-library-*.tar.gz.sha256 .env .env.* *.key -*.pemnode_modules +*.pem From 5f4b112bb87b69393690aff30ec6d7f85433162d Mon Sep 17 00:00:00 2001 From: Mika Ayenson Date: Tue, 1 Dec 2026 15:15:47 -0600 Subject: [PATCH 7/7] fix: remove stray spaces in terminate-genai-process description --- .../terminate-genai-process/terminate-genai-process.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/workflows/terminate-genai-process/terminate-genai-process.yaml b/library/workflows/terminate-genai-process/terminate-genai-process.yaml index c98d8baa..e81045ad 100644 --- a/library/workflows/terminate-genai-process/terminate-genai-process.yaml +++ b/library/workflows/terminate-genai-process/terminate-genai-process.yaml @@ -11,7 +11,7 @@ template-metadata: (Linux on by default in 9.5; use Defend AI data collection / advanced genai_observability on other OS or older policies). Alert or manual. Requires process.entity_id — PID-only targets are always refused - (PID reuse risk). Audit by default; enable enforce to submit kill, + (PID reuse risk). Audit by default; enable enforce to submit kill, poll completion, and verify. Optional host isolate is a separate install toggle and runs only after a verified kill. Needs Defend kill_process (and isolate if enabled). Polling kill completion needs