الفلاتر
طريقة البحث
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • "كلمتان" تجد العبارة بالضبط.
  • --name أو -x تجد خيارًا.
  • #كلمة تبحث داخل الأوامر فقط.
  • @grep تجد الدروس والمعامل التي تستخدم grep.
  • الفلاتر: cat:network · in:labs · level:rhcsa · ch:8 · root:yes. ضع ! قبل كلمة لاستبعادها. OR بين الكلمات تعني إحداها.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث

الفصل 4الاسم في الدورة: Pod Security Admission and security contexts

Enforce Pod Security Standards

Pod Security Standards define three levels of pod safety. The built-in Pod Security Admission controller enforces them per namespace with labels — no extra software needed. A pod that breaks the level is rejected (or warned about).

  • 4 الدروس
  • 2 الأوامر

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

$ مستخدم عادي# بصلاحية root (أو مع sudo)

المهارات في هذا الفصل

  • معايير Pod Security وسياقات الأمان

4.1

Know the three levels

Choose the strictest level each namespace can live with.

LevelAllowsFor
privilegedEverythingSystem namespaces (CNI, storage drivers)
baselineBlocks known escalations: host namespaces, privileged, hostPath, extra capabilitiesMost legacy apps
restrictedAlso: non-root, no privilege escalation, drop ALL capabilities, seccomp RuntimeDefaultNew apps — the target

4.2

Label a namespace

Three modes per namespace: enforce (reject), audit (log), warn (warning to the user).

kubectl label namespace shop pod-security.kubernetes.io/enforce=restricted pod-security.kubernetes.io/enforce-version=latest
kubectl label namespace shop pod-security.kubernetes.io/warn=restricted pod-security.kubernetes.io/audit=restricted --overwrite
kubectl label --dry-run=server --overwrite namespace legacy pod-security.kubernetes.io/enforce=restricted
kubectl get ns shop --show-labels

في العمل

The --dry-run=server line lists which running pods would break the level before you enforce it.

الأوامر في هذا الدرس

4.3

Write a restricted pod

This pod passes the restricted level.

restricted-pod.yaml
apiVersion: v1
kind: Pod
metadata: { name: api, namespace: shop }
spec:
  securityContext:
    runAsNonRoot: true
    runAsUser: 1001
    runAsGroup: 1001
    fsGroup: 1001
    seccompProfile: { type: RuntimeDefault }
  containers:
    - name: api
      image: ghcr.io/s0sta/api:2.0
      securityContext:
        allowPrivilegeEscalation: false
        readOnlyRootFilesystem: true
        capabilities: { drop: ["ALL"] }
      volumeMounts:
        - { name: tmp, mountPath: /tmp }
  volumes:
    - name: tmp
      emptyDir: {}
kubectl apply -f restricted-pod.yaml
kubectl run bad --image=nginx -n shop
Error from server (Forbidden): pods "bad" is forbidden: violates PodSecurity "restricted:latest": allowPrivilegeEscalation != false ...

الأوامر في هذا الدرس

4.4

Fix a rejected workload

The error message lists every broken rule. Fix them one by one in the pod template (Deployments are not rejected — their pods are; check the ReplicaSet events).

kubectl get events -n shop --field-selector reason=FailedCreate
kubectl describe rs -n shop -l app=web | grep -A3 Warning
Message partFix
runAsNonRoot != truesecurityContext.runAsNonRoot: true (+ a non-root image or runAsUser)
allowPrivilegeEscalation != falseSet it to false per container
unrestricted capabilitiescapabilities.drop: ["ALL"]
seccompProfileseccompProfile.type: RuntimeDefault
hostPath volumesUse PVCs or emptyDir

تذكّر

Pod Security Admission checks only new pods. Existing pods keep running until they are recreated.

كل الأوامر في هذا الفصل