-
Notifications
You must be signed in to change notification settings - Fork 2.2k
specconv: temporarily allow userns path and mapping if they match #4134
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -522,9 +522,9 @@ func toConfigIDMap(specMaps []specs.LinuxIDMapping) []configs.IDMap { | |
| idmaps := make([]configs.IDMap, len(specMaps)) | ||
| for i, id := range specMaps { | ||
| idmaps[i] = configs.IDMap{ | ||
| ContainerID: int(id.ContainerID), | ||
| HostID: int(id.HostID), | ||
| Size: int(id.Size), | ||
| ContainerID: int64(id.ContainerID), | ||
| HostID: int64(id.HostID), | ||
| Size: int64(id.Size), | ||
| } | ||
| } | ||
| return idmaps | ||
|
|
@@ -973,18 +973,32 @@ func setupUserNamespace(spec *specs.Spec, config *configs.Config) error { | |
| config.GIDMappings = toConfigIDMap(spec.Linux.GIDMappings) | ||
| } | ||
| if path := config.Namespaces.PathOf(configs.NEWUSER); path != "" { | ||
| // We cannot allow uid or gid mappings to be set if we are also asked | ||
| // to join a userns. | ||
| if config.UIDMappings != nil || config.GIDMappings != nil { | ||
| return errors.New("user namespaces enabled, but both namespace path and mapping specified -- you may only provide one") | ||
| } | ||
| // Cache the current userns mappings in our configuration, so that we | ||
| // can calculate uid and gid mappings within runc. These mappings are | ||
| // never used for configuring the container if the path is set. | ||
| uidMap, gidMap, err := userns.GetUserNamespaceMappings(path) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to cache mappings for userns: %w", err) | ||
| } | ||
| // We cannot allow uid or gid mappings to be set if we are also asked | ||
| // to join a userns. | ||
| if config.UIDMappings != nil || config.GIDMappings != nil { | ||
| // FIXME: It turns out that containerd and CRIO pass both a userns | ||
| // path and the mappings of the namespace in the same config.json. | ||
| // Such a configuration is technically not valid, but we used to | ||
| // require mappings be specified, and thus users worked around our | ||
| // bug -- so we can't regress it at the moment. But we also don't | ||
| // 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. | ||
|
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. Could you add links to the containerd issue and the crio issue tickets? 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. 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. |
||
| if !userns.IsSameMapping(uidMap, config.UIDMappings) || | ||
| !userns.IsSameMapping(gidMap, config.GIDMappings) { | ||
| return errors.New("user namespaces enabled, but both namespace path and non-matching mapping specified -- you may only provide one") | ||
| } | ||
| logrus.Warnf("config.json has both a userns path to join and a matching userns mapping specified -- you may only provide one. Future versions of runc may return an error with this configuration, please report a bug on <https://github.com/opencontainers/runc> if you see this warning and cannot update your configuration.") | ||
| } | ||
|
|
||
| config.UIDMappings = uidMap | ||
| config.GIDMappings = gidMap | ||
| logrus.WithFields(logrus.Fields{ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -169,3 +169,18 @@ func GetUserNamespaceMappings(nsPath string) (uidMap, gidMap []configs.IDMap, er | |
|
|
||
| return uidMap, gidMap, nil | ||
| } | ||
|
|
||
| // 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 { | ||
|
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. Can we just use 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. Reflection is slower and importing Once we switch to Go 1.21, we can use |
||
| if len(a) != len(b) { | ||
| return false | ||
| } | ||
| for idx := range a { | ||
| if a[idx] != b[idx] { | ||
| return false | ||
| } | ||
| } | ||
| return true | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.