-
Notifications
You must be signed in to change notification settings - Fork 403
status: restrict valid container ID names #2077
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
giuseppe
wants to merge
2
commits into
containers:main
Choose a base branch
from
giuseppe:validate-container-name
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+109
−4
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1298,6 +1298,39 @@ def test_annotation_delegate_cgroup(): | |
| run_crun_command(["delete", "-f", cid]) | ||
|
|
||
|
|
||
| def test_annotation_delegate_cgroup_dotdot(): | ||
| """Test that run.oci.delegate-cgroup rejects '..' components.""" | ||
| if not is_cgroup_v2_unified(): | ||
| return (77, "requires cgroup v2") | ||
| if not running_on_systemd(): | ||
| return (77, "requires systemd") | ||
| if get_cgroup_manager() != 'systemd': | ||
| return (77, "requires systemd cgroup manager") | ||
|
|
||
| conf = base_config() | ||
| add_all_namespaces(conf, cgroupns=True) | ||
| conf['process']['args'] = ['/init', 'echo', 'hello'] | ||
|
|
||
| if 'annotations' not in conf: | ||
| conf['annotations'] = {} | ||
| conf['annotations']['run.oci.systemd.subgroup'] = 'mysubgroup' | ||
|
|
||
| for invalid in ["../../../victim", "../escape", "a/../b"]: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: I would add ".." to the list. |
||
| conf['annotations']['run.oci.delegate-cgroup'] = invalid | ||
| try: | ||
| out, _ = run_and_get_output(conf, hide_stderr=True) | ||
| return -1 | ||
| except Exception as e: | ||
| if hasattr(e, 'output') and e.output: | ||
| err = e.output.decode() | ||
| if "delegate-cgroup" in err: | ||
| continue | ||
| logger.info("got error for delegate-cgroup '%s': %s", invalid, err) | ||
| else: | ||
| logger.info("got exception without output for delegate-cgroup '%s': %s", invalid, str(e)) | ||
| return -1 | ||
| return 0 | ||
|
|
||
| def test_annotation_systemd_force_cgroup_v1(): | ||
| """Test run.oci.systemd.force_cgroup_v1 annotation.""" | ||
| if not is_cgroup_v2_unified(): | ||
|
|
@@ -1544,6 +1577,7 @@ def test_cgroup_subcgroup_cleanup(): | |
| "cgroup-create-without-resources": test_cgroup_create_without_resources, | ||
| "annotation-systemd-subgroup": test_annotation_systemd_subgroup, | ||
| "annotation-delegate-cgroup": test_annotation_delegate_cgroup, | ||
| "annotation-delegate-cgroup-dotdot": test_annotation_delegate_cgroup_dotdot, | ||
| "annotation-systemd-force-cgroup-v1": test_annotation_systemd_force_cgroup_v1, | ||
| "cgroup-v2-mount-options": test_cgroup_v2_mount_options, | ||
| "cgroup-subcgroup-cleanup": test_cgroup_subcgroup_cleanup, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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:
'+'(since ~2016, Allow + in container ID opencontainers/runc#675); not sure why._.-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
There was a problem hiding this comment.
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