# hydrojak/aws-cloud-hardening-baseline architecture

> Architecture diagram of the GitHub repository hydrojak/aws-cloud-hardening-baseline, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hydrojak/aws-cloud-hardening-baseline
- Repository: https://github.com/hydrojak/aws-cloud-hardening-baseline

## Overview

1. **Project shape**
   - This is a Terraform-only AWS security baseline, not an application runtime.
   - The root `terraform/main.tf` composes small modules that each own one security control area: hardening, logging, detection, alerting, optional remediation, and optional org-wide enforcement.

2. **Control plane boundary**
   - Terraform is the only deployment mechanism.
   - The repo’s architecture is split into reusable Terraform modules with clear AWS service boundaries; most modules create one service domain and expose outputs for wiring into later modules.

3. **Preventive hardening layer**
   - `iam-baseline` establishes account-level IAM hygiene: password policy and IAM Access Analyzer.
   - `s3-guardrails` attaches explicit-deny IAM policies to a user or role to prevent public S3 exposure and disabling S3 Public Access Block.
   - `organizations-scp` optionally extends prevention to the AWS Organizations boundary with SCPs that block CloudTrail tampering and S3 guardrail bypasses.

4. **Audit logging core**
   - `cloudtrail-logging` is the logging foundation.
   - It creates a hardened S3 bucket for CloudTrail logs and configures CloudTrail for management events, with options for multi-region, organization trails, log file validation, lifecycle expiration, and optional SSE-KMS.
   - The bucket policy uses strict source-account/source-ARN conditions to reduce confused-deputy risk.

5. **Detection ingestion path**
   - `detection-eventbridge` is the main event intake layer.
   - It converts CloudTrail-derived security-relevant events into EventBridge rules and forwards them to the centralized detections log group.
   - It can also invoke the remediation Lambda when CloudTrail tampering is detected.

6. **Centralized detections store**
   - `alerting-cloudwatch` creates the dedicated CloudWatch Logs group used as the single sink for detection events.
   - This log group is the convergence point for multiple sources: CloudTrail tampering, IAM changes, credential creation, S3 exposure attempts, and optional GuardDuty/Security Hub findings.

7. **Alerting pipeline**
   - `alerting-alarms` turns detections into CloudWatch metric filters and alarms.
   - Each detection class becomes a metric, then an alarm, which can notify an SNS topic if configured.
   - `alerting-sns` is optional and provides the notification endpoint; the design also allows using an existing SNS topic instead of creating one.

8. **Optional managed-security integrations**
   - `guardduty-integration` can enable GuardDuty and forward high-severity findings into the same detections log group.
   - `securityhub-integration` does the same for imported Security Hub findings.
   - These are intentionally isolated modules so the core baseline stays cost-conscious when they are disabled.

9. **Optional automated remediation**
   - `remediation-cloudtrail` contains a Python Lambda (`lambda/index.py`) plus its IAM role/policies.
   - It is triggered by EventBridge and is scoped narrowly to restoring CloudTrail settings, such as re-enabling logging or reapplying expected selectors.
   - The repo treats remediation as optional and conservative, keeping it separate from detection and alerting.

10. **Data flow through the system**
   - Hardening controls reduce the attack surface first.
   - CloudTrail records management activity, EventBridge detects suspicious security events, detections are written to CloudWatch Logs, metric filters convert them to metrics, alarms fire, and SNS optionally delivers notifications.
   - Optional GuardDuty/Security Hub signals are normalized into the same log-and-alarm pipeline, which keeps alert handling consistent across sources.

11. **Organization-wide vs account-scoped boundaries**
   - Most modules are account-scoped and can be deployed in a lab or single account.
   - SCPs require AWS Organizations management-account access, so they sit at a higher governance boundary than the rest of the baseline.
   - The README also notes that guardrails may need to be attached after deployment to avoid blocking Terraform itself.

12. **Cost and operational posture**
   - The architecture is intentionally minimal: CloudTrail management events, CloudWatch Logs, EventBridge, SNS, and Lambda are the main runtime services.
   - GuardDuty, Security Hub, CloudTrail data events, and KMS are optional because they can materially change cost.
   - No EC2, NAT, OpenSearch, or SIEM stack is part of the baseline.

13. **Documentation as architecture contract**
   - The `docs/` folder captures detection logic, CIS mapping, hardening decisions, security maturity, and operational/testing guidance.
   - For diagramming, this means the repo is not just infrastructure code; it also defines the control intent and the expected security event flows.

