Skip to content
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

specconv: temporarily allow userns path and mapping if they match #4134

Merged
merged 2 commits into from Dec 14, 2023
Merged

specconv: temporarily allow userns path and mapping if they match #4134

merged 2 commits into from Dec 14, 2023

Conversation

cyphar
Copy link
Member

@cyphar cyphar commented Dec 6, 2023

It turns out that the error added in commit 09822c3 ("configs: disallow ambiguous userns and timens configurations") causes issues with containerd and CRIO because they pass both userns mappings and a userns path.

These configurations are broken, but to avoid the regression in this one case, output a warning to tell the user that the configuration is incorrect but we will continue to use it if and only if the configured mappings are identical to the mappings of the provided namespace.

/cc @rata

Fixes: 09822c3 ("configs: disallow ambiguous userns and timens configurations")
Fixes #4133
Signed-off-by: Aleksa Sarai cyphar@cyphar.com

Copy link
Contributor

@rata rata left a comment

Choose a reason for hiding this comment

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

@cyphar thanks, this LGTM! It works with both containerd and crio when using k8s pods.

I've tested applying this patch on top of #3985.

It seems unit tests need to be updated, though.

libcontainer/specconv/spec_linux.go Outdated Show resolved Hide resolved
Copy link
Contributor

@rata rata left a comment

Choose a reason for hiding this comment

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

LGTM

It turns out that the error added in commit 09822c3 ("configs:
disallow ambiguous userns and timens configurations") causes issues with
containerd and CRIO because they pass both userns mappings and a userns
path.

These configurations are broken, but to avoid the regression in this one
case, output a warning to tell the user that the configuration is
incorrect but we will continue to use it if and only if the configured
mappings are identical to the mappings of the provided namespace.

Fixes: 09822c3 ("configs: disallow ambiguous userns and timens configurations")
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
Copy link
Contributor

@rata rata left a comment

Choose a reason for hiding this comment

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

LGTM (my previous review was before the second commit was added).

Copy link
Member

@lifubang lifubang left a comment

Choose a reason for hiding this comment

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

LGTM, @AkihiroSuda PTAL

@lifubang lifubang added the backport/todo/1.1 A PR in main branch which needs to be backported to release-1.1 label Dec 13, 2023
// want to produce broken behaviour if the mapping doesn't match
// the userns. So (for now) we output a warning if the actual
// userns mappings match the configuration, otherwise we return an
// error.
Copy link
Member

Choose a reason for hiding this comment

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

Could you add links to the containerd issue and the crio issue tickets?

Copy link
Member Author

@cyphar cyphar Dec 14, 2023

Choose a reason for hiding this comment

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

AFAIK there are no bug reports for crio and containerd. @rata was right that they were forced to do this, and I suspect that it will be somewhat difficult for them to change this because they might want to work with older runc versions.

// IsSameMapping returns whether or not the two id mappings are the same. Note
// that if the order of the mappings is different, or a mapping has been split,
// the mappings will be considered different.
func IsSameMapping(a, b []configs.IDMap) bool {
Copy link
Member

Choose a reason for hiding this comment

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

Can we just use reflect.DeepEqual ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Reflection is slower and importing reflect IIRC means the compiler can't do certain optimisations. We do use reflect elsewhere in runc, but it seems best to not add more uses that aren't actually necessary.

Once we switch to Go 1.21, we can use slices.Equal. I would prefer that over either option.

Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

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

LGTM, but a couple of nits

Using ints for all of our mapping structures means that a 32-bit binary
errors out when trying to parse /proc/self/*id_map:

  failed to cache mappings for userns: failed to parse uid_map of userns /proc/1/ns/user:
  parsing id map failed: invalid format in line "         0          0 4294967295": integer overflow on token 4294967295

This issue was unearthed by commit 1912d59 ("*: actually support
joining a userns with a new container") but the underlying issue has
been present since the docker/libcontainer days.

In theory, switching to uint32 (to match the spec) instead of int64
would also work, but keeping everything signed seems much less
error-prone. It's also important to note that a mapping might be too
large for an int on 32-bit, so we detect this during the mapping.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
@lifubang lifubang merged commit a31262c into opencontainers:main Dec 14, 2023
45 checks passed
@cyphar cyphar deleted the ns-path-regression branch December 14, 2023 05:20
@kolyshkin kolyshkin added backport/done/1.1 A PR in main branch which was backported to release-1.1 and removed backport/todo/1.1 A PR in main branch which needs to be backported to release-1.1 labels Dec 14, 2023
@kolyshkin
Copy link
Contributor

1.1 backport: #4144

@lifubang lifubang mentioned this pull request Jan 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/done/1.1 A PR in main branch which was backported to release-1.1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

containerd/crio passes invalid config.json
5 participants