Blog

Four AWS containment workflows that run on one analyst approval

AWS remediation runs from the alert, with no Lambda in between. Elastic Workflows signs its own AWS API calls, deactivates IAM keys, quarantines EC2 interfaces, restarts CloudTrail or blocks public S3, then checks AWS to confirm the change.

Elastic Workflows now signs its own AWS API requests. One step, aws.request, reaches AWS Identity and Access Management (IAM), Amazon Elastic Compute Cloud (EC2), Amazon Simple Storage Service (S3), AWS CloudTrail, Amazon CloudWatch Logs, Amazon GuardDuty, and AWS Security Hub in Elastic 9.7, with no AWS Lambda function to deploy or maintain.

We used it to publish four AWS remediation workflows in the Elastic Workflows Template Library: 

  • Deactivate a compromised IAM access key.

  • Quarantine an EC2 network interface.

  • Restart a stopped CloudTrail.

  • Apply all four S3 Block Public Access controls. 

Each one pulls its target from the alert and shows an analyst the exact action against current AWS state. Nothing changes until that analyst approves the action. The workflow then reads the target back from AWS, and the execution fails if the state is wrong.

Key takeaways

  • Elastic Security alerts can supply AWS resource context directly to a remediation workflow.

  • A human-in-the-loop (HITL) gate keeps an analyst in control before a consequential cloud change.

  • A dedicated, least-privilege connector limits what each workflow can modify.

  • Approved mutations are followed by AWS read-back and explicit verification.

  • Across IAM, EC2, CloudTrail, and S3, invalid targets and unsuccessful verification fail visibly instead of appearing as successful remediation.

The AWS connector signs any AWS API call

Until now, getting a workflow in Elastic Workflows to act in AWS meant one of two things:

  • We had a connector for that specific service, like Lambda or CloudWatch.

  • Or you deployed a Lambda function in your own account to make the call for you. 

The second option works, but it’s one more piece of code to deploy and secure, as well as maintain, before the workflow can do anything.

The reason is request authentication; that is, AWS API requests made with IAM credentials must be signed with AWS Signature Version 4 (SigV4), using the credentials, request contents, and current time. An unauthenticated HTTP session cannot do that for you.

The new AWS connector works by letting you store a valid AWS access key ID and secret access key once, and every request a workflow sends through the connector is signed for you. It isn't tied to one service; IAM, EC2, S3, CloudTrail, CloudWatch Logs, Security Hub, GuardDuty, or other AWS service APIs can be called through the same connector.

To set it up, create an AWS connector in Kibana and paste in the keys. The Test button sends an AWS Security Token Service (STS) API call for GetCallerIdentity (basically, AWS Who am I?), so you know that the keys work before any workflow runs:

Successful test execution of the AWS connector in Kibana showing STS GetCallerIdentity verification.

In Workflows, the connector is a single step, aws.request, and it’s available starting with Elastic 9.7. The step is built in, so there’s nothing else to install or deploy.

How do I call an AWS API from Workflows?

You describe the AWS call in YAML, as an aws.request step in your workflow. If you’re new to Workflows, you can start with Building automation with Elastic Workflows. The step builds the URL and signs the request, and then it sends it. You can set the following fields:

  • service: The AWS service, as it appears in its hostname; for example, iam, ec2, s3, or logs.

  • region: For example, us-east-1. Leave it out for global services, like IAM.

  • method: GET (the default), POST, PUT, PATCH, DELETE, or HEAD.

  • path: The request path. It defaults to /.

  • query: Query string parameters.

  • headers: Extra headers, such as the Content-Type and X-Amz-Target that JSON APIs need.

  • body: Text is sent as is. Anything else, like a YAML object, is sent as JSON.

  • signingName: Rarely needed. A few APIs sign under a different name than their hostname. For example, bedrock-runtime signs as bedrock.

With a region, the request goes to https://{service}.{region}.amazonaws.com{path}. Without one, it goes to https://{service}.amazonaws.com{path}.

AWS APIs come in three styles. Here’s what each one looks like in the Workflows YAML format for aws.request:

API style

Operation named by

