# hkb-alert-org-policy-change

Fires on: Organizations policy attach, detach, update or delete (SCPs, RCPs and others).

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

## Symptoms
An email from `hkb master alert`: `Organizations AttachPolicy` (or Detach, Update, Delete) with the caller's ARN. The message itself says this is expected during reviewed change sets.

## Pre-checks
1. Was a reviewed change set run just now? The `hkb-org-*` stacks are the only intended source of these calls, executed by hand by HKB-MasterAdmin through the CloudFormation role.
2. Check the caller: a change through CloudFormation shows `invokedBy` `cloudformation.amazonaws.com`. A call with no `invokedBy` came straight from a person's session, and the HKB-MasterAdmin direct-write alert will have fired as well.
3. List what's attached now: `aws organizations list-policies-for-target --profile ro-hkb-master --target-id <root, OU or account> --filter SERVICE_CONTROL_POLICY`.

## Resolution
- **Matches a reviewed change set:** nothing to do.
- **Doesn't match:** run the control tests. INV-11 compares the deployed templates in the management, Shared Services and Security accounts, and the StackSets, with the repository, and the policy checks report any statement missing. Restore the policy by updating its stack from the repository (a reviewed change set), never by hand-editing the policy.

## Post-checks
`verify/hkb-verify.sh` passes the organization policy checks and INV-11 shows no difference for the `hkb-org-*` stacks.

## Rollback
A stack update from the repository is the rollback. If the change set itself was wrong, revert the PR and run a new change set from the reverted commit.

## Alert details

| Property | Value |
| --- | --- |
| Runs in | the management account, us-east-1 |
| Email | From `hkb master alert`: `Organizations <what> at <time> by <who>. Expected during reviewed change sets; investigate otherwise.` |
| Source | `security/hkb-security-master-alerts.yaml`, resource `OrganizationsPolicyRule` |

The event pattern, as deployed:

```yaml
EventPattern:
  source: [aws.organizations]
  detail-type: [AWS API Call via CloudTrail]
  detail:
    eventSource: [organizations.amazonaws.com]
    eventName: [AttachPolicy, DetachPolicy, UpdatePolicy, DeletePolicy]
```
