أمان الحاويات (Docker/Kubernetes)
طبّقوا ممارسات آمنة لبناء التطبيقات المعبأة في حاويات ونشرها وإدارتها باستخدام Docker وKubernetes، بما في ذلك فحص الصور وسياسات الشبكة.
أمان الحاويات (Docker/Kubernetes) درس مجاني في Secure Coding & OWASP Top 10 for Backend على CoddyKit. هذا هو الدرس 2 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 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)» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 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 مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 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 يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- النشر الآمن على السحابة (AWS/Azure/GCP)
- أمان الحاويات (Docker/Kubernetes)
- أفضل ممارسات أمان Serverless
- أمان البنية التحتية كتعليمات برمجية