Skip to content

Ruzibaev007/terraform-aws-security

Β 
Β 

Repository files navigation

NIS2/DORA CI License: MIT NIS2 Compliant DORA Ready ISO 27001 Terraform AWS BSI IT-Grundschutz

πŸ” terraform-aws-security

Production-ready AWS security baseline for the EU β€” NIS2, DORA, ISO 27001, BSI IT-Grundschutz.

The only open-source Terraform framework that covers NIS2 Articles 21–32, DORA Article 16, and BSI IT-Grundschutz out of the box β€” built for German Mittelstand and EU critical infrastructure.

πŸ‡©πŸ‡ͺ Deutsche Version | πŸ‡¬πŸ‡§ English Version


English

⚑ 5-Minute Quick Start

# Prerequisites: terraform >= 1.5, aws-cli >= 2.13, opa >= 0.68
bash install/linux.sh     # Linux / Linux Mint
bash install/macos.sh     # macOS
# Windows: .\install\windows.ps1

# Deploy
git clone https://github.com/Protector080322/terraform-aws-security
cd terraform-aws-security
cp examples/mittelstand-sme/terraform.tfvars .
make validate             # NIS2/DORA compliance check
make plan                 # Preview changes
make apply                # Deploy (requires confirmation)

🎯 Who Is This For?

You are... This gives you...
German Mittelstand IT team NIS2-compliant AWS baseline in under 1 hour
Security Architect (EU) 35+ controls mapped to NIS2/DORA/ISO 27001
vCISO / Compliance Lead Automated evidence generation & BSI-ready reports
DevOps Engineer Policy-as-Code pipeline blocking non-compliant deploys
Auditor / Pen Tester Ready-made OPA policies for infrastructure review

πŸ† Why This Project?

The problem: NIS2 became mandatory in Germany in October 2024. DORA in January 2025. Most AWS environments are NOT compliant. Manual compliance is expensive, slow, and error-prone.

The solution: Infrastructure-as-Code + Policy-as-Code = compliance at the speed of deployment.

Traditional compliance:  manual audit β†’ 3 months β†’ €50k+
This framework:          terraform apply β†’ 5 minutes β†’ automated evidence

πŸ“Š Compliance Frameworks

Framework Articles Status Who Needs It
πŸ‡ͺπŸ‡Ί NIS2 (EU 2022/2555) 21, 23, 25, 28, 32 βœ… Full All EU essential/important operators
🏦 DORA (EU 2022/2554) 16 (incident reporting) βœ… Implemented Banks, insurance, investment firms
πŸ“‹ ISO 27001:2022 A.5–A.18 (35+ controls) βœ… Mapped Any security-conscious organization
πŸ‡©πŸ‡ͺ BSI IT-Grundschutz ORP.4, CON.1, DER.2.1, NET.1.1 βœ… Aligned German organizations
πŸ”’ GDPR Data residency (EU-DE) βœ… Configured All EU data processors
πŸš— TISAX VDA ISA 6.0 βœ… Example Automotive suppliers

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   AWS Organization                       β”‚
β”‚                                                         β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚  Management β”‚  β”‚ Production  β”‚  β”‚  Audit Account  β”‚ β”‚
β”‚  β”‚  Account    β”‚  β”‚  Account    β”‚  β”‚                 β”‚ β”‚
β”‚  β”‚  SCPs       β”‚  β”‚  EKS/k3s    β”‚  β”‚  CloudTrail     β”‚ β”‚
β”‚  β”‚  GuardDuty  β”‚  β”‚  RDS (enc.) β”‚  β”‚  S3 (locked)    β”‚ β”‚
β”‚  β”‚  SecurityHubβ”‚  β”‚  VPC        β”‚  β”‚  KMS            β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                   β”‚                   β”‚
    NIS2 Art.21         NIS2 Art.32         NIS2 Art.25
    (Access Control)  (Network Security)  (Audit Logging)

See ARCHITECTURE.md for full Mermaid diagrams.

πŸ”’ Security Controls (35+)

NIS2 Article 21 β€” Access Control
  • MFA enforcement (deny all actions without MFA)
  • Permission boundaries on all IAM roles/users
  • Break-glass PAM role (emergency access, 15-min MFA window)
  • Session timeout: 8 hours maximum
  • Access key rotation: 90-day AWS Config rule
  • No root access key (Config rule)
  • RBAC: auditor read-only role
