Podman Container Security Hardening Prompt
Harden a Podman container with dropped capabilities, no-new-privileges, a read-only rootfs, a tuned seccomp profile, and a user namespace mapping that actually fits the workload.
- Target user
- Platform and security engineers hardening Podman workloads without breaking them
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT
The prompt
You are a senior container security engineer who hardens workloads without breaking them. You know rootless Podman already removes a large class of risk by running the container's root as an unprivileged host UID, and that this is a starting point rather than the finish line. You know `--cap-drop=ALL` followed by explicit `--cap-add` is the only defensible capability posture, that `--security-opt no-new-privileges` blocks setuid escalation inside the container, that `--read-only` needs `--read-only-tmpfs` or explicit tmpfs mounts for paths the app writes, and that `--userns=auto` gives each container its own UID range rather than sharing one mapping. I will describe the workload. Produce a hardening plan that it survives. Steps: 1. **Establish the baseline**: record whether the container runs rootless or root, the effective capabilities via `podman top <ctr> capeff`, the user it runs as inside, and what it writes to disk at runtime — hardening without this is guesswork. 2. **Reduce capabilities to the minimum**: start from `--cap-drop=ALL`, then add back only the capabilities with a demonstrated need, naming the specific operation that requires each. Treat `NET_ADMIN`, `SYS_ADMIN`, and `SYS_PTRACE` as requiring written justification. 3. **Block privilege escalation**: apply `--security-opt no-new-privileges` and identify anything in the image that depends on setuid binaries, since that is what will break. 4. **Make the rootfs read-only**: set `--read-only`, enumerate every path the app writes, and provide tmpfs mounts or named volumes for exactly those — do not grant a writable rootfs because one log path was missed. 5. **Tune seccomp deliberately**: keep Podman's default profile unless a specific syscall is proven blocked, and if a custom profile is needed, derive it from the default and add the minimum rather than starting from unconfined. Show how to identify the blocked syscall from the failure. 6. **Design the user namespace**: choose between the default rootless mapping, `--userns=auto` for per-container isolated ranges, and `--userns=keep-id` where the container must match the host user's UID for volume access, explaining the file-ownership consequence of each. 7. **Constrain the remaining surface**: set `--pids-limit`, memory and CPU limits, drop unneeded devices, avoid mounting the Podman socket into the container, and never use `--privileged` — call out any request for it and propose the specific capabilities that would replace it. 8. **Verify and stage**: give the commands that prove each control is active (`podman inspect` for security options, `podman top capeff`, a write attempt against the read-only rootfs), and a staged rollout that applies controls one at a time so a break is attributable. Fill in: - Workload and image: [DESCRIBE] - Rootless or root, and current run/Quadlet config: [PASTE] - Paths written at runtime: [LIST] - Known privileged operations the app performs: [DESCRIBE] - Compliance requirements: [DESCRIBE] Output as: (a) the hardened `podman run` command with every security flag justified, (b) the equivalent Quadlet directives, and (c) a control-by-control table of what it blocks, what could break, and the verification command — plus the staged rollout order. Do not apply every control at once in production. Stage them one at a time so a failure points at a specific control, and never substitute `--privileged` for the work of identifying the capabilities actually needed.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Why this prompt works
Hardening guides usually fail in one of two directions: they list every available control with no guidance on what breaks, or they stop at “run it rootless” as though the user namespace solved the problem. This prompt treats rootless as the baseline it actually is and then works through the controls that still matter — capabilities, escalation blocking, filesystem writability, syscall filtering, and namespace design — each tied to a specific thing it prevents. That framing is what makes the output reviewable rather than a checklist someone applies until something stops working.
The read-only rootfs step reflects how these changes fail in practice. --read-only is one of the highest-value controls available and it breaks applications constantly, because almost every image writes somewhere unexpected — a PID file, a cache directory, a temp path buried in a library. The tempting response is to drop the flag entirely, which trades a strong control for one unenumerated log path. Requiring the write paths to be listed and mounted individually keeps the control in place at the cost of a few minutes of investigation.
The staged rollout in step eight is the operational insight that makes the rest usable. Applying dropped capabilities, no-new-privileges, a read-only rootfs, and a custom seccomp profile in a single change produces a container that fails for an unknown reason, and the near-universal response is to revert all of it. Applying them one at a time, with a verification command per control, means a break is immediately attributable and only the offending control needs adjusting. That is the difference between hardening that survives contact with production and hardening that gets rolled back on the first incident.
Related prompts
-
Podman SELinux Volume Labeling Strategy Prompt
Decide between :z, :Z, and permanent host relabeling for every Podman mount so containers get access without weakening SELinux or corrupting host directory labels.
-
Rootless Podman Readiness Audit Prompt
Audit a host for rootless Podman readiness — subuid/subgid ranges, user lingering, cgroup v2 delegation, sysctls, and storage — before workloads are deployed.
-
Docker to Podman Team Migration Plan Prompt
Produce a phased Docker-to-Podman migration plan covering socket compatibility, CI impact, rootless gaps, and the developer workflow changes a team will actually hit.
-
Dockerfile to Buildah Build Script Conversion Prompt
Convert a Dockerfile into an equivalent scripted buildah build so image construction can use host tooling, secrets, and logic that Dockerfile syntax cannot express.
More Podman prompts & error guides
Browse every Podman prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.