شعار Container Image Hardening

Container Image Hardening

المجتمع
selvarajmurugesan90
container-image-hardening

Guides building minimal, non-root, hardened container images — multi-stage builds, distroless/minimal base images, non-root users, read-only root filesystems, dropped Linux capabilities, and pinned/ digest-referenced base images. Use when the user asks to "harden this Dockerfile", "reduce container image attack surface/size", "make our container run as non-root", "switch to a distroless base image", "fix a container security scan finding about running as root or having a shell", or "set Kubernetes securityContext restrictions for a pod".

نظرة عامة

الناشرselvarajmurugesan90
المستودعops-engineering-skills
اسم المهارةcontainer-image-hardening
النجوم
44
التفريعات
18
الملفات المرفقة
تعليمات فقط
الترخيصApache-2.0
الروابط
  • تعليمات بصيغة Markdown

    ملف SKILL.md يُحمّله النموذج عند الحاجة، فلا يستهلك توكنات إلا عندما يَرِد طلب ذو صلة فعلًا.

  • تعمل مع أي نموذج لغوي كبير

    مهارات الذكاء الاصطناعي مكتوبة بصيغة Markdown وليست شيفرة خاصة بمزوّد معيّن، لذا تعمل مع GPT أو Claude أو Gemini أو Grok أو نموذج محلي.

  • مكتفية بذاتها

    كل ما يحتاجه النموذج موجود في التعليمات — لا ملفات إضافية لمزامنتها.

  • مفتوحة المصدر

    نشرها selvarajmurugesan90 على GitHub. اطّلع على المصدر قبل تثبيتها.

التثبيت

ثبّت مهارة الذكاء الاصطناعي Container Image Hardening في TypingMind لاستخدامها مع أي نموذج لغوي كبير، أو أضفها إلى وكيل ذكاء اصطناعي آخر يقرأ SKILL.md.

1

التثبيت في TypingMind

يُثبّت TypingMind المهارة مباشرةً من مجلدها على GitHub — فيقرأ SKILL.md، ويجمع ملفات الموارد في حزمة، ويحفظ النتيجة محليًا.

  1. افتح التطبيق وانتقل إلى «الإضافات» ثم «المهارات».
  2. اختر «تثبيت من GitHub».
  3. الصق رابط مجلد المهارة الموضّح أدناه وأكّد التثبيت.
    https://github.com/selvarajmurugesan90/ops-engineering-skills/tree/main/plugins/devsecops/skills/container-image-hardening
  4. فعّل المهارة في كل محادثة تريد إتاحتها فيها.
الإضافات ← المهارات ← إضافة مهارة ← من رابط GitHub، ثم الصق رابط المجلد واضغط على «متابعة».
2

التثبيت في وكيل ذكاء اصطناعي آخر

يمكن لأي وكيل ذكاء اصطناعي يقرأ تنسيق Agent Skills استخدام هذه المهارة — انسخ المجلد إلى مجلد المهارات الخاص بذلك الوكيل.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/selvarajmurugesan90/ops-engineering-skills.git /tmp/ops-engineering-skills
mkdir -p .claude/skills
cp -r /tmp/ops-engineering-skills/plugins/devsecops/skills/container-image-hardening .claude/skills/container-image-hardening
أعد تشغيل Claude Code بعد النسخ ليتعرّف على المهارة الجديدة.

استخدمها في TypingMind

فعّل Container Image Hardening في أي محادثة على TypingMind وسيتولى النموذج الباقي. تتضمن مطالبة النظام اسمها ووصفها، وبمجرد ورود طلب ذي صلة، يُحمّل النموذج التعليمات الكاملة تلقائيًا — فلا تحتاج إلى استدعائها يدويًا، ولا تستهلك أي توكنات حتى تُستخدم فعليًا.

يُحمّل النموذج مهارة Container Image Hardening تلقائيًا بمجرد ورود طلب ذي صلة بها.