NIS2 Article 23 β€” Incident Detection & Response
  • GuardDuty (ML-based threat detection, EKS audit logs)
  • Security Hub (CIS 1.4.0 + AFSBP + NIST centralized findings)
  • Lambda incident response playbook (auto-classifies, notifies BSI)
  • EventBridge: GuardDuty HIGH/CRITICAL β†’ Lambda β†’ SNS
  • CloudWatch alarms: root login, MFA disable, GuardDuty disable
  • DORA Step Functions: 4h β†’ 72h β†’ 1-month BaFin reporting
NIS2 Article 25 β€” Audit Logging & Encryption
  • CloudTrail: multi-region, log file validation, KMS encrypted
  • S3 Object Lock: tamper-proof logs, GOVERNANCE mode, 365 days
  • S3 lifecycle: STANDARD_IA (90d) β†’ Glacier (365d) β†’ delete (7yr)
  • KMS: dedicated key, automatic annual rotation
  • All S3 buckets: KMS encryption (not AES256)
  • RDS: encrypted storage (Config rule)
  • EBS: encrypted volumes (Config rule)
NIS2 Article 28 β€” Supply Chain & Data Residency
  • EU-only regions: eu-central-1 (Frankfurt) + eu-west-1 (Ireland)
  • Terraform variable validation: startswith(var.region, "eu-")
  • SCP: deny CloudTrail disable
  • SCP: deny GuardDuty disable
  • SCP: deny Security Hub disable
  • SCP: deny S3 public access
NIS2 Article 32 β€” Network Segmentation
  • k3s NetworkPolicies: default-deny-ingress
  • IMDSv2 required on all EC2 (SSRF protection)
  • No public IPs on backend instances
  • VPC flow logs (Config rule)
  • Lambda in VPC (Config rule)
  • SSH/RDP blocked from internet (OPA rule)

πŸš€ What's Inside

terraform-aws-security/
β”œβ”€β”€ πŸ“ envs/
β”‚   β”œβ”€β”€ dev/           # 7-step deployment (stateβ†’loggingβ†’configβ†’securityβ†’pacβ†’scpsβ†’iam)
β”‚   └── prod/          # Production mirror
β”œβ”€β”€ πŸ“ modules/
β”‚   β”œβ”€β”€ logging/       # CloudTrail + KMS + S3
β”‚   β”œβ”€β”€ iam/           # Permission boundaries + MFA
β”‚   β”œβ”€β”€ config/        # AWS Config + conformance packs
β”‚   └── org/scps/      # Organization SCPs
β”œβ”€β”€ πŸ“ compliance/
β”‚   β”œβ”€β”€ nis2/          # Articles 21, 23, 25 (Terraform)
β”‚   └── dora/          # Article 16 Step Functions workflow
β”œβ”€β”€ πŸ“ examples/
β”‚   β”œβ”€β”€ mittelstand-sme/  # German manufacturing, ~500 employees
β”‚   β”œβ”€β”€ healthcare/       # GDPR Art.9 + NIS2 essential
β”‚   └── automotive/       # TISAX + ISO-SAE-21434
β”œβ”€β”€ πŸ“ kubernetes/
β”‚   └── k3s-hardened/     # NIS2 Art.21/32 hardened cluster
β”œβ”€β”€ πŸ“ policies-as-code/
β”‚   └── opa/              # 20+ NIS2/DORA/ISO 27001 OPA rules
β”œβ”€β”€ πŸ“ install/
β”‚   β”œβ”€β”€ macos.sh          # One-command setup for macOS
β”‚   β”œβ”€β”€ linux.sh          # One-command setup for Linux
β”‚   └── windows.ps1       # One-command setup for Windows
β”œβ”€β”€ πŸ“ scripts/
β”‚   β”œβ”€β”€ validate-compliance.sh  # Pre-deploy check
β”‚   └── generate-report.sh      # Compliance report generator
β”œβ”€β”€ πŸ“ docs/
β”‚   └── compliance-mapping.md   # 35+ controls mapped
β”œβ”€β”€ Makefile              # make validate / plan / apply / report
β”œβ”€β”€ ARCHITECTURE.md       # 7 Mermaid diagrams
β”œβ”€β”€ GETTING_STARTED.md    # 5-minute setup guide
└── CHANGELOG.md          # Version history

