Skip to content

status: restrict valid container ID names#2077

Open
giuseppe wants to merge 2 commits intocontainers:mainfrom
giuseppe:validate-container-name
Open

status: restrict valid container ID names#2077
giuseppe wants to merge 2 commits intocontainers:mainfrom
giuseppe:validate-container-name

Conversation

@giuseppe
Copy link
Copy Markdown
Member

Allow only IDs that match [a-zA-Z0-9][a-zA-Z0-9_.-]*, following the same naming convention used by Podman and Docker.
IDs starting with a dot are not allowed since the "." prefix is reserved for internal use.

Also reject ".." in delegate-cgroup annotation to prevent misuses.

Closes: #2074

@giuseppe giuseppe force-pushed the validate-container-name branch from 2d94b30 to 0d18d24 Compare April 27, 2026 19:15
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request improves container ID and cgroup path validation by rejecting '..' components and enforcing an alphanumeric naming scheme. It also adds relevant test cases. Review feedback suggests replacing isalnum with explicit ASCII checks to avoid locale-dependency and adding a NULL check to the path utility for better robustness.

Comment thread src/libcrun/status.c
Comment thread src/libcrun/utils.h
giuseppe and others added 2 commits April 27, 2026 21:37
Allow only IDs that match [a-zA-Z0-9][a-zA-Z0-9_.-]*, following
the same naming convention used by Podman and Docker.

IDs starting with a dot are not allowed since the "." prefix is
reserved for internal use.

Closes: containers#2074

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
The run.oci.delegate-cgroup annotation value is used as a path
fragment appended to the container cgroup path.  Even if it is an
unsafe annotation, reject values containing ".." components as a
safety measure and prevent silly mistakes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
@giuseppe giuseppe force-pushed the validate-container-name branch from 0d18d24 to 083ffde Compare April 27, 2026 19:37
Comment thread src/libcrun/status.c
return true;
if (first)
return false;
return c == '_' || c == '.' || c == '-';
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Podman use this regex: ^[a-zA-Z0-9][a-zA-Z0-9_.-]*$.

Docker use this regex: ^[a-zA-Z0-9][a-zA-Z0-9_.-]+$. The difference is, one-letter names are not allowed (I checked that).

Both Docker and Podman are slightly more restrictve than runc:

  1. runc allows all this and also '+' (since ~2016, Allow + in container ID opencontainers/runc#675); not sure why.
  2. runc allows _.- as the first character (but disallows names like '.' and '..').

NOTE Docker/Podman container names are not the same as crun/runc container IDs. Both Docker/containerd and Podman (I guess k8s, too) generate a random 64 character hexadecimal ID (like 0dda2d02664f88b49fae96705383da6da90149a49476ff6b0ee74b2ae3936c2f) which is used by crun/runc.

I'm not quite sure but maybe it makes sense to stay compatible with runc here (i.e. be less restrictive than docker/podman). The runc validation logic is here: https://github.com/opencontainers/runc/blob/main/libcontainer/factory_linux.go#L192

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The runc convention makes the validation a bit more difficult as we need to treat the string as a path but doable. In any case it is a best effort measure, I will change the implementation to match runc

conf['annotations'] = {}
conf['annotations']['run.oci.systemd.subgroup'] = 'mysubgroup'

for invalid in ["../../../victim", "../escape", "a/../b"]:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I would add ".." to the list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Container ID of ".." can lead to removal of parent directory

2 participants