Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ workflows-library-*.tar.gz.sha256
.env
.env.*
*.key
*.pem
*.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,322 @@
template-metadata:
slug: respond-genai-credential-exposure
version: "1.0.0"
availability: ">=9.5.0"
name: "Respond to GenAI Credential Exposure"
description: >-
Deactivate or revoke one identified AI-provider API key using a
customer-configured secure HTTP connector. Metadata-only triggers - no
prompt bodies or raw tokens. Initial Anthropic Admin API (status
inactive) with GET verify; OpenAI project-key delete as second adapter.
Audit by default. Enforce requires analyst approval before the provider
call.
solutions: [security]
categories: [response]
install:
form:
- name: enable-enforce
label: "Enforce key deactivate or revoke"
description: >-
When true, call the provider Admin API through the selected HTTP
connector after analyst approval.
inputType: boolean
required: true
default: false
- name: anthropic-admin-connector
label: "Anthropic Admin HTTP connector"
description: >-
HTTP connector with base URL https://api.anthropic.com and Admin API key
in secret headers (x-api-key). Never put the key in YAML.
inputType: connector
connectorType: .http
required: false
- name: openai-admin-connector
label: "OpenAI Admin HTTP connector"
description: >-
HTTP connector with base URL https://api.openai.com and organization
admin credentials in secret headers for project API key delete.
inputType: connector
connectorType: .http
required: false