πŸ“ˆ CI/CD Pipeline

Every pull request runs:

terraform fmt β†’ terraform validate
       ↓
  tfsec (HIGH+)  β†’  checkov
       ↓
  OPA unit tests β†’ OPA plan eval
       ↓
  gitleaks (secrets scan)
       ↓
  terraform plan (with OPA validation)
       ↓
  compliance report
       ↓
  terraform apply (main branch only, after approval)

🏭 Industry Examples

# German Mittelstand (manufacturing, ~500 employees)
cp examples/mittelstand-sme/terraform.tfvars .

# Healthcare (GDPR Art.9 + NIS2 essential operator)
cp examples/healthcare/terraform.tfvars .

# Automotive (TISAX + VDA ISA 6.0 + NIS2)
cp examples/automotive/terraform.tfvars .

πŸ“š Documentation


Deutsch

⚑ 5-Minuten Schnellstart

# Voraussetzungen: terraform >= 1.5, aws-cli >= 2.13
bash install/linux.sh     # Linux / Linux Mint
bash install/macos.sh     # macOS

# Deployment
git clone https://github.com/Protector080322/terraform-aws-security
cd terraform-aws-security
cp examples/mittelstand-sme/terraform.tfvars .
make validate             # NIS2/DORA Compliance-PrΓΌfung
make plan && make apply   # Infrastruktur deployen

🎯 Warum dieses Projekt?

Das Problem: Die NIS2-Richtlinie ist seit Oktober 2024 in Deutschland verbindlich. DORA seit Januar 2025. Die meisten AWS-Umgebungen sind nicht konform. Manuelle Compliance kostet Zeit und Geld.

Die LΓΆsung: Infrastructure-as-Code + Policy-as-Code = Compliance mit jedem Deployment automatisch sichergestellt.

πŸ‡©πŸ‡ͺ BSI IT-Grundschutz Mapping

BSI-Baustein Beschreibung Implementierung
ORP.4 IdentitΓ€ts- & Zugriffsmanagement modules/iam/
CON.1 Kryptokonzept modules/logging/ (KMS)
OPS.1.1.5 Datensicherung AWS Backup + S3 Object Lock
DER.2.1 Incident Management compliance/nis2/article-23-incident-response.tf
NET.1.1 Netzarchitektur kubernetes/k3s-hardened/
INF.14 Automatisierungsnetze compliance/nis2/article-32-network-security.tf

βš–οΈ NIS2 Meldepflichten (BSI)

Vorfall Frist BehΓΆrde
Erheblicher Sicherheitsvorfall 24 Stunden (Erstmeldung) BSI
VollstΓ€ndige Meldung 72 Stunden BSI
Abschlussbericht 1 Monat BSI
BSI Meldung: https://www.bsi.bund.de

πŸ’° Zielgruppen in Deutschland

  • Mittelstand (Fertigung, Maschinenbau, Automobilzulieferer)
  • Gesundheitswesen (KrankenhΓ€user, Pharmaunternehmen)
  • Finanzsektor (DORA-pflichtige Unternehmen)
  • Kritische Infrastruktur (KRITIS-Betreiber)
  • IT-Dienstleister fΓΌr die oben genannten

🀝 Contributing

See CONTRIBUTING.md β€” we welcome:

  • New NIS2/DORA article implementations
  • Additional industry examples (energy, finance, healthcare)
  • Improved OPA policies
  • Bug fixes and documentation

πŸ“œ License

MIT License β€” free to use, modify, and distribute.

πŸ‘€ Maintainer

Ruzibaev007 Berlin, Germany | Security Architect | NIS2 | AWS | Terraform

πŸ“§ z.ruzibaev@mail.de πŸ”— GitHub


Built for German Mittelstand. Compliant with EU regulations. Open source.

About

πŸ” NIS2/DORA/ISO 27001 AWS Security Baseline β€” Terraform + OPA. Production-ready compliance framework for German Mittelstand & EU critical infrastructure.

Topics

Resources

Contributing

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • HCL 69.5%
  • Shell 14.7%
  • Open Policy Agent 7.8%
  • Makefile 4.4%
  • PowerShell 3.6%