ความปลอดภัยของคอนเทนเนอร์ (Docker/Kubernetes)
นำแนวทางปฏิบัติที่ปลอดภัยสำหรับการสร้าง นำขึ้นใช้งาน และจัดการแอปพลิเคชันแบบคอนเทนเนอร์ด้วย Docker และ Kubernetes ไปใช้ ซึ่งรวมถึงการสแกนอิมเมจและนโยบายเครือข่าย
ความปลอดภัยของคอนเทนเนอร์ (Docker/Kubernetes) เป็นบทเรียน Secure Coding & OWASP Top 10 for Backend ฟรีบน CoddyKit นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Secure Coding & OWASP Top 10 for Backend และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Secure Coding & OWASP Top 10 for Backend มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
Introduction to Container Security
Welcome to Container Security! Here, we'll explore how to protect your applications when they run inside containers like Docker and are orchestrated by systems like Kubernetes.
Containers offer great flexibility and efficiency, but they also introduce new security challenges that need careful attention.
Minimize Container Images
Smaller container images mean less attack surface. Remove unnecessary tools, libraries, and files from your final image.
Using multi-stage builds and minimal base images (like Alpine Linux variants) are excellent strategies.
FROM openjdk:17-jdk-slim AS builder
WORKDIR /app
COPY . .
RUN javac Main.java
FROM openjdk:17-jre-slim
WORKDIR /app
COPY --from=builder /app/Main.class .
CMD ["java", "Main"]Use Trusted Base Images
Always start with official and well-maintained base images from trusted registries. Unofficial images might contain vulnerabilities or even malicious code.
- Verify sources: Only pull images from reputable vendors or official repositories.
- Scan regularly: Even official images can have vulnerabilities; scan them often.
Principle of Least Privilege
Run your containers with the minimum necessary permissions. This limits the damage if a container is compromised.
- Run as non-root: Avoid running processes as the root user inside the container.
- Drop capabilities: Remove Linux capabilities (e.g.,
NET_ADMIN,SYS_ADMIN) that your application doesn't need.
docker run --user 1000:1000 \
--cap-drop=ALL \
my-secure-appScan Container Images for Vulnerabilities
Integrate automated image scanning tools (like Trivy, Clair, or vulnerability scanners from cloud providers) into your CI/CD pipeline.
Scan images early and often to detect known vulnerabilities in your dependencies and operating system layers before deployment.
Kubernetes Network Policies
Network Policies in Kubernetes allow you to control which pods can communicate with each other and with external network endpoints.
By default, pods can communicate freely. Network policies enforce segmentation, creating a firewall around your pods.
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: deny-all-ingress
namespace: default
spec:
podSelector: {}
policyTypes:
- IngressSecure Secrets Management
Sensitive information like API keys, database passwords, and private certificates should never be hardcoded into images or configuration files.
Use Kubernetes Secrets, HashiCorp Vault, or cloud-specific secret managers to store and inject secrets securely at runtime.
apiVersion: v1
kind: Secret
metadata:
name: my-app-secret
type: Opaque
data:
api_key: YmFzZTY0ZW5jb2RlZHNlY3JldA== # base64 encoded value
db_password: cGFzc3dvcmQ=Runtime Security & Monitoring
Even with robust build-time security, runtime protection is crucial. Monitor container behavior for suspicious activities.
Tools like Falco can detect anomalous process execution, unauthorized file access, or unexpected network connections within your containers.
Kubernetes Security Contexts
Security Contexts in Kubernetes allow you to define privilege and access control settings for a Pod or Container.
You can specify settings like running as a non-root user, dropping Linux capabilities, or configuring SELinux/AppArmor profiles.
apiVersion: v1
kind: Pod
metadata:
name: secure-pod
spec:
securityContext:
runAsNonRoot: true
runAsUser: 1000
fsGroup: 2000
containers:
- name: my-container
image: my-image
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop: ["ALL"]Quick Check: Image Security
Which of the following are best practices for securing container images?
Container Security Recap
In this lesson, we covered key aspects of securing containerized applications:
- Minimizing image size and using trusted base images.
- Applying the principle of least privilege.
- Regularly scanning images for vulnerabilities.
- Controlling network access with Kubernetes Network Policies.
- Managing secrets securely.
- Monitoring containers at runtime for suspicious activity.
- Enforcing security settings with Kubernetes Security Contexts.
By following these practices, you can significantly enhance the security posture of your Docker and Kubernetes deployments.
คำถามที่พบบ่อย
บทเรียน “ความปลอดภัยของคอนเทนเนอร์ (Docker/Kubernetes)” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “ความปลอดภัยของคอนเทนเนอร์ (Docker/Kubernetes)” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Secure Coding & OWASP Top 10 for Backend ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Secure Coding & OWASP Top 10 for Backend มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “ความปลอดภัยของคอนเทนเนอร์ (Docker/Kubernetes)”
นำแนวทางปฏิบัติที่ปลอดภัยสำหรับการสร้าง นำขึ้นใช้งาน และจัดการแอปพลิเคชันแบบคอนเทนเนอร์ด้วย Docker และ Kubernetes ไปใช้ ซึ่งรวมถึงการสแกนอิมเมจและนโยบายเครือข่าย คุณปฏิบัติ 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 ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน
บทเรียน “ความปลอดภัยของคอนเทนเนอร์ (Docker/Kubernetes)” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Secure Coding & OWASP Top 10 for Backend นี้ได้ไหม
ได้ บทเรียน Secure Coding & OWASP Top 10 for Backend ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- การนำระบบขึ้นคลาวด์อย่างปลอดภัย (AWS/Azure/GCP)
- ความปลอดภัยของคอนเทนเนอร์ (Docker/Kubernetes)
- แนวทางปฏิบัติที่ดีที่สุดด้านความปลอดภัยของระบบไร้เซิร์ฟเวอร์
- ความปลอดภัยของโครงสร้างพื้นฐานในรูปโค้ด