id: securityhub-active-critical-finding-sentinel
namespace: company.team
description: |
Query AWS Security Hub for findings filtered server-side to CRITICAL or
HIGH severity and ACTIVE record state, classify the result HEALTHY or
ACTIVE_FINDINGS_DETECTED, and alert Slack with the exact titles and
severities when a real, unresolved finding exists.
triggers:
- id: periodic_finding_check
type: io.kestra.plugin.core.trigger.Schedule
description: "Checks every 30 minutes - Security Hub aggregates findings
continuously from every enabled source (GuardDuty, Inspector, Config, IAM
Access Analyzer, and its own standards checks), so a security-relevant
check benefits from a tighter cadence than a routine compliance sweep.
Shipped disabled; enable it once aws_region points at a real account with
Security Hub enabled and a manual run has been verified."
cron: "*/30 * * * *"
disabled: true
inputs:
aws_region: "us-east-1"
inputs:
- id: aws_region
type: STRING
displayName: "AWS Region"
defaults: "us-east-1"
description: "Region passed to io.kestra.plugin.aws.cli.AwsCLI as
AWS_DEFAULT_REGION. Security Hub is enabled per region."
tasks:
- id: probe_active_findings
type: io.kestra.plugin.aws.cli.AwsCLI
description: "get-findings's own --filters option does the severity and
record-state filtering server-side using Security Hub's own StringFilter
syntax (SeverityLabel, RecordState, each an array of {Comparison, Value}
objects) - all verified from AWS's own Security Hub GetFindings API
reference. Security Hub's own documented filter semantics apply OR logic
within the same attribute (CRITICAL or HIGH) and AND logic across
different attributes (severity AND record state), so this single filter
means CRITICAL-or-HIGH, and also ACTIVE. Unlike GuardDuty, get-findings
here returns full finding objects directly - no separate detail-fetch call
is needed."
accessKeyId: "{{ secret('AWS_ACCESS_KEY_ID') }}"
secretKeyId: "{{ secret('AWS_SECRET_ACCESS_KEY') }}"
region: "{{ inputs.aws_region }}"
commands:
- aws securityhub get-findings --filters
'{"SeverityLabel":[{"Comparison":"EQUALS","Value":"CRITICAL"},{"Comparison":"EQUALS","Value":"HIGH"}],"RecordState":[{"Comparison":"EQUALS","Value":"ACTIVE"}]}'
--output json | tr -d '\n' | xargs -0 -I {} echo '::{"outputs":{}}::'
- id: evaluate_findings_presence
type: io.kestra.plugin.core.flow.If
description: "ACTIVE_FINDINGS_DETECTED whenever the Findings list (verified from
Security Hub's own GetFindings API reference) has at least one entry -
since the server-side filter already restricts it to CRITICAL-or-HIGH
severity and ACTIVE record state, any entry at all means a real,
unresolved finding."
condition: "{{ outputs.probe_active_findings.vars.Findings is not empty }}"
then:
- id: alert_active_findings
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: "Always alert on ACTIVE_FINDINGS_DETECTED so an on-call engineer
sees the exact finding without opening the Security Hub console."
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{{ {
"text": "Security Hub finding sentinel: ACTIVE_FINDINGS_DETECTED in " ~ inputs.aws_region ~ ". " ~ (outputs.probe_active_findings.vars.Findings | length) ~ " active CRITICAL/HIGH finding(s): " ~ (outputs.probe_active_findings.vars.Findings | jq('map("[\(.SeverityLabel)] \(.Title)") | join("; ")') | first) ~ ". Execution " ~ execution.id ~ "."
} | toJson }}
else:
- id: log_no_active_findings
type: io.kestra.plugin.core.log.Log
message: "HEALTHY: no ACTIVE CRITICAL or HIGH severity findings in Security Hub
for {{ inputs.aws_region }}."
- id: log_audit_complete
type: io.kestra.plugin.core.log.Log
description: "Final status line for every run, independent of which branch fired."
message: "Finding audit complete for {{ inputs.aws_region }}.
active_finding_count={{ outputs.probe_active_findings.vars.Findings |
length }}."
errors:
- id: alert_execution_failure
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: "Alert when the flow itself fails outside the handled branches, for
example Security Hub not enabled in this region, an unreachable API, or
invalid credentials."
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{{ {
"text": "Security Hub finding sentinel FAILED in execution " ~ execution.id ~ " for region " ~ inputs.aws_region ~ ". get-findings did not complete; investigate before trusting the last known HEALTHY/ACTIVE_FINDINGS_DETECTED status."
} | toJson }}