Sicherheit von Infrastructure as Code
Lernen Sie, als Code definierte Cloud-Infrastruktur mit Terraform abzusichern, Vorlagen auf Fehlkonfigurationen zu prüfen und Drift sowie unsichere Standardwerte zu verhindern.
Sicherheit von Infrastructure as Code ist eine kostenlose Secure Coding & OWASP Top 10 for Backend-Lektion auf CoddyKit. Dies ist Lektion 4 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Secure Coding & OWASP Top 10 for Backend-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Secure Coding & OWASP Top 10 for Backend-Kurs umfasst insgesamt 4 Lektionen.
Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.
What Is IaC?
Infrastructure as Code (IaC) defines cloud resources in declarative files (Terraform, CloudFormation, Bicep) instead of clicking through consoles. It makes infrastructure repeatable, reviewable, and version-controlled.
That same automation means a single mistake can be deployed everywhere instantly.
Security Benefits of IaC
IaC enables security at scale:
- Changes go through code review and version history
- Configurations are consistent across environments
- Security policies can be enforced automatically
The goal is to catch insecure config before it ever reaches the cloud.
Common Misconfigurations
The most frequent IaC security mistakes include:
- Storage buckets open to the public
- Security groups allowing 0.0.0.0/0 on sensitive ports
- Unencrypted volumes and databases
- Overly broad IAM permissions
An Insecure Example
This Terraform snippet exposes a database port to the entire internet.
resource 'aws_security_group_rule' 'db' {
type = 'ingress'
from_port = 5432
to_port = 5432
protocol = 'tcp'
cidr_blocks = ['0.0.0.0/0'] # INSECURE: open to all
}The Secure Version
Restrict access to a known private range and enforce encryption by default.
resource 'aws_security_group_rule' 'db' {
type = 'ingress'
from_port = 5432
to_port = 5432
protocol = 'tcp'
cidr_blocks = ['10.0.1.0/24'] # private app subnet only
}Static Scanning
Tools like Checkov, tfsec, and Terrascan scan IaC files for insecure patterns before deployment. Run them in CI so risky templates fail the build automatically.
# Example CI step (conceptual)
# checkov -d ./infra --quiet
rules_failed = ['CKV_AWS_24: SSH open to 0.0.0.0/0']
for r in rules_failed:
print('FAIL', r)Policy as Code
Policy as Code tools like Open Policy Agent (OPA) and Sentinel let you write rules such as 'no public buckets' that block non-compliant plans automatically, turning security standards into enforceable code.
Securing State Files
Terraform state can contain secrets and resource details. Store it in an encrypted, access-controlled backend (such as an encrypted S3 bucket with locking), never in the git repository.
- Encrypt state at rest
- Restrict who can read it
- Enable state locking to prevent corruption
Avoiding Hardcoded Secrets
Never put credentials directly in IaC files. Reference a secrets manager or inject values at apply time so secrets never land in version control or state.
Detecting Drift
Drift happens when someone changes infrastructure manually, diverging from the code. Run drift detection regularly so unauthorized or accidental changes are caught and reconciled.
Least-Privilege Modules
Build reusable modules with secure defaults: encryption on, public access off, minimal IAM. Teams that consume hardened modules inherit good security without having to be experts.
Quick Check
Test your understanding of IaC security.
Recap
You learned how to secure Infrastructure as Code: review changes, scan templates with tools like Checkov, enforce policy as code, protect state files, keep secrets out of templates, and detect drift. Catching misconfiguration in code stops it before it reaches production.
Lerne Secure Coding & OWASP Top 10 for Backend mit einem KI-Tutor — kostenlos
Schreibe und führe echten Code in deinem Browser aus, bekomme sofortige Hilfe von einem 24/7 KI-Tutor und setze dein Lernen im Web oder in der App fort.
- Kurse
- 12
- Lektionen
- 48
Häufig gestellte Fragen
Ist die Lektion „Sicherheit von Infrastructure as Code“ kostenlos?
Ja — der vollständige Text von „Sicherheit von Infrastructure as Code“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Secure Coding & OWASP Top 10 for Backend-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Secure Coding & OWASP Top 10 for Backend-Kurs umfasst insgesamt 4 Lektionen.
Was lerne ich in „Sicherheit von Infrastructure as Code“?
Lernen Sie, als Code definierte Cloud-Infrastruktur mit Terraform abzusichern, Vorlagen auf Fehlkonfigurationen zu prüfen und Drift sowie unsichere Standardwerte zu verhindern. Du übst Secure Coding & OWASP Top 10 for Backend mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.
Brauche ich Erfahrung, um Secure Coding & OWASP Top 10 for Backend zu starten?
Keine Vorkenntnisse erforderlich. Secure Coding & OWASP Top 10 for Backend auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 4 von 4.
Wie lange dauert die Lektion „Sicherheit von Infrastructure as Code“?
Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.
Kann ich in dieser Secure Coding & OWASP Top 10 for Backend-Lektion Code schreiben und ausführen?
Ja. Jede Secure Coding & OWASP Top 10 for Backend-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.
Alle Lektionen in diesem Kurs
- Sichere Cloud-Bereitstellung (AWS/Azure/GCP)
- Containersicherheit (Docker/Kubernetes)
- Best Practices für die Serverless-Sicherheit
- Sicherheit von Infrastructure as Code