name: Respond to GenAI Credential Exposure
description: >-
Deactivate or revoke one identified AI-provider API key. Metadata-only
triggers - no prompt bodies or raw tokens. Audit by default. Initial provider
Anthropic (Admin API key status=inactive) with independent GET verify; OpenAI
project-key delete as second adapter. Enforce pauses for analyst approval
before the provider call. Requires a customer-configured secure HTTP
connector - never embeds credentials in YAML.
enabled: true
tags:
- security
- elastic-defend
- hunting
- response
- genai
settings:
# Cover waitForApproval (1h) plus provider HTTP verify.
timeout: 75m
concurrency:
key: "{{ workflow.id }}-cred-{{ inputs.key_id | default: event.alerts[0].gen_ai.auth.key_id | default: 'none' }}"
strategy: drop
max: 1
consts:
enable_enforce: __install__.enable-enforce
anthropic_admin_base: https://api.anthropic.com
openai_admin_base: https://api.openai.com
anthropic_version: "2023-06-01"
triggers:
- type: alert
- type: manual
inputs:
- name: provider
type: string
required: true
description: anthropic | openai
default: anthropic
- name: key_id
type: string
required: true
description: Non-secret provider key ID (e.g. apikey_...)
- name: org_or_workspace
type: string
required: false
default: ""
- name: project_id
type: string
required: false
default: ""
description: >-
Required for openai project keys (OpenAI project id, e.g. proj_...).
Ignored for anthropic.
- name: owner
type: string
required: false
default: ""
- name: evidence_ref
type: string
required: false
default: ""
steps:
- name: set_context
type: data.set
with:
# Alert fields first: manual-input defaults are applied on alert runs too.
provider: "{% if event.alerts[0].gen_ai.provider != '' and event.alerts[0].gen_ai.provider != null %}{{ event.alerts[0].gen_ai.provider | downcase }}{% elsif event.alerts[0].cloud.provider != '' and event.alerts[0].cloud.provider != null %}{{ event.alerts[0].cloud.provider | downcase }}{% elsif inputs.provider != '' and inputs.provider != null %}{{ inputs.provider | downcase }}{% else %}{% endif %}"
key_id: "{% if event.alerts[0].gen_ai.auth.key_id != '' and event.alerts[0].gen_ai.auth.key_id != null %}{{ event.alerts[0].gen_ai.auth.key_id }}{% elsif inputs.key_id != '' and inputs.key_id != null %}{{ inputs.key_id }}{% else %}{% endif %}"
org_or_workspace: "{% if inputs.org_or_workspace != '' %}{{ inputs.org_or_workspace }}{% else %}{% endif %}"
project_id: "{% if event.alerts[0].gen_ai.project.id != '' and event.alerts[0].gen_ai.project.id != null %}{{ event.alerts[0].gen_ai.project.id }}{% elsif inputs.project_id != '' and inputs.project_id != null %}{{ inputs.project_id }}{% else %}{% endif %}"
owner: "{% if inputs.owner != '' %}{{ inputs.owner }}{% elsif event.alerts[0].user.email != '' %}{{ event.alerts[0].user.email }}{% else %}{% endif %}"
evidence_ref: "{% if inputs.evidence_ref != '' %}{{ inputs.evidence_ref }}{% elsif event.alerts[0].kibana.alert.uuid != '' %}{{ event.alerts[0].kibana.alert.uuid }}{% else %}{{ execution.id }}{% 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 != '' %}{{ event.alerts[0]._id }}{% 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
Comment thread
infra-vault-gh-plugin-prod[bot] marked this conversation as resolved.
Resolved
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"'
Comment thread
Mikaayenson marked this conversation as resolved.
Resolved
steps:
- name: log_reject_batch
type: console
with:
message: "rejected - received {{ steps.set_context.output.alert_count }} alerts; this workflow handles exactly one credential at a time. Re-run per alert. outcome=rejected"
Comment thread
Mikaayenson marked this conversation as resolved.
Resolved
- name: fail_reject_batch
type: workflow.fail
with:
message: "Received {{ steps.set_context.output.alert_count }} alerts; this workflow handles exactly one credential per run."
else:
# --- key_id format allowlist: refuse raw secrets (Liquid; KQL has no regex) ---
- name: check_key_format
type: data.set
with:
key_id_ok: >-
{%- assign s = steps.set_context.output.key_id | default: '' -%}
{%- assign allowed = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_.:-' -%}
{%- assign alnum = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' -%}
{%- assign ok = false -%}
{%- assign len = s.size -%}
{%- if len > 0 and len <= 128 -%}
{%- assign c0 = s | slice: 0, 1 -%}
{%- assign prefix = s | slice: 0, 3 -%}
{%- if alnum contains c0 and prefix != 'sk-' -%}
{%- assign bad = false -%}
{%- for i in (0..127) -%}
{%- if i >= len -%}{%- break -%}{%- endif -%}
{%- assign c = s | slice: i, 1 -%}
{%- unless allowed contains c -%}{%- assign bad = true -%}{%- break -%}{%- endunless -%}
{%- endfor -%}
{%- unless bad -%}{%- assign ok = true -%}{%- endunless -%}
{%- endif -%}
{%- endif -%}
{{ ok }}
- name: check_project_id
type: data.set
with:
# Anthropic ignores project_id. OpenAI requires a proj_... id — never echo rejects.
project_id_ok: >-
{%- assign provider = steps.set_context.output.provider | default: '' -%}
{%- if provider != 'openai' -%}
true
{%- else -%}
{%- assign s = steps.set_context.output.project_id | default: '' -%}
{%- assign allowed = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_.:-' -%}
{%- assign ok = false -%}
{%- assign len = s.size -%}
{%- assign prefix = s | slice: 0, 5 -%}
{%- assign sk = s | slice: 0, 3 -%}
{%- if len >= 6 and len <= 128 and prefix == 'proj_' and sk != 'sk-' -%}
{%- assign bad = false -%}
{%- for i in (0..127) -%}
{%- if i >= len -%}{%- break -%}{%- endif -%}
{%- assign c = s | slice: i, 1 -%}
{%- unless allowed contains c -%}{%- assign bad = true -%}{%- break -%}{%- endunless -%}
{%- endfor -%}
{%- unless bad -%}{%- assign ok = true -%}{%- endunless -%}
{%- endif -%}
{{ ok }}
{%- endif -%}
- name: validate_key_format
type: if
condition: 'not steps.check_key_format.output.key_id_ok: "true"'
Comment thread
Mikaayenson marked this conversation as resolved.
Resolved
steps:
- name: log_bad_key
type: console
with:
message: "rejected - key_id failed format allowlist (expected provider key ID like apikey_... or key_..., not a raw secret). No value logged. outcome=rejected"
- name: fail_bad_key
type: workflow.fail
with:
message: "key_id failed format allowlist (refused raw secret-shaped values)."
else:
- name: validate_project_format
type: if
# Empty openai project_id is a missing-field skip (validate), not a format reject.
condition: 'steps.set_context.output.provider: "openai" AND not steps.set_context.output.project_id: "" AND not steps.check_project_id.output.project_id_ok: "true"'
steps:
- name: log_bad_project
type: console
with:
message: "rejected - openai project_id failed format allowlist (expected proj_... project id, not a raw secret). No value logged. outcome=rejected"
- name: fail_bad_project
type: workflow.fail
with:
message: "openai project_id failed format allowlist (refused non-proj_ or secret-shaped values)."
Comment thread
infra-vault-gh-plugin-prod[bot] marked this conversation as resolved.
Resolved
else:
- name: validate
type: if
condition: 'steps.set_context.output.key_id: "" OR (not steps.set_context.output.provider: "anthropic" AND not steps.set_context.output.provider: "openai") OR (steps.set_context.output.provider: "openai" AND steps.set_context.output.project_id: "")'
steps:
- name: log_skip
type: console
with:
message: "skipped - need non-secret key_id and provider anthropic|openai (openai also needs project_id). No secret content logged. outcome=skipped"
- name: fail_skip
type: workflow.fail
with:
message: "Missing non-secret key_id and/or provider anthropic|openai (openai also needs project_id)."
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 deactivate provider={{ steps.set_context.output.provider }} key_id={{ steps.set_context.output.key_id }}{% if steps.set_context.output.provider == 'openai' %} project={{ steps.set_context.output.project_id }}{% endif %} owner={{ steps.set_context.output.owner }} evidence={{ steps.set_context.output.evidence_ref }} outcome=audited"
else:
- name: approve_revoke
type: waitForApproval
timeout: 1h
with:
message: "Revoke {{ steps.set_context.output.provider }} key {{ steps.set_context.output.key_id }}{% if steps.set_context.output.provider == 'openai' %} project={{ steps.set_context.output.project_id }}{% endif %} (evidence {{ steps.set_context.output.evidence_ref }})?"
approveLabel: Revoke key
rejectLabel: Hold
- name: after_approval
type: if
condition: 'steps.approve_revoke.output.response.approved: true'
steps:
- name: anthropic_path
type: if
condition: 'steps.set_context.output.provider: "anthropic"'
steps:
- name: anthropic_inactive
type: http
connector-id: __install__.anthropic-admin-connector
with:
method: POST
path: /v1/organizations/api_keys/{{ steps.set_context.output.key_id | url_encode }}
headers:
anthropic-version: "{{ consts.anthropic_version }}"
content-type: application/json
body:
status: inactive
- name: anthropic_verify
type: http
connector-id: __install__.anthropic-admin-connector
on-failure:
continue: true
with:
method: GET
path: /v1/organizations/api_keys/{{ steps.set_context.output.key_id | url_encode }}
headers:
anthropic-version: "{{ consts.anthropic_version }}"
- name: anthropic_outcome
type: data.set
with:
outcome: "{% if steps.anthropic_verify.output.data.status == 'inactive' %}verified{% elsif steps.anthropic_inactive.output.status >= 200 and steps.anthropic_inactive.output.status < 300 %}submitted{% else %}failed{% endif %}"
- name: log_anthropic
type: console
with:
message: "anthropic revoke key_id={{ steps.set_context.output.key_id }} post_status={{ steps.anthropic_inactive.output.status }} verify_key_status={{ steps.anthropic_verify.output.data.status }} outcome={{ steps.anthropic_outcome.output.outcome }}"
- name: fail_anthropic_unverified
type: if
condition: 'not steps.anthropic_outcome.output.outcome: "verified"'
steps:
- name: fail_anthropic
type: workflow.fail
with:
message: "Anthropic key {{ steps.set_context.output.key_id }} was not verified inactive after the update."
else:
- name: openai_delete
type: http
connector-id: __install__.openai-admin-connector
with:
method: DELETE
path: /v1/organization/projects/{{ steps.set_context.output.project_id | url_encode }}/api_keys/{{ steps.set_context.output.key_id | url_encode }}
- name: openai_verify
type: http
connector-id: __install__.openai-admin-connector
on-failure:
continue: true
with:
method: GET
path: /v1/organization/projects/{{ steps.set_context.output.project_id | url_encode }}/api_keys/{{ steps.set_context.output.key_id | url_encode }}
- name: openai_outcome
type: data.set
with:
outcome: "{% if steps.openai_verify.error.message contains '[404]' %}verified{% else %}submitted{% endif %}"
- name: log_openai
type: console
with:
message: "openai revoke project={{ steps.set_context.output.project_id }} key_id={{ steps.set_context.output.key_id }} delete_status={{ steps.openai_delete.output.status }} verify_error={{ steps.openai_verify.error.message }} outcome={{ steps.openai_outcome.output.outcome }}"
- name: fail_openai_unverified
type: if
condition: 'not steps.openai_outcome.output.outcome: "verified"'
steps:
- name: fail_openai
type: workflow.fail
with:
message: "OpenAI key {{ steps.set_context.output.key_id }} was deleted, but the follow-up GET did not return 404."
else:
- name: log_approval_rejected
type: console
with:
message: "rejected - analyst declined revoke for provider={{ steps.set_context.output.provider }} key_id={{ steps.set_context.output.key_id }} outcome=rejected"
- name: fail_approval_rejected
type: workflow.fail
with:
message: "Analyst declined revoke for {{ steps.set_context.output.provider }} key {{ steps.set_context.output.key_id }}."