تعمل مع أي نموذج ذكاء اصطناعي

مهارات الذكاء الاصطناعي هي تعليمات بصيغة Markdown وليست شيفرة خاصة بمزوّد معيّن، لذا لا ترتبط Container Image Hardening بالنموذج الذي كُتبت له. ثبّتها مرة واحدة في TypingMind واستخدمها مع GPT-5 أو Claude أو Gemini أو Grok أو DeepSeek أو Mistral أو Llama أو نموذج محلي تشغّله بنفسك — كل ذلك باستخدام مفاتيح API الخاصة بك.

  • تُحمَّل عند الحاجة فقط

    تتضمن مطالبة النظام الاسم والوصف فقط. وتُجلب التعليمات عند أول طلب ذي صلة، لذا لا تستهلك تعليمات المهارة أي توكنات ما دامت المهارة غير مستخدمة.

  • بدّل النماذج أثناء المحادثة

    لأن المهارة تعليمات وليست شيفرة، فإن تغيير النموذج لا يعطّلها — فالنموذج التالي يقرأ ملف SKILL.md نفسه.

تعليمات المهارة

هذا هو محتوى SKILL.md الذي يُحمّله النموذج. اقرأه قبل التثبيت — فالمهارة عبارة عن تعليمات سيتبعها نموذجك.

Container Image Hardening

Purpose

A container image built from a full general-purpose base image (e.g. a default Ubuntu or Debian image with a shell, package manager, and dozens of unrelated utilities) running as root gives an attacker who compromises the application inside it a much larger toolkit and a much easier path to container breakout or lateral movement than a minimal, non-root image with no shell and only the application's actual runtime dependencies. Container image hardening is about shrinking that attack surface at build time: using multi-stage builds so build tooling never ships in the final image, choosing minimal or distroless base images, running as a non-root user, making the root filesystem read-only, dropping unnecessary Linux capabilities, and pinning base images by digest so "the same image" can't silently change out from under you. None of this replaces vulnerability scanning of what is in the image — it reduces what's there to scan and what's exploitable if a vulnerability is found.

When to use

  • The user asks to "harden this Dockerfile" or "reduce the attack surface" of a container image.
  • A container/SCA scan flags a base image with dozens of OS-level vulnerabilities and the user wants to address the base image itself, not just individual CVEs.
  • The user wants to fix a "runs as root" finding from a security scanner, admission-policy rejection, or manual review.
  • The user is deciding between a distroless, Alpine, minimal, or full-distribution base image for a given language/runtime.
  • The user wants to set Kubernetes securityContext fields (runAsNonRoot, readOnlyRootFilesystem, allowPrivilegeEscalation: false, dropped capabilities) consistently across workloads.
  • The user is troubleshooting a hardened image that fails at runtime (permission errors, missing shell for debugging, missing writable temp directory) and needs to understand the trade-offs.