Parameters go in

Response

Example services

Action-style

Action query parameter

Query string

XML (returned as text)

IAM, STS, EC2

JSON

X-Amz-Target header

JSON body

JSON (parsed)

CloudWatch Logs, CloudTrail

REST-style

HTTP method and path

Path and body

XML (returned as text)

S3

Action-style AWS APIs (IAM, STS, EC2)

Older APIs take an Actionand a Version, along with the parameters for that action. This step lists the access keys of the user from the alert:

- name: list_access_keys
  type: aws.request
  connector-id: "REPLACE_WITH_AWS_CONNECTOR_ID"
  with:
    service: iam
    query:
      Action: ListAccessKeys
      Version: "2010-05-08"
      UserName: "{{ event.alerts[0].user.name }}"

JSON AWS APIs (CloudWatch Logs, CloudTrail)

Newer APIs take a JSON body and name the operation in the X-Amz-Target header. This step lists five log groups:

- name: list_log_groups
  type: aws.request
  connector-id: "REPLACE_WITH_AWS_CONNECTOR_ID"
  with:
    service: logs
    region: us-east-1
    method: POST
    headers:
      Content-Type: application/x-amz-json-1.1
      X-Amz-Target: Logs_20140328.DescribeLogGroups
    body:
      limit: 5

REST-style AWS APIs (S3)

REST-style APIs, like S3, use the method and path instead. The following S3 workflow shows an example.

What an aws.request step returns

An aws.request step returns the response status, headers, and data. JSON responses are parsed by aws.request, so later steps can read fields directly; for example, {{ steps.list_log_groups.output.data.logGroups[0].logGroupName }}. XML responses, such as EC2's, come back as text.

If AWS rejects the request (for example, with AccessDenied or a throttling error), the step fails with AWS's own error message. That means on-failure retries and error handling work the same as for any other step.

A repeatable AWS remediation pattern

The published workflows validate targets before they reach AWS, require approval, limit each mutation, and verify the result. If an approved action cannot be verified, the execution fails.

  1. Resolve resource identifiers and account or Region context from the alert or manual input.

  2. Fail closed when the target cannot be established safely.

  3. Read current state, and present the exact proposed action to an analyst.

  4. Require an explicit approval before mutation.

  5. Send a SigV4-signed request through a least-privilege AWS connector.

  6. Read the resulting AWS state, retrying only where eventual consistency requires it.

  7. Assert the expected state and retain decisions, responses, and failures in execution history.

Overview of the seven-step repeatable AWS response workflow sequence, from context resolution to state verification and audit logging.

Before you enable an AWS remediation workflow

Install each workflow from the Elastic Workflow Template Library, and select an AWS connector during installation. Use a dedicated remediation identity rather than administrator credentials. Scope its policy to the actions and resources that the workflow is allowed to modify.

Covering multiple AWS accounts

Each AWS connector works in one AWS account. It signs every call with one IAM user's long-term access keys, which are stored in Kibana, and it can't switch to a role in another account. To cover several accounts, you have two options:

  • Install each workflow once per account, and pick that account's connector during installation.

  • Or keep one workflow, and add an if step per account that picks the connector from the alert's account ID. For example, in the CloudTrail workflow:

- name: production_account
  type: if
  condition: "${{ event.alerts[0].aws.cloudtrail.recipient_account_id == '111111111111' }}"
  steps:
    - name: start_logging_production
      type: aws.request
      connector-id: "PRODUCTION_ACCOUNT_CONNECTOR_ID"
      with:
        service: cloudtrail
        region: "{{ event.alerts[0].cloud.region }}"
        method: POST
        headers:
          Content-Type: application/x-amz-json-1.1
          X-Amz-Target: CloudTrail_20131101.StartLogging
        body:
          Name: "{{ event.alerts[0].aws.cloudtrail.flattened.request_parameters.name }}"

Add one block like this for every account, each with that account's connector. Add a final check that fails the run when no account matches, so an alert from an account without a connector doesn't go unnoticed.

Required alert fields by workflow

Workflow

Target

Required alert fields

AWS permissions

