Logo: Container Hardening

Container Hardening

Organisatioun
RedHatProductSecurity
container-hardening

Harden container images and runtime configuration. Use when building, reviewing, or auditing Containerfiles, Dockerfiles, container compose files, or Kubernetes pod security settings.

Iwwersiicht

EditeurRedHatProductSecurity
Repositoryprodsec-skills
Skill-Nummcontainer-hardening
Stären
56
Forks
9
Matgeliwwert Dateien
Nëmmen Instruktiounen
LizenzApache-2.0
Linken
  • Instruktiounen am Markdown-Format

    Eng SKILL.md-Datei, déi de Modell bei Bedarf luet, soudatt nëmmen Token ufalen, wann eng Ufro tatsächlech dozou passt.

  • Funktionéiert mat all LLM

    KI-Skills si reng Markdown, keen ubidderspezifesche Code. Dofir funktionéiert dëse Skill mat GPT, Claude, Gemini, Grok oder engem lokale Modell.

  • Alles an den Instruktiounen

    Alles, wat de Modell brauch, steet an den Instruktiounen — keng zousätzlech Dateien ze synchroniséieren.

  • Open Source

    RedHatProductSecurity huet de Skill op GitHub verëffentlecht. Liest de Quelltext, ier Dir de Skill installéiert.

Installatioun

Installéiert de KI-Skill Container Hardening an TypingMind, fir e mat all LLM ze benotzen, oder setzt en an en anere KI-Agent an, deen SKILL.md liest.

1

An TypingMind installéieren

TypingMind installéiert e Skill direkt aus sengem GitHub-Dossier — dobäi gëtt SKILL.md gelies, d'Ressourcedateie gi gebëndelt an d'Resultat gëtt lokal gespäichert.

  1. Maacht d'App op a gitt op Plugins → Skills.
  2. Wielt „Vu GitHub installéieren“.
  3. Pecht d'URL vum Skill-Dossier, déi hei drënner steet, an a bestätegt d'Installatioun.
    https://github.com/RedHatProductSecurity/prodsec-skills/tree/main/ge-core/container-hardening
  4. Aktivéiert de Skill an all Chat, an deem Dir e benotze wëllt.
Plugins → Skills → Skill derbäisetzen → Iwwer eng GitHub-URL. Pecht dann d'URL vum Dossier an a klickt op Weider.
2

An engem anere KI-Agent installéieren

All KI-Agent, deen d'Format Agent Skills liest, kann dëse Skill benotzen — kopéiert den Dossier an d'Skill-Verzeechnes vun deem KI-Agent.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/RedHatProductSecurity/prodsec-skills.git /tmp/prodsec-skills
mkdir -p .claude/skills
cp -r /tmp/prodsec-skills/ge-core/container-hardening .claude/skills/container-hardening
Start Claude Code nom Kopéieren nei, fir datt den neie Skill erkannt gëtt.

An TypingMind benotzen

Aktivéiert Container Hardening an engem Chat vun TypingMind, an de Modell iwwerhëlt de Rescht. Den Numm an d'Beschreiwung stinn am System-Prompt. Soubal eng Ufro dozou passt, luet de Modell déi komplett Instruktioune selwer — Dir musst de Skill ni manuell opruffen, an et fale keng Token un, bis en tatsächlech benotzt gëtt.

De Modell luet Container Hardening automatesch, soubal eng Ufro dozou passt.

Funktionéiert mat all KI-Modell

KI-Skills si reng Markdown-Instruktiounen amplaz vun ubidderspezifeschem Code. Dofir ass Container Hardening net un de Modell gebonnen, fir deen de Skill geschriwwe gouf. Installéiert en eemol an TypingMind a benotzt e mat GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama oder engem lokale Modell, deen Dir selwer bedreift — alles mat Ären eegenen API-Schlësselen.

  • Gëtt nëmme gelueden, wann et néideg ass

    De System-Prompt enthält nëmmen den Numm an d'Beschreiwung. D'Instruktioune gi bei der éischter passender Ufro gelueden, soudatt en onbenotzte Skill näischt kascht.

  • De Modell am lafende Chat wiesselen

    Well de Skill aus Instruktiounen amplaz vu Code besteet, funktionéiert en och no engem Modellwiessel — den nächste Modell liest déi selwecht SKILL.md-Datei.