Main entry points: [`terraform/main.tf`](https://github.com/hydrojak/aws-cloud-hardening-baseline/blob/main/terraform/main.tf) (Root stack), [`terraform/modules/alerting-cloudwatch/main.tf`](https://github.com/hydrojak/aws-cloud-hardening-baseline/blob/main/terraform/modules/alerting-cloudwatch/main.tf) (Detections log), [`terraform/modules/detection-eventbridge/main.tf`](https://github.com/hydrojak/aws-cloud-hardening-baseline/blob/main/terraform/modules/detection-eventbridge/main.tf) (EventBridge rules), [`terraform/modules/alerting-alarms/main.tf`](https://github.com/hydrojak/aws-cloud-hardening-baseline/blob/main/terraform/modules/alerting-alarms/main.tf) (Alarm filters)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_terraform["Terraform baseline"]
  node_root["Root stack<br/>terraform-compose<br/>[main.tf]"]
  node_iam_baseline["IAM baseline<br/>hardening<br/>[main.tf]"]
  node_s3_guardrails["S3 guardrails<br/>hardening<br/>[main.tf]"]
  node_s3_account["S3 baseline<br/>account-hardening<br/>[main.tf]"]
  node_org_scp["Org SCPs<br/>governance<br/>[main.tf]"]
  node_cloudtrail[("CloudTrail logs<br/>audit-logging<br/>[main.tf]")]
  node_eventbridge["EventBridge rules<br/>detection-ingest<br/>[main.tf]"]
  node_cw_logs[("Detections log<br/>log-sink<br/>[main.tf]")]
  node_alarms["Alarm filters<br/>alerting<br/>[main.tf]"]
  node_sns(("SNS notify<br/>notification<br/>[main.tf]"))
end

subgraph group_optional["Optional modules"]
  node_remediation["CloudTrail fix<br/>lambda-remediation<br/>[main.tf]"]
  node_lambda_code["Lambda code<br/>python-handler<br/>[index.py]"]
  node_guardduty["GuardDuty ingest<br/>security-findings<br/>[main.tf]"]
  node_securityhub["Security Hub ingest<br/>security-findings<br/>[main.tf]"]
end

subgraph group_docs["Documentation"]
  node_docs_detection["Detection docs<br/>[detection.md]"]
  node_docs_hardening["Hardening docs"]
  node_docs_ops["Ops guide<br/>docs"]
end

node_root -->|"compose"| node_iam_baseline
node_root -->|"compose"| node_s3_account
node_root -->|"compose"| node_s3_guardrails
node_root -->|"compose"| node_cloudtrail
node_root -->|"compose"| node_eventbridge
node_root -->|"compose"| node_cw_logs
node_root -->|"compose"| node_alarms
node_root -->|"compose"| node_sns
node_root -.->|"optional"| node_org_scp
node_root -.->|"optional"| node_remediation
node_root -.->|"optional"| node_guardduty
node_root -.->|"optional"| node_securityhub
node_cloudtrail -->|"events"| node_eventbridge
node_cloudtrail -->|"logs"| node_cw_logs
node_eventbridge -->|"forward"| node_cw_logs
node_eventbridge -->|"invoke"| node_remediation
node_guardduty -->|"forward"| node_cw_logs
node_securityhub -->|"forward"| node_cw_logs
node_cw_logs -->|"metric filters"| node_alarms
node_alarms -->|"notify"| node_sns
node_remediation -->|"implements"| node_lambda_code
node_docs_detection -.->|"describes"| node_eventbridge
node_docs_hardening -.->|"describes"| node_iam_baseline
node_docs_ops -.->|"operates"| node_alarms

click node_root "https://github.com/hydrojak/aws-cloud-hardening-baseline/blob/main/terraform/main.tf"
click node_iam_baseline "https://github.com/hydrojak/aws-cloud-hardening-baseline/blob/main/terraform/modules/iam-baseline/main.tf"
click node_s3_guardrails "https://github.com/hydrojak/aws-cloud-hardening-baseline/blob/main/terraform/modules/s3-guardrails/main.tf"
click node_s3_account "https://github.com/hydrojak/aws-cloud-hardening-baseline/blob/main/terraform/modules/s3-account-baseline/main.tf"
click node_org_scp "https://github.com/hydrojak/aws-cloud-hardening-baseline/blob/main/terraform/modules/organizations-scp/main.tf"
click node_cloudtrail "https://github.com/hydrojak/aws-cloud-hardening-baseline/blob/main/terraform/modules/cloudtrail-logging/main.tf"
click node_eventbridge "https://github.com/hydrojak/aws-cloud-hardening-baseline/blob/main/terraform/modules/detection-eventbridge/main.tf"
click node_cw_logs "https://github.com/hydrojak/aws-cloud-hardening-baseline/blob/main/terraform/modules/alerting-cloudwatch/main.tf"
click node_alarms "https://github.com/hydrojak/aws-cloud-hardening-baseline/blob/main/terraform/modules/alerting-alarms/main.tf"
click node_sns "https://github.com/hydrojak/aws-cloud-hardening-baseline/blob/main/terraform/modules/alerting-sns/main.tf"
click node_remediation "https://github.com/hydrojak/aws-cloud-hardening-baseline/blob/main/terraform/modules/remediation-cloudtrail/main.tf"
click node_lambda_code "https://github.com/hydrojak/aws-cloud-hardening-baseline/blob/main/terraform/modules/remediation-cloudtrail/lambda/index.py"
click node_guardduty "https://github.com/hydrojak/aws-cloud-hardening-baseline/blob/main/terraform/modules/guardduty-integration/main.tf"
click node_securityhub "https://github.com/hydrojak/aws-cloud-hardening-baseline/blob/main/terraform/modules/securityhub-integration/main.tf"
click node_docs_detection "https://github.com/hydrojak/aws-cloud-hardening-baseline/blob/main/docs/detection.md"
click node_docs_hardening "https://github.com/hydrojak/aws-cloud-hardening-baseline/blob/main/docs/hardening-decisions.md"
click node_docs_ops "https://github.com/hydrojak/aws-cloud-hardening-baseline/blob/main/docs/Security_operation.md"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_root,node_iam_baseline,node_s3_guardrails,node_s3_account,node_org_scp,node_cloudtrail,node_eventbridge,node_cw_logs,node_alarms,node_sns toneBlue
class node_remediation,node_lambda_code,node_guardduty,node_securityhub toneAmber
class node_docs_detection,node_docs_hardening,node_docs_ops toneMint
```

## Components

### Terraform baseline

Core account-scoped security controls composed by the root Terraform stack.

- [Root stack](https://github.com/hydrojak/aws-cloud-hardening-baseline/blob/main/terraform/main.tf): terraform-compose · Top-level Terraform composition that wires the security baseline modules together. · `terraform/main.tf`
- [IAM baseline](https://github.com/hydrojak/aws-cloud-hardening-baseline/blob/main/terraform/modules/iam-baseline/main.tf): hardening · Sets account IAM hygiene such as password policy and IAM Access Analyzer. · `terraform/modules/iam-baseline/main.tf`
- [S3 guardrails](https://github.com/hydrojak/aws-cloud-hardening-baseline/blob/main/terraform/modules/s3-guardrails/main.tf): hardening · Attaches deny policies to prevent public S3 exposure and disabling S3 public access block. · `terraform/modules/s3-guardrails/main.tf`
- [S3 baseline](https://github.com/hydrojak/aws-cloud-hardening-baseline/blob/main/terraform/modules/s3-account-baseline/main.tf): account-hardening · Account-level S3 baseline module used to enforce safer default S3 posture. · `terraform/modules/s3-account-baseline/main.tf`
- [Org SCPs](https://github.com/hydrojak/aws-cloud-hardening-baseline/blob/main/terraform/modules/organizations-scp/main.tf): governance · Optional AWS Organizations service control policies for higher-boundary prevention. · `terraform/modules/organizations-scp/main.tf`
- [CloudTrail logs](https://github.com/hydrojak/aws-cloud-hardening-baseline/blob/main/terraform/modules/cloudtrail-logging/main.tf): audit-logging · Creates hardened CloudTrail logging storage and trail configuration. · `terraform/modules/cloudtrail-logging/main.tf`
- [EventBridge rules](https://github.com/hydrojak/aws-cloud-hardening-baseline/blob/main/terraform/modules/detection-eventbridge/main.tf): detection-ingest · Turns security-relevant CloudTrail events into detection routing and remediation triggers. · `terraform/modules/detection-eventbridge/main.tf`
- [Detections log](https://github.com/hydrojak/aws-cloud-hardening-baseline/blob/main/terraform/modules/alerting-cloudwatch/main.tf): log-sink · Central CloudWatch Logs group that receives normalized detection events. · `terraform/modules/alerting-cloudwatch/main.tf`
- [Alarm filters](https://github.com/hydrojak/aws-cloud-hardening-baseline/blob/main/terraform/modules/alerting-alarms/main.tf): alerting · Builds metric filters and CloudWatch alarms from detection classes. · `terraform/modules/alerting-alarms/main.tf`
- [SNS notify](https://github.com/hydrojak/aws-cloud-hardening-baseline/blob/main/terraform/modules/alerting-sns/main.tf): notification · Optional notification endpoint for alarm delivery. · `terraform/modules/alerting-sns/main.tf`

### Optional modules

Features that can be enabled selectively for broader coverage or automation.

- [CloudTrail fix](https://github.com/hydrojak/aws-cloud-hardening-baseline/blob/main/terraform/modules/remediation-cloudtrail/main.tf): lambda-remediation · Optional Lambda that restores CloudTrail settings when tampering is detected. · `terraform/modules/remediation-cloudtrail/main.tf`
- [Lambda code](https://github.com/hydrojak/aws-cloud-hardening-baseline/blob/main/terraform/modules/remediation-cloudtrail/lambda/index.py): python-handler · Python entrypoint implementing the CloudTrail remediation logic. · `terraform/modules/remediation-cloudtrail/lambda/index.py`
- [GuardDuty ingest](https://github.com/hydrojak/aws-cloud-hardening-baseline/blob/main/terraform/modules/guardduty-integration/main.tf): security-findings · Optional GuardDuty integration forwarding high-severity findings into detections. · `terraform/modules/guardduty-integration/main.tf`
- [Security Hub ingest](https://github.com/hydrojak/aws-cloud-hardening-baseline/blob/main/terraform/modules/securityhub-integration/main.tf): security-findings · Optional Security Hub integration forwarding imported findings into detections. · `terraform/modules/securityhub-integration/main.tf`

### Documentation

Architecture, detection logic, and operational guidance that define control intent.

- [Detection docs](https://github.com/hydrojak/aws-cloud-hardening-baseline/blob/main/docs/detection.md): docs · Detection logic, CIS mapping, and validation guidance for the baseline. · `docs/detection.md`
- [Hardening docs](https://github.com/hydrojak/aws-cloud-hardening-baseline/blob/main/docs/hardening-decisions.md): docs · Design decisions and security posture notes for preventive controls. · `docs/hardening-decisions.md`
- [Ops guide](https://github.com/hydrojak/aws-cloud-hardening-baseline/blob/main/docs/Security_operation.md): docs · Operational and testing guidance for running and validating the baseline. · `docs/Security_operation.md`

## Connections

- Root stack → IAM baseline: compose · Root stack wires the IAM hardening module into the baseline.
- Root stack → S3 baseline: compose · Root stack includes the account-level S3 baseline.
- Root stack → S3 guardrails: compose · Root stack applies S3 prevention guardrails.
- Root stack → CloudTrail logs: compose · Root stack provisions audit logging.
- Root stack → EventBridge rules: compose · Root stack enables detection routing.
- Root stack → Detections log: compose · Root stack creates the centralized detections log sink.
- Root stack → Alarm filters: compose · Root stack turns detections into alarms.
- Root stack → SNS notify: compose · Root stack can create notification plumbing.
- Root stack → Org SCPs: optional · Root stack can extend controls to the organization boundary.
- Root stack → CloudTrail fix: optional · Root stack can add automated CloudTrail remediation.
- Root stack → GuardDuty ingest: optional · Root stack can ingest GuardDuty findings.
- Root stack → Security Hub ingest: optional · Root stack can ingest Security Hub findings.
- CloudTrail logs → EventBridge rules: events · CloudTrail management activity feeds the detection rules.
- CloudTrail logs → Detections log: logs · CloudTrail writes audit logs to hardened storage.
- EventBridge rules → Detections log: forward · Security-relevant events are normalized into the central log group.
- EventBridge rules → CloudTrail fix: invoke · CloudTrail tampering can trigger the remediation Lambda.
- GuardDuty ingest → Detections log: forward · GuardDuty findings are normalized into the same detection sink.
- Security Hub ingest → Detections log: forward · Security Hub findings are normalized into the same detection sink.
- Detections log → Alarm filters: metric filters · Log entries are converted into detection metrics and alarms.
- Alarm filters → SNS notify: notify · Alarms can publish notifications to SNS.
- CloudTrail fix → Lambda code: implements · The Terraform module packages the Python remediation handler.
- Detection docs → EventBridge rules: describes · Documentation captures expected event routing and detection logic.
- Hardening docs → IAM baseline: describes · Documentation records the preventive control intent.
- Ops guide → Alarm filters: operates · Operational guidance covers how alarms and testing should be used.