Deactivate IAM access key

AKIA long-term user key

user.name, aws.cloudtrail.user_identity.access_key_id

iam:UpdateAccessKey, iam:ListAccessKeys

Quarantine EC2 network interface

Elastic Network Interface (ENI) in the configured Amazon Virtual Private Cloud (VPC)

aws.vpcflow.interface_id or aws.cloudtrail.flattened.request_parameters.networkInterfaceId, plus cloud.region

ec2:ModifyNetworkInterfaceAttribute, ec2:DescribeNetworkInterfaces

Restore CloudTrail logging

Trail, by account-qualified Amazon Resource Name (ARN)

aws.cloudtrail.flattened.request_parameters.name, aws.cloudtrail.recipient_account_id, cloud.region

cloudtrail:StartLogging, cloudtrail:GetTrailStatus

Block public S3 access

Bucket, owner-bound

aws.cloudtrail.flattened.request_parameters.bucketName, aws.cloudtrail.recipient_account_id, cloud.region

s3:PutBucketPublicAccessBlock, s3:GetBucketPublicAccessBlock

Only long-term AKIA IAM user keys are supported. ASIA session credentials require session revocation instead.

The IAM, EC2, and S3 workflows process the first alert in an execution. The CloudTrail workflow processes the complete alert batch, normalizes names and ARNs, groups duplicate alerts by canonical trail ARN, and requests approval for each distinct trail.

Field availability depends on the source detection rule and integration version. Validate the required values before enabling a workflow as a rule action. If a field is absent, enrich the alert or use a reviewed manual execution. Don’t infer resource identifiers from untrusted text.

For alert-driven CloudTrail and S3 remediation, and for EC2 when the network interface ID comes from a CloudTrail event, CloudTrail request parameters must be retained in flattened form. EC2 alerts that use aws.vpcflow.interface_id don't depend on this setting. The S3 workflow deliberately doesn’t parse the keyword representation.

EC2 isolation security group and VPC requirements

The EC2 workflow requires, at installation:

  • A pre-created isolation security group with no inbound or outbound rules.

  • The ID of that security group’s VPC. 

The workflow verifies that the target ENI belongs to the configured VPC before requesting approval. Therefore, one installation supports one VPC. For multiple VPCs, install a separate workflow copy with a VPC-local isolation security group for each VPC. The workflow doesn’t currently support a VPC-to-security-group mapping. The isolation group should have no inbound or outbound rules. Prepare and review it before an incident instead of creating it dynamically during containment.

Elastic Security Workflows UI showing available AWS remediation workflow templates for S3, CloudTrail, EC2, and IAM.

Deactivate a compromised IAM access key

Imagine that a detection identifies an IAM access key used from an unusual location. Deleting the key immediately may disrupt an investigation or workload. Setting it to inactive stops further use while preserving the key record for review and rollback.

The workflow supports long-term IAM user access keys whose IDs begin with AKIA. It rejects temporary ASIA credentials before making an IAM request and directs the analyst toward session revocation. Unrecognized identifiers fail with guidance to correct or recheck the input.

For a supported key, the workflow lists the user’s access keys and displays the parsed response. It then waits for approval. After UpdateAccessKey, it retries ListAccessKeys up to three times to accommodate eventual consistency. The execution succeeds only when the exact target key is confirmed inactive.

Get the workflow at Deactivate AWS IAM Access Key.

IAM permissions and rollback

  • Grant iam:UpdateAccessKey and iam:ListAccessKeys on the approved IAM user ARN.

  • Optionally, grant iam:GetAccessKeyLastUsed on * if the workflow is extended to show last-use context before approval.

To roll back, if the investigation concludes that the key is safe, a separately approved workflow can call UpdateAccessKey with Status: Active. Prefer key rotation over reactivation when compromise remains possible.

Visual workflow graph and approval request step details for deactivating a targeted AWS IAM access key.

Workflow visual graph and execution run view for deactivating an IAM access key.

Quarantine an EC2 workload at its network interface

