Podman subuid/subgid & User Namespace Sizing Prompt
Allocate non-overlapping subuid/subgid ranges and pick a user namespace mapping strategy for a host running rootless Podman for multiple tenants.
- Target user
- Sysadmins and platform engineers running shared rootless Podman hosts
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT
The prompt
You are a senior Linux systems engineer who treats ID-range allocation as a security boundary, because on a multi-tenant host it is one. I will provide some or all of: - The current `/etc/subuid` and `/etc/subgid` contents - How many tenant users exist now, the expected growth, and whether users are local or come from LDAP/SSSD - What each tenant runs: single-UID applications, or images that need many distinct in-container UIDs - Symptoms if any: "there might not be enough IDs available in the namespace", chown failures during image pull, files owned by nobody/nogroup on volumes, or overlapping ranges between users - Whether volumes are shared between tenants and whether SELinux is enforcing Your job: 1. **Explain what the ranges actually control** — describe how a rootless container maps container UID 0 to the invoking user's host UID and container UIDs 1..N to the user's subuid range, and why the range size caps the highest in-container UID an image can use. Make clear that an image with a high UID in its `USER` directive fails on a short range. 2. **Audit the existing allocation** — parse the provided files for overlaps between users, gaps, ranges smaller than the conventional 65536, and users missing entries entirely. Overlapping ranges mean two tenants can write each other's files as the same host UID; call this out as a finding, not a note. 3. **Design the allocation plan** — propose a start offset well above any real host UID and above the `SYS_UID_MAX`/login UID space, a per-user range size justified by the UIDs the tenants' images actually need, and a fixed stride so allocation is arithmetic rather than ad hoc. Show the resulting table for the first several tenants and the total host-wide consumption against the available ID space. 4. **Give the provisioning commands** — use `usermod --add-subuids` and `--add-subgids` (or the equivalent `useradd` options at creation time) rather than hand-editing, and state the mandatory follow-up: after changing a user's ranges, `podman system migrate` must run as that user so existing containers and storage are remapped, and note that already-created containers may otherwise become unusable. 5. **Choose the mapping mode per workload** — compare the default mapping, `--userns=keep-id` (with `uid=`/`gid=` options) for bind mounts where host file ownership must line up, `--userns=nomap` for stronger isolation of the host user's own files, and `--userns=auto` (with `size=`) which draws from the range assigned to the `containers` user in `/etc/subuid`. Recommend one per workload class and explain the file-ownership consequence of each. 6. **Handle shared and bind-mounted storage** — explain why files appear as `nobody` across namespaces, and prescribe the fix: `keep-id` mapping, the `:U` mount option to recursively chown a volume into the mapped range, or `podman unshare chown` from inside the user namespace. Warn that `:U` rewrites ownership on the host path. 7. **Cover LDAP and non-local users** — note that subuid/subgid lookup does not automatically follow directory-provided users, and describe the options: local `/etc/subuid` entries per user, or an NSS/SSSD configuration that supplies the ranges, with the failure symptom if neither is in place. 8. **Verify the result** — give per-user checks: `podman unshare cat /proc/self/uid_map`, `podman info` fields showing the ID mappings, a test container running as a high UID, and a cross-tenant write test proving isolation holds. Output as: (a) explanation of range semantics, (b) audit findings on the current allocation with severity, (c) allocation table and sizing math, (d) provisioning commands including the migrate step, (e) userns mode recommendation per workload, (f) shared-storage handling, (g) directory-user notes, (h) verification commands. Changing a user's subuid/subgid range after containers exist can orphan that user's storage. Always state the backup and `podman system migrate` sequence before recommending a range change on a host with live workloads.
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
ID-range allocation looks like bookkeeping and behaves like a security boundary, which is the framing this prompt insists on from the first line. On a single-user workstation an overlapping or undersized range is an annoyance. On a shared host, overlapping ranges mean two tenants map to the same host UIDs and can write each other’s files, so the audit step is instructed to report overlaps as findings with severity rather than as notes in a table.
The sizing logic is grounded in what actually fails. A rootless container maps container UID 0 to the invoking user and UIDs 1..N to the subuid range, so the range size caps the highest in-container UID an image can use — which is why an image with a high UID in its USER directive dies with “there might not be enough IDs available in the namespace” on a short range. Tying the range size to the UIDs tenants’ images genuinely need, with a fixed stride and a start offset above the login UID space, makes allocation arithmetic instead of ad hoc, and makes the host-wide consumption calculable before the tenth tenant arrives.
The two operational traps get their own steps because both are silent. Changing a range without running podman system migrate as that user leaves their existing storage mapped to IDs they no longer own; and subuid lookup does not automatically follow LDAP or SSSD-provided users, so a directory-backed tenant can have no entries at all with a failure that reads as a Podman bug. Requiring the migrate sequence, the backup, and the per-user verification commands turns a range change from a config edit into a procedure someone can execute on a live host.
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.
-
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.
-
Rootless Podman in CI Pipelines Prompt
Get rootless Podman building and running containers reliably inside GitLab CI or GitHub Actions runners, including nested-container and storage-driver constraints.
-
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.
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.