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

الفصل 9الاسم في الدورة: Container security

Secure images and containers

Container security has two halves: a clean image (small, patched, scanned, signed, no secrets) and a locked-down runtime (non-root, few capabilities, read-only, limits). Both are checked automatically in the pipeline.

  • 6 الدروس
  • 6 الأوامر

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

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

9.1

Scan images for vulnerabilities

Scanners compare the packages in an image with vulnerability databases (CVEs).

trivy image nginx:1.27
trivy image --severity HIGH,CRITICAL --ignore-unfixed --exit-code 1 shop:dev
trivy fs --scanners vuln,secret,misconfig .
grype shop:dev
docker scout cves shop:dev

تذكّر

Scan in CI on every build and regularly for images already running — new CVEs are found every day.

9.2

Make an SBOM

A Software Bill of Materials lists every package in the image. When a new vulnerability appears, you know at once which images contain it.

syft shop:dev -o spdx-json > sbom.spdx.json
trivy image --format cyclonedx --output sbom.cdx.json shop:dev
grype sbom:./sbom.spdx.json

9.3

Sign and verify images

A signature proves who built an image and that it was not changed. cosign (Sigstore) signs with a key or keyless with the CI identity.

cosign generate-key-pair
cosign sign --key cosign.key ghcr.io/s0sta/shop@sha256:DIGEST
cosign verify --key cosign.pub ghcr.io/s0sta/shop@sha256:DIGEST
cosign attest --key cosign.key --type spdxjson --predicate sbom.spdx.json ghcr.io/s0sta/shop@sha256:DIGEST

في العمل

Sign by digest, not by tag. In Kubernetes, an admission policy can then allow only signed images (see CKS supply chain).

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

9.4

Run containers with fewer rights

Take away everything the app does not need.

docker run -d --name api \
    --user 1001:1001 \
    --read-only --tmpfs /tmp \
    --cap-drop ALL --cap-add NET_BIND_SERVICE \
    --security-opt no-new-privileges \
    --memory 512m --pids-limit 200 \
    myorg/api:2.0
SettingStops
--user (non-root)Root power if the app is hacked
--read-onlyChanges to the app files, dropped malware
--cap-drop ALLRoot powers like changing the network or mounting
no-new-privilegesSUID programs giving more rights
LimitsOne container taking the whole host down

انتبه

Never use --privileged, never mount /var/run/docker.sock into a container (it is root on the host), and avoid --network host and --pid host.

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

9.5

Keep secrets out of images

Anything in a layer can be read by anyone with the image — even if a later layer deletes it.

docker build --secret id=npmrc,src=$HOME/.npmrc -t web:dev .
docker run -d --name api -v /run/secrets/db:/run/secrets/db:ro myorg/api:2.0
Dockerfile (build secret)
RUN --mount=type=secret,id=npmrc,target=/root/.npmrc npm ci

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

9.6

Check the host and the daemon

The host matters too: patched kernel, rootless engine where possible, and the CIS benchmark.

podman info --format '{{.Host.Security.Rootless}}'
docker run --rm --net host --pid host --cap-add audit_control -v /etc:/etc:ro -v /var/lib:/var/lib:ro -v /var/run/docker.sock:/var/run/docker.sock:ro docker/docker-bench-security

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