# hkb-forward-cloudtrail

Fires on: CloudTrail stop, delete and update.

Run the [common pre-checks](/wiki/runbooks/#common-pre-checks) first.

## Symptoms
An email from `hkb security alert`: `SECURITY EVENT aws.cloudtrail <call> in account <member>`. Something tried to stop, delete or change a trail.

## Pre-checks
1. Read `errorCode` first. The organization trail belongs to Control Tower, and SCP-03 denies these calls to everything but the Control Tower and StackSets execution roles. A denied call is the guardrail working.
2. A successful call from `AWSControlTowerExecution` during a landing zone update is expected (that update raises its own alert).

## Resolution
- **Denied:** identify the caller and why it tried.
- **Succeeded, not Control Tower:** the audit record may have a gap. Check the trail is logging (`aws cloudtrail get-trail-status`), then re-register the OU in Control Tower to restore the trail, and compare the Log Archive replica (Object Lock) with the primary bucket for the gap's time range.

## Post-checks
The organization trail shows `IsLogging` true in both Regions, and the control tests' log checks pass.

## Rollback
Control Tower re-registration restores the trail as it manages it.

## Alert details

| Property | Value |
| --- | --- |
| Runs in | every member account, both Regions, forwarded to the `hkb-security-events` bus in Security |
| Email | From `hkb security alert`: `SECURITY EVENT <src> <what> in account <account>, <region>, at <time> by <who>.` |
| Source | `baseline/hkb-baseline-events.yaml`, resource `CloudTrailRule` |

The event pattern, as deployed:

```yaml
EventPattern:
  source: [aws.cloudtrail]
  detail-type: [AWS API Call via CloudTrail]
  detail:
    eventSource: [cloudtrail.amazonaws.com]
    eventName: [StopLogging, DeleteTrail, UpdateTrail, PutEventSelectors]
```
