|
| 1 | +# IAM Role Admin Privilege Monitor |
| 2 | + |
| 3 | +This project provides an automated way to **monitor IAM roles for privilege escalation**. It leverages AWS EventBridge, Lambda, and SNS to detect when IAM role permissions change and sends an alert if administrative privileges are added. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## Overview |
| 8 | + |
| 9 | +- **Input:** One or more IAM role names to monitor. |
| 10 | +- **Event Trigger:** AWS EventBridge rule that listens for `IAM Role Policy` changes. |
| 11 | +- **Detection:** A Lambda function (written in TypeScript) inspects the target role’s: |
| 12 | + - Inline policies |
| 13 | + - Attached custom policies |
| 14 | + - Attached managed policies |
| 15 | +- **Alerting:** If the role gains `AdministratorAccess` or wildcard permissions (`*` actions/resources), the Lambda publishes a message to the specified SNS topic. |
| 16 | + |
| 17 | +This helps prevent **unauthorized privilege escalation** in AWS accounts. |
| 18 | + |
| 19 | +--- |
| 20 | + |
| 21 | +## Architecture |
| 22 | + |
| 23 | +1. **Terraform Module** |
| 24 | + - Creates EventBridge rule for IAM role policy changes |
| 25 | + - Provisions a Lambda function with detection logic |
| 26 | + - Grants Lambda necessary IAM permissions |
| 27 | + - Connects Lambda to SNS topic for alerts |
| 28 | + |
| 29 | +2. **Lambda Function (TypeScript)** |
| 30 | + - Fetches IAM role policy details |
| 31 | + - Detects admin-like privileges |
| 32 | + - Publishes findings to SNS |
| 33 | + |
| 34 | +--- |
| 35 | + |
| 36 | +## Project Structure |
| 37 | + |
| 38 | +. |
| 39 | +├── main.tf # Root module entrypoint |
| 40 | +├── iam.tf # IAM permissions for Lambda |
| 41 | +├── lambda.tf # Lambda packaging and deployment |
| 42 | +├── cw_events.tf # CloudWatch / EventBridge rules |
| 43 | +├── outputs.tf # Module outputs |
| 44 | +├── variables.tf # Input variables |
| 45 | +├── versions.tf # Provider versions |
| 46 | +└── lambda/ |
| 47 | + |
| 48 | +--- |
| 49 | + |
| 50 | +## Inputs |
| 51 | + |
| 52 | +| Variable | Type | Description | |
| 53 | +| --------------- | -------------- | --------------------------------------------------------------- | |
| 54 | +| `role_names` | `list(string)` | List of IAM role names to monitor (e.g. `["role_A", "role_B"]`) | |
| 55 | +| `sns_topic_arn` | `string` | ARN of an existing SNS topic to publish alerts | |
| 56 | + |
| 57 | +--- |
| 58 | + |
| 59 | +## Outputs |
| 60 | + |
| 61 | +| Output | Description | |
| 62 | +| ------------- | ---------------------------------------------------- | |
| 63 | +| `lambda_name` | Name of the monitoring Lambda function | |
| 64 | +| `rule_arn` | ARN of the EventBridge rule that triggers the Lambda | |
| 65 | + |
| 66 | +--- |
| 67 | + |
| 68 | +## Usage |
| 69 | + |
| 70 | +Example Terraform configuration: |
| 71 | + |
| 72 | +```hcl |
| 73 | +module "iam_role_alerts" { |
| 74 | + source = "<path_to_this_repository_and_version>" |
| 75 | + sns_topic_arn = aws_sns_topic.role_policy_alerts.arn |
| 76 | + role_names = ["my-infra-apply-role", "my-infra-plan-role"] |
| 77 | +} |
| 78 | +``` |
0 commit comments