Skip to content

Commit 1a3f3c6

Browse files
author
Mrunal Patel
authored
Merge pull request #199 from Mashimiao/add-namespace-check-for-mappings
add namespace check for uid/gid mappings
2 parents ebda26c + bf50b73 commit 1a3f3c6

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

cmd/ocitools/validate.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -316,13 +316,7 @@ func checkLinux(spec rspec.Spec, rootfs string, hostCheck bool) (msgs []string)
316316
ipcExists := false
317317
mountExists := false
318318
netExists := false
319-
320-
if len(spec.Linux.UIDMappings) > 5 {
321-
msgs = append(msgs, "Only 5 UID mappings are allowed (linux kernel restriction).")
322-
}
323-
if len(spec.Linux.GIDMappings) > 5 {
324-
msgs = append(msgs, "Only 5 GID mappings are allowed (linux kernel restriction).")
325-
}
319+
userExists := false
326320

327321
for index := 0; index < len(spec.Linux.Namespaces); index++ {
328322
if !namespaceValid(spec.Linux.Namespaces[index]) {
@@ -336,10 +330,20 @@ func checkLinux(spec rspec.Spec, rootfs string, hostCheck bool) (msgs []string)
336330
netExists = true
337331
} else if spec.Linux.Namespaces[index].Type == rspec.MountNamespace {
338332
mountExists = true
333+
} else if spec.Linux.Namespaces[index].Type == rspec.UserNamespace {
334+
userExists = true
339335
}
340336
}
341337
}
342338

339+
if (len(spec.Linux.UIDMappings) > 0 || len(spec.Linux.GIDMappings) > 0) && !userExists {
340+
msgs = append(msgs, "UID/GID mappings requires a new User namespace to be specified as well")
341+
} else if len(spec.Linux.UIDMappings) > 5 {
342+
msgs = append(msgs, "Only 5 UID mappings are allowed (linux kernel restriction).")
343+
} else if len(spec.Linux.GIDMappings) > 5 {
344+
msgs = append(msgs, "Only 5 GID mappings are allowed (linux kernel restriction).")
345+
}
346+
343347
for k := range spec.Linux.Sysctl {
344348
if strings.HasPrefix(k, "net.") && !netExists {
345349
msgs = append(msgs, fmt.Sprintf("Sysctl %v requires a new Network namespace to be specified as well", k))

0 commit comments

Comments
 (0)