Shutting down a compromised EC2 instance can destroy volatile evidence or interrupt a critical service. It can even trigger automated replacement. The workflow instead replaces the network interface's complete security-group set with a pre-created isolation group. The instance stays available for investigation while the isolation group blocks new network activity.

The workflow verifies that the target ENI belongs to the configured isolation VPC before requesting approval. It then reads the ENI again and shows the refreshed security-group state. It requires final confirmation, after which it reads the ENI one more time and compares a canonicalized security-group set with the approved state. If the set changed or cannot be parsed, the workflow aborts without mutation.

The final read narrows but cannot eliminate the nonatomic interval before ModifyNetworkInterfaceAttribute. AWS doesn’t provide a compare-and-swap operation for this change, so coordinating with other ENI writers when preserving concurrent changes is a hard requirement.

Security-group replacement doesn’t guarantee immediate termination of established tracked connections. A network access control list (ACL) deny can block traffic that crosses subnet boundaries, but it doesn’t affect same-subnet traffic. Use an operating-system or host-level action when same-subnet sessions must be interrupted immediately.

Get the workflow at Quarantine AWS EC2 Network Interface.

EC2 permissions and rollback

  • Grant ec2:ModifyNetworkInterfaceAttribute on the approved target ENI and isolation security group.

  • Grant ec2:DescribeNetworkInterfaces on *, because EC2 Describe actions don’t support resource-level permissions.

The workflow records the DescribeNetworkInterfaces response captured immediately before mutation as the rollback source. Preserve that evidence in an Elastic case or another controlled incident record, and restore exactly that reviewed security-group set after eradication. Don’t assume that the launch-time groups are still correct.

Workflow graph and pending analyst approval details for EC2 network interface isolation and VPC verification.

Workflow graph and step execution log showing EC2 network interface quarantine and security group replacement.

Restart stopped CloudTrail logging

Disabling a trail is a common defense-evasion objective because it creates an audit gap without deleting the trail configuration. When a detection identifies StopLogging, the response can be direct: resolve the affected trail, inspect its status, request approval, call StartLogging, and verify GetTrailStatus.

The production workflow processes the entire alert batch. It normalizes bare names and ARNs into account-qualified trail ARNs and groups duplicate alerts for the same trail into one decision. It also keeps identically named trails that are in different accounts separate. A trail outside the connector's account fails with an AWS error instead of being changed. Organization trails can only be restarted from the management account or a delegated administrator account. Invalid targets are recorded before any valid target enters an AWS request or approval wait.

Each valid trail receives its own approval. Verification failures are accumulated rather than stopping the loop, allowing later targets to be processed. After all targets are handled, the execution fails if any target was invalid or any approved restoration was not verified.

Get the workflow at Restore AWS CloudTrail Logging.

CloudTrail permissions and rollback

  • Grant cloudtrail:StartLogging.

  • Grant cloudtrail:GetTrailStatus.

Scope both actions to approved trail ARNs. Starting a trail doesn’t recover events lost while logging was stopped, so the incident timeline should preserve the beginning and end of the audit gap.

There’s normally no defensive reason to stop logging again. If the workflow targeted the wrong disposable or migration trail, use a separately reviewed action instead of embedding automatic rollback.

Workflow graph displaying the iteration loop and approval prompt for restoring AWS CloudTrail logging on stopped trails.

Execution flow and step details for restoring AWS CloudTrail logging following a StopLogging alert.

Apply S3 Block Public Access to an exposed bucket

An S3 bucket can become exposed through a policy or an ACL. It can also become exposed through a change to its public-access settings. Applying all four Block Public Access controls creates an immediate containment boundary while responders investigate bucket policy, ACLs, access points, and object-level permissions.

Alert-driven runs require the AWS integration's request-parameter retention mode to be All or Flattened. The workflow reads the bucket name only from flattened request parameters and fails closed when that field is unavailable. It doesn’t parse the attacker-influenced keyword representation.

The expected bucket owner comes from aws.cloudtrail.recipient_account_id, not the caller’s cloud.account.id. Every S3 read and write includes x-amz-expected-bucket-owner, binding the action to the reviewed resource account. If the bucket belongs to a different account, AWS rejects the call. Manual runs require an explicit owner.