Prerequisites & environment

  • Docker or another OCI-compatible builder (Buildah, Podman, BuildKit) supporting multi-stage builds (standard in Docker since 18.09+, and in essentially all current tooling).
  • Familiarity with the target application's actual runtime dependencies — hardening requires knowing what the app truly needs at runtime versus what's only needed to build it, which usually means reading the existing Dockerfile and build process rather than guessing.
  • Base image choices to evaluate:
    • Distroless (gcr.io/distroless/*) — no shell, no package manager, only the language runtime and its direct OS-level dependencies; smallest attack surface, but harder to debug (no exec-into-shell) and requires a compatible language runtime image per stack (distroless/java, distroless/nodejs, distroless/cc for compiled binaries with a C library, distroless/static for fully static binaries e.g. Go with CGO disabled).
    • Alpine — small (musl libc, apk package manager), widely used, but musl's subtle differences from glibc occasionally break compiled dependencies (e.g. some Python/Node native modules); still ships a shell and package manager unless explicitly stripped.
    • -slim variants (e.g. python:3.12-slim, node:20-slim) — a reasonable middle ground: much smaller than the full image, glibc-based (fewer compatibility surprises than Alpine), still has a shell.
    • Full-distribution images (ubuntu, debian, default python:3.12) — largest attack surface and image size; rarely justified for a final runtime image, sometimes needed as a build stage.
  • Kubernetes cluster (if hardening deploy-time securityContext) with admission-policy enforcement optional but recommended — see policy-as-code-guardrails to make these properties mandatory rather than best-effort.

Step-by-step guidance

  1. Split the build into stages, so build-only tooling (compilers, dev package variants, source code not needed at runtime) never reaches the final image:

    dockerfile
    # syntax=docker/dockerfile:1
    FROM golang:1.22 AS builder
    WORKDIR /src
    COPY go.mod go.sum ./
    RUN go mod download
    COPY . .
    RUN CGO_ENABLED=0 GOOS=linux go build -o /out/app ./cmd/app
    
    FROM gcr.io/distroless/static-debian12:nonroot
    COPY --from=builder /out/app /app
    USER nonroot:nonroot
    ENTRYPOINT ["/app"]
  2. Pin the base image by digest, not just tag, for anything you consider "the same" across rebuilds — tags are mutable and can be repointed by the upstream maintainer:

    dockerfile
    FROM python:3.12-slim@sha256:<digest> AS base

    Balance this against staying current on security patches: pinning by digest requires an explicit, deliberate bump process (e.g. a Renovate/Dependabot rule that tracks base-image digests) rather than silently freezing on a vulnerable base forever.

  3. Run as a non-root user explicitly — don't rely on a base image's default (distroless/*-nonroot variants set this for you; for others, create and switch to a dedicated user):

    dockerfile
    RUN addgroup --system app && adduser --system --ingroup app app
    USER app:app
  4. Set a read-only root filesystem at deploy time, with an explicit writable volume only where genuinely needed (temp files, cache):

    yaml
    # Kubernetes pod securityContext
    securityContext:
      runAsNonRoot: true
      readOnlyRootFilesystem: true
      allowPrivilegeEscalation: false
      capabilities:
        drop: ["ALL"]
    volumes:
      - name: tmp
        emptyDir: {}
    volumeMounts:
      - name: tmp
        mountPath: /tmp
  5. Drop all Linux capabilities and add back only what's required — most application containers need none of the default capability set:

    yaml
    securityContext:
      capabilities:
        drop: ["ALL"]
        # add: ["NET_BIND_SERVICE"]  # only if binding to a port < 1024
  6. Remove build-time secrets and unnecessary files from the final image — use BuildKit secret mounts for anything credential-like during build (see secrets-management), and a .dockerignore to keep .git, local env files, and test fixtures out of the build context entirely:

    # .dockerignore
    .git
    .env*
    **/__pycache__
    node_modules
    *.md
  7. Scan the built image, not just the Dockerfile, since the final image is what actually ships:

    bash
    trivy image --severity CRITICAL,HIGH myorg/myapp:1.4.2

    See software-composition-analysis-sca for the full scanning workflow.

  8. Verify hardening holds at runtime, not just at build time — a Dockerfile with USER app can still be overridden by a Kubernetes pod spec with runAsUser: 0; enforce the deploy-time properties via an admission policy (see policy-as-code-guardrails) so the Dockerfile's intent can't be silently undone at deploy time.

Best practices

  • Treat multi-stage builds as the default, not an optimization — any Dockerfile with a compiler, dev headers, or source checkout that also runs the application in the same final stage is very likely shipping unnecessary attack surface.
  • Choose the smallest base image the application can actually run reliably on: distroless/static for statically-linked binaries (Go, Rust with musl target), a -slim glibc-based image for interpreted languages with native extensions where Alpine's musl libc causes friction, Alpine where compatibility is confirmed and size matters most.
  • Set non-root, read-only-root, dropped-capabilities, and no-privilege-escalation together as a bundle — these four properties compound: a non-root user with a writable root filesystem is still meaningfully weaker than the same user with a read-only filesystem.
  • Pin base images by digest for reproducibility, but pair it with an automated process to bump that digest regularly (Renovate/Dependabot digest-update rules) — an unpinned :latest drifts unpredictably, but a digest pinned once and never revisited silently accumulates unpatched base-image CVEs, which is not obviously better.
  • Enforce hardening properties at the Kubernetes admission layer in addition to the Dockerfile — a well-hardened image can still be run insecurely (runAsUser: 0, capabilities added back, writable root filesystem) by pod spec alone, and only cluster-side enforcement guarantees the properties actually hold at runtime.
  • Keep a debug story for distroless/no-shell images before you need it in an incident — e.g. a separate debug image variant with a shell built from the same application layer, or kubectl debug with an ephemeral container attached to the running pod — rather than discovering during an incident that you can't exec in at all.

Common pitfalls

  • Symptom: Switching to a distroless base image breaks the ability to kubectl exec -it into the container to debug an issue. Fix: This is expected — distroless images have no shell by design. Use kubectl debug <pod> -it --image=busybox --target=<container> to attach an ephemeral debug container with a shell to the running pod's namespaces instead of relying on exec-into-the-app-container, or maintain a separate -debug image tag with a shell for troubleshooting builds specifically.

  • Symptom: An Alpine-based image works in local Docker Desktop testing but a compiled Python/Node native dependency fails or behaves differently in the CI/production Alpine build. Fix: This is usually musl libc vs. glibc incompatibility in a native extension; either switch that stage to a glibc-based -slim image, or confirm the specific native dependency has verified musl support before committing to Alpine for that service.

  • Symptom: Setting readOnlyRootFilesystem: true causes the application to crash on startup with a permission or "read-only file system" error. Fix: The app is writing somewhere in the root filesystem at runtime (temp files, a cache directory, a PID file) — identify the path (check the crash log/strace) and mount a dedicated emptyDir (or persistent volume, if it must survive restarts) at exactly that path rather than reverting the read-only setting entirely.

  • Symptom: A Dockerfile sets USER app but the running pod in Kubernetes still shows the process running as root (UID 0). Fix: Something in the deploy path (runAsUser: 0 in the pod spec, or a Helm chart default) is overriding the image's default user; Kubernetes pod spec takes precedence over the Dockerfile USER instruction. Set and enforce runAsNonRoot: true in the pod securityContext and consider an admission policy to prevent this override cluster-wide (see policy-as-code-guardrails).

  • Symptom: Image size and vulnerability count barely improve after switching base images, and the SCA scan still shows the same dozens of CRITICAL findings. Fix: Check whether build-stage tooling or dev dependencies are still leaking into the final stage (missing COPY --from=builder scoping, or installing dev packages in the final stage instead of only the builder stage) — the base image swap alone doesn't help if the Dockerfile still installs a compiler or full package set in the runtime stage.

Worked example

A Go HTTP service is rewritten from a single-stage, root, full-Debian Dockerfile to a hardened multi-stage, distroless, non-root build, with matching Kubernetes securityContext.

Before:

dockerfile
FROM golang:1.22
WORKDIR /app
COPY . .
RUN go build -o server ./cmd/server
CMD ["./server"]

(Runs as root, ships the full Go toolchain and source tree, ~900MB image, default Debian base with a shell and package manager.)

After:

dockerfile
# syntax=docker/dockerfile:1
FROM golang:1.22 AS builder
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -o /out/server ./cmd/server

FROM gcr.io/distroless/static-debian12:nonroot@sha256:<digest>
COPY --from=builder /out/server /server
USER nonroot:nonroot
ENTRYPOINT ["/server"]

Corresponding Kubernetes pod hardening:

yaml
apiVersion: v1
kind: Pod
metadata:
  name: myapp
spec:
  containers:
    - name: myapp
      image: myorg/myapp:1.4.2@sha256:<image-digest>
      securityContext:
        runAsNonRoot: true
        readOnlyRootFilesystem: true
        allowPrivilegeEscalation: false
        capabilities:
          drop: ["ALL"]
      volumeMounts:
        - name: tmp
          mountPath: /tmp
  volumes:
    - name: tmp
      emptyDir: {}

Result: image size drops from ~900MB to under 20MB (statically-linked Go binary plus a near-empty distroless base), the final image ships no shell/package manager/source tree for an attacker to leverage after a compromise, a trivy image scan on the new image shows a dramatically smaller finding count because there's no OS package layer to accumulate CVEs, and the pod-level securityContext guarantees the container can't be started as root or with a writable filesystem even if someone edits the deployment manifest later — assuming an admission policy is in place to keep that guarantee from being quietly overridden.

Cross-references

  • software-composition-analysis-sca — scanning the resulting image for known vulnerabilities in whatever base-image packages and dependencies remain.
  • supply-chain-security-slsa-sbom — generating an SBOM and signing the hardened image so its provenance can be verified downstream.
  • policy-as-code-guardrails — enforcing non-root/read-only/dropped-capabilities requirements at Kubernetes admission time so a hardened Dockerfile's properties can't be silently overridden by a pod spec.

الأسئلة الشائعة

ماذا تفعل مهارة الذكاء الاصطناعي Container Image Hardening؟

Guides building minimal, non-root, hardened container images — multi-stage builds, distroless/minimal base images, non-root users, read-only root filesystems, dropped Linux capabilities, and pinned/ digest-referenced base images. Use when the user asks to "harden this Dockerfile", "reduce container image attack surface/size", "make our container run as non-root", "switch to a distroless base image", "fix a container security scan finding about running as root or having a shell", or "set Kubernetes securityContext restrictions for a pod".

لماذا تستخدم Container Image Hardening على TypingMind؟

لأنك تثبّتها مرة واحدة وتستخدمها مع أي نموذج. مهارة Container Image Hardening عبارة عن نص Markdown وليست شيفرة خاصة بمزود بعينه، لذا تعمل المهارة نفسها مع GPT-5 أو Claude أو Gemini أو Grok أو نموذج محلي، ويمكنك تبديل النموذج أثناء المحادثة دون تعطّل المهارة. يعمل TypingMind بمفاتيح API الخاصة بك، فتدفع للمزودين مباشرةً بدلًا من اشتراك لكل مقعد، وتبقى مهاراتك ومحادثاتك في مساحة التخزين الخاصة بك.

كيف أثبّت Container Image Hardening في TypingMind؟

في TypingMind، افتح «الإضافات»، ثم «المهارات»، ثم اختر «التثبيت من GitHub» والصق https://github.com/selvarajmurugesan90/ops-engineering-skills/tree/main/plugins/devsecops/skills/container-image-hardening. يقرأ TypingMind ملف SKILL.md الخاص بالمهارة ويثبّتها كمهارة يمكنك تفعيلها لكل محادثة على حدة.

ما نماذج الذكاء الاصطناعي التي يمكنها استخدام Container Image Hardening؟

أي نموذج تربطه في TypingMind. مهارات الذكاء الاصطناعي عبارة عن تعليمات Markdown وليست شيفرة خاصة بمزود بعينه، لذا يمكن لكل من GPT وClaude وGemini وGrok والنماذج المحلية تحميل هذه المهارة عندما يتوافق الطلب معها.

كم نموذج ذكاء اصطناعي يمكنني استخدامه مع Container Image Hardening؟

أي عدد تريده. ما دام النموذج يدعم المهارات، يمكنك استخدام Container Image Hardening معه، سواء كان GPT أو Claude أو Gemini أو Grok أو DeepSeek أو Mistral أو Llama أو غيرها، وكل ذلك على TypingMind باستخدام مفاتيح API الخاصة بك.

هل مهارة الذكاء الاصطناعي Container Image Hardening مجانية؟

نعم. نشرها selvarajmurugesan90 على GitHub بموجب ترخيص Apache-2.0. لا تدفع إلا لمزود الذكاء الاصطناعي الخاص بك مقابل التوكنات التي تستخدمها.

ما هي مهارات الذكاء الاصطناعي؟

مهارة الذكاء الاصطناعي حزمة تعليمات قابلة لإعادة الاستخدام تعلّم نموذج الذكاء الاصطناعي كيفية تنفيذ مهمة محددة. وتتبع تنسيق Agent Skills المفتوح: ملف SKILL.md يتضمن اسمًا ووصفًا، إلى جانب أي نصوص برمجية أو قوالب أو ملفات مرجعية قد يحتاج إليها النموذج. لا يقرأ النموذج التعليمات إلا عندما يتوافق طلبك مع المهارة، لذا لا تترتب على المهارة المثبتة أي تكلفة حتى تُستخدم.

كيف تختلف مهارات الذكاء الاصطناعي عن الإضافات أو موصلات MCP؟

تمنح الإضافة أو موصل MCP النموذج أدوات جديدة يمكنه استدعاؤها، وهي شيفرة تُنفَّذ في مكان ما وتُرجع نتيجة. أما مهارة الذكاء الاصطناعي فتزوّد النموذج بالمعرفة ومنهجية العمل: كيفية التعامل مع مهمة، والخطوات التي ينبغي اتباعها، وما ينبغي أن تكون عليه المخرجات الجيدة. المهارات عبارة عن نصوص Markdown، لذا لا تحتاج إلى خادم أو مفتاح API أو بيئة تشغيل، وتعمل مع أي نموذج.

عرض الكل
شعار openclaw

Openclaw Ci Limits

openclaw
مؤسسةشائع

أدِر سعة GitHub Actions وBlacksmith CI في OpenClaw، وميزانيات تسجيل المشغّلات، وحدود التوزيع المتوازي، وضمان تشغيل مهمة واحدة لكل دفعة دفع إلى main، وتحديد أحجام الأجزاء، ونقل الأحمال إلى المشغّلات المستضافة، وصحة قائمة الانتظار، والتدرّج الآمن في خفض السعة وزيادتها…

82.2K
391K
الملفات: 1
عرض
شعار openclaw

Openclaw Debugging

openclaw
مؤسسةشائع

شخّص مشكلات النماذج ومزوّدي الخدمة وواجهات الأدوات ووضع البرمجة والبث المباشر وسلوك OpenClaw المباشر/Crabbox، باختيار السجلات والفحوصات ومسار التحقق المناسب قبل تغيير الشيفرة، بما في ذلك جلب الجلسات المحفوظة…

82.2K
391K
الملفات: 1
عرض
شعار openclaw

Openclaw Live Updater

openclaw
مؤسسةشائع

حافِظ على نسخة العمل الرئيسية المعتمدة من OpenClaw، وGateway المُدار عبر LaunchAgent على macOS، وتطبيق macOS المحلي، وCI للفرع main عند رأس الالتزام المحدد، والتحقق الكامل والمتكرر من الإصدارات. استخدمها لتحديثات التقديم السريع…

82.2K
391K
الملفات: 2
عرض
شعار openclaw

Openclaw Pr Maintainer

openclaw
مؤسسةشائع

راجِع مشكلات OpenClaw وطلبات السحب، وفرزها، وإصلاحها أو دمجها، مستندًا إلى أدلة من المصدر الحالي وسير عمل المشرفين الأصلي.

82.2K
391K
الملفات: 5
عرض

أنشئ مساحة عملك للذكاء الاصطناعي الآن

اشترك في نشرتنا الإخبارية لتصلك أخبار الميزات الجديدة والهدايا القادمة 👇