Skill-Instruktiounen

Dëst ass den Inhalt vu SKILL.md, deen de Modell luet. Liest e virun der Installatioun — e Skill besteet aus Instruktiounen, déi Äre Modell befollegt.

Container Hardening

Secure container images and runtime configuration to reduce attack surface, prevent privilege escalation, and ensure compliance with Kubernetes security best practices.

Base Image Selection

  • Use a Universal Base Image (UBI) from the official Red Hat Container Registry
  • Prefer ubi-minimal (ubi8/ubi-minimal or ubi9/ubi-minimal) to reduce attack surface
  • Use the most up-to-date image available

Required for: all profiles (mandatory)

Image Tagging Strategy

SourceStrategy
Red Hat CatalogOmit floating tags to get the latest image; exception: Konflux project uses digest-based pinning with automated updates
Non-Red Hat registriesPin the version or digest to ensure you use the intended image and not a tampered one

Minimize Installed Software

Remove non-essential packages and clean up package manager caches:

dockerfile
RUN microdnf upgrade -y && \
    microdnf install -y <required-packages> && \
    microdnf remove -y <unnecessary-packages> && \
    microdnf clean all

Use microdnf on ubi-minimal images; dnf on full UBI images.

Runtime Security

Non-Root Execution

Containers must not run as root. Set runAsNonRoot: true and provide a numeric non-root USER in the Containerfile.

Required for: all profiles (mandatory)

dockerfile
USER 1000
yaml
securityContext:
  runAsNonRoot: true
  runAsUser: 1000

Either the pod-level or container-level securityContext can set these fields. Do not use UID 0 (root) or UID 1337 (reserved for Istio sidecar proxies).

Required for: Extended (mandatory), all others (optional) — UID 1337 restriction

Privilege Restrictions

Set allowPrivilegeEscalation: false to prevent privilege escalation during container execution:

Required for: all profiles (mandatory)

yaml
securityContext:
  allowPrivilegeEscalation: false

Or in a compose file:

yaml
security_opt:
  - no-new-privileges: true

Read-Only Filesystem

Use read-only root filesystems wherever possible:

Required for: all profiles (optional, recommended best practice)

yaml
securityContext:
  readOnlyRootFilesystem: true

Mount writable tmpfs volumes only where the application requires write access (e.g., /tmp, /var/run).

Read-Only Volumes

Mount volumes as read-only unless the container must write to them:

yaml
volumeMounts:
  - name: config
    mountPath: /etc/app
    readOnly: true

Service Account Token

Disable automatic mounting of the Kubernetes API service account token unless the pod needs API access:

Required for: Telco (mandatory), Far-Edge (mandatory), Extended (mandatory), Non-Telco (optional)

yaml
spec:
  automountServiceAccountToken: false

Pods that require API access (e.g., operators, controllers) should use a dedicated service account with minimal RBAC permissions and explicitly set automountServiceAccountToken: true.

One Process Per Container

Each container should run a single process. This simplifies monitoring, log collection, debugging, and security assessment. Use sidecar containers for auxiliary tasks (log shipping, proxy, etc.) rather than running multiple daemons in one container.

Required for: all profiles (optional, recommended best practice)

No SSH Daemons

Containers must not run SSH daemons. SSH in containers creates additional attack surfaces and violates immutable infrastructure principles. Use kubectl exec or oc debug for troubleshooting instead.

Required for: Telco (mandatory), Far-Edge (mandatory), Extended (mandatory), Non-Telco (optional)

Security Context Categories

The certsuite defines 4 approved security context categories based on required Linux capabilities. Target Category 1 (most restrictive) unless the workload requires advanced networking or DPDK.

Required for: Extended (mandatory), all others (optional)