The workflow distinguishes a missing Block Public Access configuration from other pre-read errors, requires approval, applies all four controls, and then parses the follow-up XML and verifies that every control is true. Missing targets and unsafe pre-read errors, as well as unsuccessful verification, fail the execution.

Get the workflow at Block Public Access to AWS S3 Bucket.

S3 permissions and rollback

  • Grant s3:PutBucketPublicAccessBlock.

  • Grant s3:GetBucketPublicAccessBlock.

Scope both actions to the approved bucket ARN. Block Public Access doesn’t remove a risky bucket policy or ACL; it prevents those configurations from granting public access. Continue the investigation, and remove the underlying exposure.

When rolling back, preserve the original four settings in the incident record. Restore them only when public access is an approved business requirement and when the bucket policy, ACLs, access points, and account-level controls have been reviewed.

Workflow diagram and approval prompt displaying the pre-change S3 Block Public Access configuration state.

Workflow graph and detailed status for applying Block Public Access controls to an S3 bucket.

Guardrails for AWS remediation in production

Approval, least privilege, target validation, and explicit verification turn a powerful API call into a defensible response process.

  • Use a dedicated connector identity for remediation. Don’t store administrator credentials in the connector.

  • Restrict resource-level actions to approved ARNs. Keep wildcard permissions only for AWS APIs, such as some Describe actions, that don’t support resource scoping.

  • Validate account, Region, resource identifiers, and credential type before presenting approval.

  • Show the analyst the exact action, target, account context, and current state, not only the alert title.

  • Read the resource state back after mutation. A successful HTTP response alone isn’t sufficient evidence of the desired state.

  • Use bounded retries only for transient behavior, such as eventual consistency. Don’t retry authorization failures or invalid targets indefinitely.

  • Capture immediate pre-change state for reversible actions, especially EC2 security-group replacement and S3 public-access settings.

  • Keep rejected decisions and failed executions visible. They’re operational evidence, not noise.

  • Coordinate with other infrastructure writers when AWS doesn’t offer atomic conditional mutation.

  • Test each workflow in a disposable account before attaching it to a production rule.

Start with one detection in a disposable account

Calling the AWS API is the easy part. A production response also has to carry the correct alert fields, show an analyst the exact target, limit the connector's permissions, and prove that AWS reached the requested state. These workflows keep those decisions and result in one execution record.

The implementation differs by service. IAM requires eventual-consistency retries. EC2 relies on a final comparison before mutation. CloudTrail calls for account-qualified deduplication across an alert batch. S3 needs explicit owner binding and XML verification. The common sequence is still straightforward: establish the resource, approve the target, make the smallest necessary change, and assert the result.

Start with one detection and one low-risk containment action in a disposable account. Test the alert fields, connector permissions, rejection path, verification logic, concurrency assumptions, and rollback evidence before attaching the workflow to a production rule.

About Elastic Security Labs

Elastic Security Labs is the threat intelligence branch of Elastic Security dedicated to creating positive change in the threat landscape. Elastic Security Labs provides publicly available research on emerging threats, with an analysis of strategic, operational, and tactical adversary objectives, and then integrates that research with the built-in detection and response capabilities of Elastic Security.

Follow Elastic Security Labs on Twitter @elasticseclabs, and check out our research.

How helpful was this content?

From posture to root cause: Investigate OpenShift compliance with Elastic Agent Builder

From posture to root cause: Investigate OpenShift compliance with Elastic Agent Builder

Anand Vyas
Azure AD Graph Activity Logs: Ingestion and threat detection to close the visibility gap

Azure AD Graph Activity Logs: Ingestion and threat detection to close the visibility gap

Terrance DeJesus
Microsoft Entra ID OAuth Phishing and Detections

Microsoft Entra ID OAuth Phishing and Detections

Terrance DeJesus
Exploring AWS STS AssumeRoot

Exploring AWS STS AssumeRoot

Terrance DeJesus
Monitoring Okta threats with Elastic Security

Monitoring Okta threats with Elastic Security

Terrance DeJesus

Elastic Security Labs Newsletter