diff --git a/.gitignore b/.gitignore index 4b0506e5..f19ede28 100644 --- a/.gitignore +++ b/.gitignore @@ -32,4 +32,4 @@ workflows-library-*.tar.gz.sha256 .env .env.* *.key -*.pem \ No newline at end of file +*.pem diff --git a/library/workflows/remove-selected-ai-extension/remove-selected-ai-extension.yaml b/library/workflows/remove-selected-ai-extension/remove-selected-ai-extension.yaml new file mode 100644 index 00000000..90c2ad5e --- /dev/null +++ b/library/workflows/remove-selected-ai-extension/remove-selected-ai-extension.yaml @@ -0,0 +1,411 @@ +template-metadata: + slug: remove-selected-ai-extension + version: "1.0.4" + availability: ">=9.5.0" + name: "Remove Selected AI Extension" + description: >- + Uninstall one user-installed VS Code or Cursor extension from an + endpoint with Elastic Defend execute. Audits by default; enforce runs + manually with the user's home directory after analyst approval. + Requires Defend with the execute response action (Enterprise) and a + system-wide editor install. + solutions: [security] + categories: [response] + install: + form: + - name: enable-enforce + label: "Enforce extension uninstall" + description: >- + When true, run the uninstall adapter for the verified extension id + after analyst approval. Alert runs still audit only; enforce needs a + manual run with absolute user_home. + inputType: boolean + required: true + default: false + +name: Remove Selected AI Extension +description: >- + Audit and remove one supported user-installed VS Code-family extension by + exact publisher.extension ID and profile. Caller must confirm + install_source=user (alert runs require gen_ai.extension.install_source; + missing field skips). Requires Elastic Defend on the host, the execute + response action (Enterprise license), and Execute Operations privilege for + the workflow identity. Alert runs audit only. Enforce is a manual run that + requires absolute inputs.user_home (never guessed from username; alert + documents do not carry a home path) so Defend execute as SYSTEM/root can + target that user's extensions via --extensions-dir / --user-data-dir. + Uninstall uses trusted system-wide editor binaries only (Program Files / + Applications / usr — not %LOCALAPPDATA% or other user-writable paths). On + Linux the binary and each parent to / must be root-owned and not group- or + other-writable. On macOS the same applies, except /Applications may be + admin group-writable (stock 775); drag-and-drop user-owned .app bundles + are unsupported (MDM/sudo root-owned installs only). Per-user installs fail + with shell_code=47. Audit by default; enforce pauses for analyst approval. +enabled: true +tags: + - security + - elastic-defend + - hunting + - response + - genai +settings: + # Cover waitForApproval (1h) plus Defend execute. + timeout: 75m + concurrency: + key: |- + {%- assign eid = inputs.extension_id | default: event.alerts[0].gen_ai.extension.id | default: '' | strip | downcase | truncate: 256, '' -%} + {%- assign ed = inputs.editor | default: event.alerts[0].gen_ai.editor.name | default: event.alerts[0].gen_ai.tool.name | default: '' | downcase | truncate: 32, '' -%} + {%- assign prof_raw = '' -%} + {%- assign prof_supplied = false -%} + {%- if inputs.profile != '' and inputs.profile != null -%} + {%- assign prof_raw = inputs.profile -%} + {%- assign prof_supplied = true -%} + {%- elsif event.alerts[0].gen_ai.editor.profile != '' and event.alerts[0].gen_ai.editor.profile != null -%} + {%- assign prof_raw = event.alerts[0].gen_ai.editor.profile -%} + {%- assign prof_supplied = true -%} + {%- endif -%} + {%- if prof_supplied -%} + {%- assign prof = prof_raw | strip | truncate: 128, '' -%} + {%- assign prof_lc = prof | downcase -%} + {%- if prof == '' -%} + {%- elsif prof_lc == 'default' -%}{%- assign prof = 'default' -%} + {%- endif -%} + {%- else -%} + {%- assign prof = 'default' -%} + {%- endif -%} + {%- assign aid = inputs.agent_id | default: event.alerts[0].agent.id | default: event.alerts[0].elastic.agent.id | default: 'none' | strip | truncate: 128, '' -%} + {%- assign home = '' -%} + {%- if inputs.user_home != '' and inputs.user_home != null -%} + {%- assign home = inputs.user_home | strip | truncate: 512, '' -%} + {%- endif -%} + {%- assign last = home | slice: -1, 1 -%} + {%- if home.size > 1 and last == '/' -%} + {%- assign hlen = home.size | minus: 1 -%} + {%- assign home = home | slice: 0, hlen -%} + {%- endif -%} + {%- assign os_raw = event.alerts[0].host.os.type | default: inputs.os_type | default: '' | downcase -%} + {%- if os_raw == 'windows' -%} + {%- assign bs = '\' -%} + {%- assign last = home | slice: -1, 1 -%} + {%- if home.size > 1 and last == bs -%} + {%- assign hlen = home.size | minus: 1 -%} + {%- assign home = home | slice: 0, hlen -%} + {%- endif -%} + {%- endif -%} + {{ workflow.id }}-ext-{{ eid | base64_encode }}|{{ ed | base64_encode }}|{{ prof | base64_encode }}|{{ aid | base64_encode }}|{{ home | base64_encode }} + strategy: drop + max: 1 +consts: + enable_enforce: __install__.enable-enforce +triggers: + - type: alert + - type: manual + inputs: + - name: agent_id + type: string + required: true + - name: os_type + type: string + required: true + description: linux | macos | windows + - name: editor + type: string + required: true + description: vscode | cursor + - name: extension_id + type: string + required: true + description: publisher.extension exact id + - name: profile + type: string + required: false + default: default + - name: user_home + type: string + required: false + default: "" + description: >- + Absolute home/profile root for the target user (required for enforce). + Manual runs only — alert documents do not carry a home path; never + guessed from username. + - name: install_source + type: string + required: false + default: user + description: >- + Caller attestation — must be user. Alert runs require + gen_ai.extension.install_source on the alert; missing field skips. +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 %}" + os_type: "{% if event.alerts[0].host.os.type != '' and event.alerts[0].host.os.type != null %}{{ event.alerts[0].host.os.type | downcase }}{% elsif inputs.os_type != '' and inputs.os_type != null %}{{ inputs.os_type | downcase }}{% else %}{% endif %}" + editor: "{% if inputs.editor != '' and inputs.editor != null %}{{ inputs.editor | downcase }}{% elsif event.alerts[0].gen_ai.editor.name != '' and event.alerts[0].gen_ai.editor.name != null %}{{ event.alerts[0].gen_ai.editor.name | downcase }}{% elsif event.alerts[0].gen_ai.tool.name != '' and event.alerts[0].gen_ai.tool.name != null %}{{ event.alerts[0].gen_ai.tool.name | downcase }}{% else %}{% endif %}" + extension_id: "{% if inputs.extension_id != '' and inputs.extension_id != null %}{{ inputs.extension_id }}{% elsif event.alerts[0].gen_ai.extension.id != '' and event.alerts[0].gen_ai.extension.id != null %}{{ event.alerts[0].gen_ai.extension.id }}{% else %}{% endif %}" + profile: |- + {%- assign supplied = false -%} + {%- assign raw = '' -%} + {%- if inputs.profile != '' and inputs.profile != null -%} + {%- assign raw = inputs.profile -%} + {%- assign supplied = true -%} + {%- elsif event.alerts[0].gen_ai.editor.profile != '' and event.alerts[0].gen_ai.editor.profile != null -%} + {%- assign raw = event.alerts[0].gen_ai.editor.profile -%} + {%- assign supplied = true -%} + {%- endif -%} + {%- if supplied -%} + {%- assign p = raw | strip -%} + {%- if p == '' -%} + {%- else -%} + {%- assign pl = p | downcase -%} + {%- if pl == 'default' -%}default{%- else -%}{{ p }}{%- endif -%} + {%- endif -%} + {%- else -%} + default + {%- endif -%} + user_home: |- + {%- assign home = '' -%} + {%- if inputs.user_home != '' and inputs.user_home != null -%} + {%- assign home = inputs.user_home | strip -%} + {%- endif -%} + {{ home }} + # Alert runs require install_source on the alert; do not default missing to user. + install_source: "{% if event.alerts[0]._id != '' and event.alerts[0]._id != null %}{% if event.alerts[0].gen_ai.extension.install_source != '' and event.alerts[0].gen_ai.extension.install_source != null %}{{ event.alerts[0].gen_ai.extension.install_source | downcase }}{% endif %}{% elsif inputs.install_source != '' and inputs.install_source != null %}{{ inputs.install_source | downcase }}{% else %}user{% endif %}" + host_name: "{% if event.alerts[0].host.name != '' and event.alerts[0].host.name != null %}{{ event.alerts[0].host.name }}{% else %}{% endif %}" + run_mode: "{% if event.alerts[0]._id != '' and event.alerts[0]._id != null %}alert{% else %}manual{% endif %}" + alert_count: "{{ event.alerts | size | default: 0 }}" + - name: reject_multi_alert + type: if + 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_reject_batch + type: console + with: + message: "rejected - received {{ steps.set_context.output.alert_count }} alerts; this workflow handles one extension removal at a time. outcome=rejected" + - name: fail_reject_batch + type: workflow.fail + with: + message: "Received {{ steps.set_context.output.alert_count }} alerts; this workflow handles one extension removal per run." + else: + # --- extension_id charset allowlist (Liquid; KQL has no regex) --- + - name: check_extension_id + type: data.set + with: + extension_id_ok: >- + {%- assign s = steps.set_context.output.extension_id | default: '' -%} + {%- assign allowed = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_.-' -%} + {%- assign alnum = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' -%} + {%- assign ok = false -%} + {%- assign len = s.size -%} + {%- if len > 2 and len <= 256 and s contains '.' -%} + {%- assign c0 = s | slice: 0, 1 -%} + {%- if alnum contains c0 -%} + {%- assign bad = false -%} + {%- for i in (0..255) -%} + {%- if i >= len -%}{%- break -%}{%- endif -%} + {%- assign c = s | slice: i, 1 -%} + {%- unless allowed contains c -%}{%- assign bad = true -%}{%- break -%}{%- endunless -%} + {%- endfor -%} + {%- unless bad -%} + {%- assign parts = s | split: '.' -%} + {%- if parts.size >= 2 and parts[0].size > 0 and parts[1].size > 0 -%} + {%- assign ok = true -%} + {%- endif -%} + {%- endunless -%} + {%- endif -%} + {%- endif -%} + {{ ok }} + - name: check_profile + type: data.set + with: + profile_ok: >- + {%- assign s = steps.set_context.output.profile | default: '' -%} + {%- assign allowed = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_.- ' -%} + {%- assign ok = true -%} + {%- assign len = s.size -%} + {%- if s == '' or len < 1 or len > 128 -%}{%- assign ok = false -%} + {%- else -%} + {%- for i in (0..127) -%} + {%- if i >= len -%}{%- break -%}{%- endif -%} + {%- assign c = s | slice: i, 1 -%} + {%- unless allowed contains c -%}{%- assign ok = false -%}{%- break -%}{%- endunless -%} + {%- endfor -%} + {%- endif -%} + {{ ok }} + - name: check_user_home + type: data.set + with: + user_home_ok: >- + {%- assign p = steps.set_context.output.user_home | default: '' | strip -%} + {%- assign pipe = '|' -%} + {%- assign ok = false -%} + {%- if p != '' and p.size <= 512 -%} + {%- unless p contains '..' or p contains '*' or p contains '?' or p contains ';' or p contains pipe or p contains '&' -%} + {%- assign os = steps.set_context.output.os_type -%} + {%- if os == 'windows' -%} + {%- assign bs = '\' -%} + {%- assign c1 = p | slice: 1, 1 -%} + {%- assign c2 = p | slice: 2, 1 -%} + {%- if c1 == ':' and c2 == '/' -%}{%- assign ok = true -%} + {%- elsif c1 == ':' and c2 == bs -%}{%- assign ok = true -%} + {%- endif -%} + {%- else -%} + {%- assign c0 = p | slice: 0, 1 -%} + {%- if c0 == '/' -%}{%- assign ok = true -%}{%- endif -%} + {%- endif -%} + {%- endunless -%} + {%- endif -%} + {{ ok }} + - name: validate_extension_id + type: if + condition: 'not steps.check_extension_id.output.extension_id_ok: "true"' + steps: + - name: log_bad_ext + type: console + with: + message: "rejected - extension_id failed charset allowlist (expect publisher.extension). outcome=rejected" + - name: fail_bad_ext + type: workflow.fail + with: + message: "extension_id failed charset allowlist (expect publisher.extension)." + else: + - name: validate + type: if + condition: 'not steps.check_profile.output.profile_ok: "true" OR steps.set_context.output.agent_id: "" OR steps.set_context.output.extension_id: "" OR steps.set_context.output.os_type: "" OR not steps.set_context.output.install_source: "user" OR (not steps.set_context.output.editor: "vscode" AND not steps.set_context.output.editor: "cursor")' + steps: + - name: log_skip + type: console + with: + message: "skipped - need agent_id, os_type, editor vscode|cursor, extension_id, install_source=user (alert field required on alert runs), and a safe non-blank profile. outcome=skipped" + - name: fail_skip + type: workflow.fail + with: + message: "Missing required fields for extension removal (agent/os/editor/extension/install_source=user/profile)." + else: + - name: decide_enforce + type: data.set + with: + enforce: "{% if steps.set_context.output.run_mode == 'alert' %}false{% elsif 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 remove editor={{ steps.set_context.output.editor }} extension={{ steps.set_context.output.extension_id }} profile={{ steps.set_context.output.profile }} user_home={{ steps.set_context.output.user_home }} agent={{ steps.set_context.output.agent_id }} host={{ steps.set_context.output.host_name }} outcome=audited" + else: + - name: require_user_home + type: if + condition: 'not steps.check_user_home.output.user_home_ok: "true"' + steps: + - name: log_missing_home + type: console + with: + message: "skipped - enforce requires absolute manual user_home (alert runs audit only; never guessed from username). outcome=skipped" + - name: fail_missing_home + type: workflow.fail + with: + message: "Enforce requires absolute manual user_home (alert runs audit only)." + else: + - name: approve_remove + type: waitForApproval + timeout: 1h + with: + message: >- + Remove {{ steps.set_context.output.editor }} extension + {{ steps.set_context.output.extension_id }} + (profile={{ steps.set_context.output.profile }}) + from agent={{ steps.set_context.output.agent_id }} + host={{ steps.set_context.output.host_name }} + user_home={{ steps.set_context.output.user_home }}? + Requires a root-owned system-wide editor install (Program Files / + Applications / usr; macOS drag-and-drop .app + bundles unsupported). Per-user or user-writable + installs fail with no trusted binary. + approveLabel: Remove extension + rejectLabel: Hold + - name: after_approval + type: if + condition: 'steps.approve_remove.output.response.approved: true' + steps: + - name: set_cmd + type: data.set + with: + command: |- + {%- assign ed = steps.set_context.output.editor -%} + {%- assign eid = steps.set_context.output.extension_id -%} + {%- assign home = steps.set_context.output.user_home -%} + {%- assign prof = steps.set_context.output.profile -%} + {%- if steps.set_context.output.os_type == 'windows' -%} + powershell.exe -NoProfile -NonInteractive -Command "$ErrorActionPreference='Stop'; $homePath=[Text.Encoding]::UTF8.GetString([Convert]::FromBase64String('{{ home | base64_encode }}')); if([string]::IsNullOrWhiteSpace($homePath)){exit 42}; if($homePath -match '^[A-Za-z]:/'){ $homePath=$homePath.Substring(0,1)+':\'+$homePath.Substring(3).Replace('/','\') }; if($homePath -notmatch '^[A-Za-z]:\\' -or $homePath.Contains('..') -or $homePath.Contains('*') -or $homePath.Contains('?') -or $homePath.Contains(';') -or $homePath.Contains('|') -or $homePath.Contains('&')){exit 42}; $eid=[Text.Encoding]::UTF8.GetString([Convert]::FromBase64String('{{ eid | base64_encode }}')); if($eid -notmatch '^[A-Za-z0-9][A-Za-z0-9_.-]*\.[A-Za-z0-9][A-Za-z0-9_.-]*$'){exit 42}; $prof=[Text.Encoding]::UTF8.GetString([Convert]::FromBase64String('{{ prof | base64_encode }}')); if($prof -and $prof.ToLowerInvariant() -ne 'default'){ if($prof -notmatch '^[A-Za-z0-9_. -]{1,128}$'){exit 42} }; $roaming=Join-Path $homePath 'AppData\Roaming'; {% if ed == 'cursor' %}$extDir=Join-Path $homePath '.cursor\extensions'; $userData=Join-Path $roaming 'Cursor'; $bins=@((Join-Path ${env:ProgramFiles} 'Cursor\resources\app\bin\cursor.cmd'),(Join-Path ${env:ProgramFiles} 'cursor\resources\app\bin\cursor.cmd'),(Join-Path ${env:ProgramFiles(x86)} 'Cursor\resources\app\bin\cursor.cmd')){% else %}$extDir=Join-Path $homePath '.vscode\extensions'; $userData=Join-Path $roaming 'Code'; $bins=@((Join-Path ${env:ProgramFiles} 'Microsoft VS Code\bin\code.cmd'),(Join-Path ${env:ProgramFiles(x86)} 'Microsoft VS Code\bin\code.cmd')){% endif %}; $bin=$bins | Where-Object { Test-Path $_ } | Select-Object -First 1; if(-not $bin){exit 47}; $args=@('--extensions-dir',$extDir,'--user-data-dir',$userData,'--uninstall-extension',$eid,'--force'); if($prof -and $prof.ToLowerInvariant() -ne 'default'){ $args+='--profile'; $args+=$prof }; & $bin @args; if($LASTEXITCODE -ne 0){exit $LASTEXITCODE}; Write-Output ('removed:'+$eid)" + {%- else -%} + home='{{ home | replace: "'", "'\\''" }}'; case "$home" in /*) ;; *) exit 42 ;; esac; case "$home" in *..*|*\;*|*\|*|*\&*|*\`*|*\$*|*\**) exit 42 ;; esac; eid='{{ eid | replace: "'", "'\\''" }}'; case "$eid" in *[!A-Za-z0-9_.-]*) exit 42 ;; esac; case "$eid" in *.*) ;; *) exit 42 ;; esac; prof='{{ prof | replace: "'", "'\\''" }}'; case "$prof" in *[!A-Za-z0-9_.\ -]*) exit 42 ;; esac; prof_lc=$(printf '%s' "$prof" | tr '[:upper:]' '[:lower:]'); {% if ed == 'cursor' %}ext_dir="$home/.cursor/extensions"; if [ "$(uname -s)" = Darwin ]; then user_data="$home/Library/Application Support/Cursor"; else user_data="$home/.config/Cursor"; fi; trust_bin(){ c="$1"; [ -x "$c" ]||return 1; t="$c"; n=0; while [ -L "$t" ]&&[ "$n" -lt 32 ]; do l=$(readlink "$t" 2>/dev/null)||return 1; case "$l" in /*) t="$l";; *) t="$(dirname "$t")/$l";; esac; n=$((n+1)); done; [ -e "$t" ]||return 1; if command -v realpath >/dev/null 2>&1; then t=$(realpath "$t" 2>/dev/null)||return 1; fi; d="$t"; while :; do if [ "$(uname -s)" = Darwin ]; then uid=$(stat -f %u "$d" 2>/dev/null)||return 1; mode=$(stat -f %Lp "$d" 2>/dev/null)||return 1; else uid=$(stat -c %u "$d" 2>/dev/null)||return 1; mode=$(stat -c %a "$d" 2>/dev/null)||return 1; fi; [ "$uid" = 0 ]||return 1; o=$((mode%10)); g=$(((mode/10)%10)); [ $((o&2)) -eq 0 ]||return 1; if [ "$(uname -s)" = Darwin ] && [ "$d" = /Applications ] && [ $((g&2)) -ne 0 ]; then gid=$(stat -f %g "$d" 2>/dev/null)||return 1; [ "$gid" = 80 ]||return 1; else [ $((g&2)) -eq 0 ]||return 1; fi; [ "$d" = / ]&&break; nd=$(dirname "$d"); [ "$nd" = "$d" ]&&break; d="$nd"; done; printf %s "$t"; return 0; }; bin=""; for c in /usr/local/bin/cursor /usr/bin/cursor "/Applications/Cursor.app/Contents/Resources/app/bin/cursor"; do r=$(trust_bin "$c")||continue; bin="$r"; break; done{% else %}ext_dir="$home/.vscode/extensions"; if [ "$(uname -s)" = Darwin ]; then user_data="$home/Library/Application Support/Code"; else user_data="$home/.config/Code"; fi; trust_bin(){ c="$1"; [ -x "$c" ]||return 1; t="$c"; n=0; while [ -L "$t" ]&&[ "$n" -lt 32 ]; do l=$(readlink "$t" 2>/dev/null)||return 1; case "$l" in /*) t="$l";; *) t="$(dirname "$t")/$l";; esac; n=$((n+1)); done; [ -e "$t" ]||return 1; if command -v realpath >/dev/null 2>&1; then t=$(realpath "$t" 2>/dev/null)||return 1; fi; d="$t"; while :; do if [ "$(uname -s)" = Darwin ]; then uid=$(stat -f %u "$d" 2>/dev/null)||return 1; mode=$(stat -f %Lp "$d" 2>/dev/null)||return 1; else uid=$(stat -c %u "$d" 2>/dev/null)||return 1; mode=$(stat -c %a "$d" 2>/dev/null)||return 1; fi; [ "$uid" = 0 ]||return 1; o=$((mode%10)); g=$(((mode/10)%10)); [ $((o&2)) -eq 0 ]||return 1; if [ "$(uname -s)" = Darwin ] && [ "$d" = /Applications ] && [ $((g&2)) -ne 0 ]; then gid=$(stat -f %g "$d" 2>/dev/null)||return 1; [ "$gid" = 80 ]||return 1; else [ $((g&2)) -eq 0 ]||return 1; fi; [ "$d" = / ]&&break; nd=$(dirname "$d"); [ "$nd" = "$d" ]&&break; d="$nd"; done; printf %s "$t"; return 0; }; bin=""; for c in /usr/local/bin/code /usr/bin/code "/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code"; do r=$(trust_bin "$c")||continue; bin="$r"; break; done{% endif %}; [ -n "$bin" ] || exit 47; if [ -n "$prof" ] && [ "$prof_lc" != "default" ]; then "$bin" --extensions-dir "$ext_dir" --user-data-dir "$user_data" --uninstall-extension "$eid" --force --profile "$prof"; else "$bin" --extensions-dir "$ext_dir" --user-data-dir "$user_data" --uninstall-extension "$eid" --force; fi; ec=$?; [ $ec -eq 0 ] || exit $ec; printf 'removed:%s\n' "$eid" + {%- endif -%} + - name: execute_remove + type: kibana.request + with: + method: POST + path: /api/endpoint/action/execute + headers: + kbn-xsrf: "true" + body: + agent_type: endpoint + endpoint_ids: + - "{{ steps.set_context.output.agent_id }}" + comment: "remove-selected-ai-extension {{ steps.set_context.output.extension_id }}" + parameters: + command: "{{ steps.set_cmd.output.command }}" + timeout: 120 + - name: remember + type: data.set + with: + action_id: "{{ steps.execute_remove.output.data.id | default: steps.execute_remove.output.id | default: '' }}" + completed: false + - name: poll + type: while + condition: 'variables.action_id: * and not variables.action_id: "" and not variables.completed: true' + max-iterations: + limit: 36 + on-limit: continue + steps: + - name: wait_poll + type: wait + with: + duration: 5s + - name: fetch + type: kibana.request + on-failure: + continue: true + with: + method: GET + path: /api/endpoint/action/{{ variables.action_id | url_encode }} + - name: mark + type: data.set + with: + completed: "{%- assign d = steps.fetch.output.data -%}{%- if variables.action_id != '' and d.id == variables.action_id and d.isCompleted -%}true{%- else -%}false{%- endif -%}" + - name: set_outcome + type: data.set + with: + outcome: "{% assign sc = steps.fetch.output.data.outputs[steps.set_context.output.agent_id].content.shell_code | default: '' %}{% if variables.completed == 'true' and steps.fetch.output.data.wasSuccessful and sc == 0 %}verified{% elsif variables.completed == 'true' and sc == 47 %}no_trusted_binary{% elsif variables.completed == 'true' %}failed{% else %}unknown{% endif %}" + - name: summarize + type: console + with: + message: "extension-remove action_id={{ variables.action_id }} completed={{ variables.completed }} wasSuccessful={{ steps.fetch.output.data.wasSuccessful }} shell_code={{ steps.fetch.output.data.outputs[steps.set_context.output.agent_id].content.shell_code }} user_home={{ steps.set_context.output.user_home }} outcome={{ steps.set_outcome.output.outcome }}{% if steps.set_outcome.output.outcome == 'no_trusted_binary' %} (no trusted root-owned system-wide editor binary under Program Files / Applications / usr; macOS drag-and-drop .app unsupported){% endif %}" + - name: fail_unverified + type: if + condition: 'not steps.set_outcome.output.outcome: "verified"' + steps: + - name: fail_remove + type: workflow.fail + with: + message: "{% if steps.set_outcome.output.outcome == 'no_trusted_binary' %}No trusted root-owned system-wide {{ steps.set_context.output.editor }} binary found (shell_code=47). Per-user, user-writable, or macOS drag-and-drop .app installs are unsupported.{% else %}Extension removal did not verify for {{ steps.set_context.output.extension_id }} (outcome={{ steps.set_outcome.output.outcome }}).{% endif %}" + else: + - name: log_approval_rejected + type: console + with: + message: "rejected - analyst declined extension removal for {{ steps.set_context.output.extension_id }} outcome=rejected" + - name: fail_approval_rejected + type: workflow.fail + with: + message: "Analyst declined removal of {{ steps.set_context.output.extension_id }}."