CategoryDescriptionAdded Capabilities
Category 1Limited access (default)None
Category 1 (no UID 0)Basic rights with mesh networksNone (runAsNonRoot: true)
Category 2Advanced networking (VLAN tag, DSCP, priority)NET_ADMIN, NET_RAW
Category 3SR-IOV and DPDKNET_ADMIN, NET_RAW, IPC_LOCK

All categories require:

  • Drop capabilities: ALL (or at minimum MKNOD, SETUID, SETGID, KILL)
  • No host access: hostIPC: false, hostNetwork: false, hostPID: false, no hostPort
  • No privileged containers: privileged: false
  • User identity: runAsUser and fsGroup set, SELinux context present
  • Allowed volume types only: ConfigMap, DownwardAPI, EmptyDir, PersistentVolumeClaim, Projected, Secret

Example: Category 1 Security Context (Preferred)

yaml
spec:
  securityContext:
    runAsNonRoot: true
    runAsUser: 1000
    fsGroup: 1000
    seLinuxOptions:
      type: container_t
  containers:
    - name: app
      image: registry.example.com/app:v1.2.3
      securityContext:
        allowPrivilegeEscalation: false
        readOnlyRootFilesystem: true
        capabilities:
          drop: ["ALL"]

Base Image Integrity

Container base images must not be modified after startup. All required binaries and dependencies must be built into the image at build time.

Required for: all profiles (mandatory)

Protected directories that must remain unchanged at runtime: /bin, /sbin, /lib, /lib64, /usr/bin, /usr/sbin, /usr/lib, /usr/lib64, /var/lib/rpm, /var/lib/dpkg

OpenShift Note: SELinux must be in Enforcing mode on all cluster nodes (mandatory across all profiles). Base images must be Red Hat UBI (mandatory across all profiles).

Containerfile Linting

Use Hadolint to lint Containerfiles for best-practice violations and inline bash issues:

bash
hadolint Containerfile

Hadolint catches common issues (running as root, missing version pins, unnecessary sudo) but should not be trusted without additional verification.

Implementation Checklist

  • Base image is a Red Hat UBI from the official catalog
  • ubi-minimal is used unless a full UBI is justified
  • Non-Red Hat base images are pinned by version or digest
  • Non-essential packages are removed and caches cleaned
  • runAsNonRoot: true is set at pod or container level
  • A numeric non-root USER is set in the Containerfile
  • Container UID is not 0 or 1337
  • allowPrivilegeEscalation: false is set
  • readOnlyRootFilesystem: true is set
  • Volumes are mounted read-only unless writes are required
  • automountServiceAccountToken: false unless API access is required
  • Each container runs a single process
  • No SSH daemons are running in containers
  • Security context matches an approved category (Category 1-3)
  • Required capabilities are dropped (ALL, or at minimum MKNOD, SETUID, SETGID, KILL)
  • Container base image is not modified post-startup
  • SELinux is in Enforcing mode on all cluster nodes
  • Hadolint runs in CI on all Containerfiles
  • Container images are rebuilt regularly to pick up base image updates

Certsuite Test Mapping

GuidanceCertsuite Test IDProfiles
Privilege escalation disabledaccess-control-security-context-privilege-escalationAll profiles: mandatory
Run as non-rootaccess-control-security-context-non-root-user-id-checkAll profiles: mandatory
Read-only root filesystemaccess-control-security-context-read-only-file-systemAll profiles: optional
Security context categoryaccess-control-security-contextExtended: mandatory, all others: optional
UID not 1337access-control-no-1337-uidExtended: mandatory, all others: optional
One process per containeraccess-control-one-process-per-containerAll profiles: optional
Service account tokenaccess-control-pod-automount-service-account-tokenTelco/Far-Edge/Extended: mandatory, Non-Telco: optional
No SSH daemonsaccess-control-ssh-daemonsTelco/Far-Edge/Extended: mandatory, Non-Telco: optional
Base image not modifiedplatform-alteration-base-imageAll profiles: mandatory
SELinux enforcingplatform-alteration-is-selinux-enforcingAll profiles: mandatory
Red Hat base imageplatform-alteration-isredhat-releaseAll profiles: mandatory

