New to Kestra?
Use blueprints to kickstart your first workflows.
Audits AWS CloudTrail logs for unauthorized API access attempts, alerting SecOps teams on Slack when AccessDenied events exceed safety thresholds.
This blueprint acts as an automated cloud security sentinel for AWS environments. Scheduled hourly, it interrogates AWS CloudTrail event history via Boto3 to detect spikes in AccessDenied and UnauthorizedOperation API responses across IAM users and roles, alerting SecOps teams on Slack before credential compromise or privilege escalation attempts go unnoticed.
hourly_security_audit schedule trigger (io.kestra.plugin.core.trigger.Schedule) initiates the audit at the start of each hour.scan_unauthorized_api_calls task (io.kestra.plugin.scripts.python.Script) queries CloudTrail lookup_events, inspecting management calls within the configured lookback window and filtering for permission denial error codes.check_unauthorized_activity flowable task (io.kestra.plugin.core.flow.If) evaluates whether total unauthorized events meet or exceed the security threshold.notify_slack_secops (io.kestra.plugin.slack.notifications.SlackIncomingWebhook) dispatches an immediate incident notification with target region and count.log_security_nominal logs nominal security posture.export_security_manifest task tags the execution with searchable status labels.flowchart TD
A[Schedule: Hourly] --> B[scan_unauthorized_api_calls: Interrogate CloudTrail Events]
B --> C{Unauthorized Events >= Threshold?}
C -- Yes --> D[notify_slack_secops: Slack Incident Alert]
C -- No --> E[log_security_nominal: Log Nominal State]
D --> F[export_security_manifest: Execution Labels]
E --> F
| Name | Type | Default | Description |
|---|---|---|---|
aws_region |
STRING | us-east-1 |
Target AWS region for auditing CloudTrail event history. |
lookback_hours |
INT | 1 |
Number of hours in the lookback window for security event auditing. |
max_unauthorized_events_threshold |
INT | 5 |
Number of AccessDenied or UnauthorizedOperation events before triggering an alert. |
slack_channel |
STRING | #secops-security-alerts |
Slack channel destination for security operations and privilege escalation alerts. |
{{ outputs.scan_unauthorized_api_calls.vars.total_unauthorized_events }}: Count of unauthorized API calls detected during the audit window.{{ outputs.scan_unauthorized_api_calls.vars.has_security_incident }}: Boolean flag indicating if events exceeded safety threshold.{{ outputs.scan_unauthorized_api_calls.outputFiles['cloudtrail_unauthorized_report.json'] }}: Structured JSON security report detailing offending IAM users and event sources.cloudtrail:LookupEvents permissions.AWS_ACCESS_KEY_ID: AWS IAM access key ID.AWS_SECRET_ACCESS_KEY: AWS IAM secret access key.SLACK_WEBHOOK_URL: Slack Incoming Webhook endpoint URL.AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and SLACK_WEBHOOK_URL in your Kestra namespace secrets.aws_region.max_unauthorized_events_threshold to prevent alert fatigue.sts:AssumeRole grants across member accounts.update_access_key(Status='Inactive') when critical thresholds are breached.ForEach task.