How hydrojak/aws-cloud-hardening-baseline works
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 Root stack · alerting-cloudwatch/main.tf Detections log · detection-eventbridge/main.tf EventBridge rules · alerting-alarms/main.tf Alarm filters
Components 17
Terraform baseline
Core account-scoped security controls composed by the root Terraform stack.
- Root stack · Top-level Terraform composition that wires the security baseline modules together.
terraform/main.tf - IAM baseline · Sets account IAM hygiene such as password policy and IAM Access Analyzer.
terraform/modules/iam-baseline/main.tf - S3 guardrails · Attaches deny policies to prevent public S3 exposure and disabling S3 public access block.
terraform/modules/s3-guardrails/main.tf - S3 baseline · Account-level S3 baseline module used to enforce safer default S3 posture.
terraform/modules/s3-account-baseline/main.tf - Org SCPs · Optional AWS Organizations service control policies for higher-boundary prevention.
terraform/modules/organizations-scp/main.tf - CloudTrail logs · Creates hardened CloudTrail logging storage and trail configuration.
terraform/modules/cloudtrail-logging/main.tf - EventBridge rules · Turns security-relevant CloudTrail events into detection routing and remediation triggers.
terraform/modules/detection-eventbridge/main.tf - Detections log · Central CloudWatch Logs group that receives normalized detection events.
terraform/modules/alerting-cloudwatch/main.tf - Alarm filters · Builds metric filters and CloudWatch alarms from detection classes.
terraform/modules/alerting-alarms/main.tf - SNS notify · 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 · Optional Lambda that restores CloudTrail settings when tampering is detected.
terraform/modules/remediation-cloudtrail/main.tf - Lambda code · Python entrypoint implementing the CloudTrail remediation logic.
terraform/modules/remediation-cloudtrail/lambda/index.py - GuardDuty ingest · Optional GuardDuty integration forwarding high-severity findings into detections.
terraform/modules/guardduty-integration/main.tf - Security Hub ingest · 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 · Detection logic, CIS mapping, and validation guidance for the baseline.
docs/detection.md - Hardening docs · Design decisions and security posture notes for preventive controls.
docs/hardening-decisions.md - Ops guide · Operational and testing guidance for running and validating the baseline.
docs/Security_operation.md
Connections 24
- 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.