ความปลอดภัยของโครงสร้างพื้นฐานในรูปโค้ด
เรียนรู้การรักษาความปลอดภัยโครงสร้างพื้นฐานคลาวด์ที่กำหนดเป็นโค้ดด้วย Terraform สแกนแม่แบบเพื่อค้นหาการกำหนดค่าผิดพลาด และป้องกันการเบี่ยงเบนกับค่าเริ่มต้นที่ไม่ปลอดภัย
ความปลอดภัยของโครงสร้างพื้นฐานในรูปโค้ด เป็นบทเรียน Secure Coding & OWASP Top 10 for Backend ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Secure Coding & OWASP Top 10 for Backend และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Secure Coding & OWASP Top 10 for Backend มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
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.
คำถามที่พบบ่อย
บทเรียน “ความปลอดภัยของโครงสร้างพื้นฐานในรูปโค้ด” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “ความปลอดภัยของโครงสร้างพื้นฐานในรูปโค้ด” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Secure Coding & OWASP Top 10 for Backend ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Secure Coding & OWASP Top 10 for Backend มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “ความปลอดภัยของโครงสร้างพื้นฐานในรูปโค้ด”
เรียนรู้การรักษาความปลอดภัยโครงสร้างพื้นฐานคลาวด์ที่กำหนดเป็นโค้ดด้วย Terraform สแกนแม่แบบเพื่อค้นหาการกำหนดค่าผิดพลาด และป้องกันการเบี่ยงเบนกับค่าเริ่มต้นที่ไม่ปลอดภัย คุณปฏิบัติ Secure Coding & OWASP Top 10 for Backend ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Secure Coding & OWASP Top 10 for Backend หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Secure Coding & OWASP Top 10 for Backend บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน
บทเรียน “ความปลอดภัยของโครงสร้างพื้นฐานในรูปโค้ด” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Secure Coding & OWASP Top 10 for Backend นี้ได้ไหม
ได้ บทเรียน Secure Coding & OWASP Top 10 for Backend ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- การนำระบบขึ้นคลาวด์อย่างปลอดภัย (AWS/Azure/GCP)
- ความปลอดภัยของคอนเทนเนอร์ (Docker/Kubernetes)
- แนวทางปฏิบัติที่ดีที่สุดด้านความปลอดภัยของระบบไร้เซิร์ฟเวอร์
- ความปลอดภัยของโครงสร้างพื้นฐานในรูปโค้ด