References

Heefeg gestallte Froen

Wat mécht de KI-Skill Container Hardening?

Harden container images and runtime configuration. Use when building, reviewing, or auditing Containerfiles, Dockerfiles, container compose files, or Kubernetes pod security settings.

Firwat Container Hardening op TypingMind benotzen?

Well Dir en eemol installéiert a mat all Modell benotze kënnt. Container Hardening besteet aus einfachem Markdown amplaz vun ubidderspezifeschem Code. Dee selwechte Skill funktionéiert also mat GPT-5, Claude, Gemini, Grok oder engem lokale Modell – an Dir kënnt de Modell matzen am Chat wiesselen, ouni datt de Skill ophält ze funktionéieren. TypingMind benotzt Är eegen API-Schlësselen, sou datt Dir d'Ubidder direkt bezuelt, amplaz en Abonnement pro Benotzerplaz ze bezuelen. Är Skills a Chats bleiwen an Ärem eegene Späicher.

Wéi installéieren ech Container Hardening an TypingMind?

Maacht an TypingMind Plugins → Skills → Vu GitHub installéieren op a setzt https://github.com/RedHatProductSecurity/prodsec-skills/tree/main/ge-core/container-hardening an. TypingMind liest d'Datei SKILL.md an installéiert de Skill, deen Dir pro Chat aktivéiere kënnt.

Wéi eng KI-Modeller kënnen Container Hardening benotzen?

All Modell, deen Dir an TypingMind verbënnt. KI-Skills sinn einfach Markdown-Instruktiounen an net ubidderspezifesche Code. Dofir kënne GPT, Claude, Gemini, Grok a lokal Modeller dëse Skill lueden, wann eng Ufro dozou passt.

Wéi vill KI-Modeller kann ech mat Container Hardening benotzen?

Esou vill wéi Dir wëllt. Soulaang e Modell Skills ënnerstëtzt, kënnt Dir Container Hardening domat benotzen – zum Beispill mat GPT, Claude, Gemini, Grok, DeepSeek, Mistral oder Llama – alles op TypingMind mat Ären eegenen API-Schlësselen.

Ass de KI-Skill Container Hardening gratis?

Jo. RedHatProductSecurity huet de Skill ënner der Lizenz Apache-2.0 op GitHub publizéiert. Dir bezuelt nëmmen Ären eegene KI-Ubidder fir d'Token, déi Dir benotzt.

Wat si KI-Skills?

E KI-Skill ass e weiderverwendbare Pak vun Instruktiounen, deen engem KI-Modell bäibréngt, wéi en eng bestëmmt Aufgab erfëllt. E follegt dem oppenen Agent Skills-Format: eng Datei SKILL.md mat engem Numm an enger Beschreiwung, plus all Scripten, Virlagen oder Referenzdateien, déi de Modell eventuell brauch. De Modell liest d'Instruktiounen eréischt, wann Är Ufro zum Skill passt. En installéierte Skill kascht also näischt, bis e benotzt gëtt.

Wéi ënnerscheede sech KI-Skills vu Plugins oder MCP-Serveren?

E Plugin oder MCP-Server gëtt engem Modell nei Tools, déi en opruffe kann – Code, deen iergendwou leeft an e Resultat zeréckgëtt. E KI-Skill gëtt dem Modell dogéint Wëssen an eng Virgoensweis: wéi en eng Aufgab ugeet, wéi eng Schrëtt e maache soll a wéi eng gutt Ausgab ausgesäit. Skills bestinn aus einfachem Markdown, brauche kee Server, keen API-Schlëssel a kee Lafzäitëmfeld a funktionéiere mat all Modell.

Alleguer weisen

Elo Ären eegene KI-Aarbechtsberäich ariichten

Abonnéiert Iech op eisen Newsletter, fir iwwer nei Funktiounen an zukünfteg Gewënnspiller informéiert ze ginn 👇