@@ -12,7 +12,6 @@ import (
1212 "github.com/opencontainers/runc/libcontainer/configs"
1313 "github.com/opencontainers/runc/libcontainer/intelrdt"
1414 selinux "github.com/opencontainers/selinux/go-selinux"
15- "github.com/sirupsen/logrus"
1615 "golang.org/x/sys/unix"
1716)
1817
@@ -29,21 +28,13 @@ func Validate(config *configs.Config) error {
2928 sysctl ,
3029 intelrdtCheck ,
3130 rootlessEUIDCheck ,
31+ mounts ,
3232 }
3333 for _ , c := range checks {
3434 if err := c (config ); err != nil {
3535 return err
3636 }
3737 }
38- // Relaxed validation rules for backward compatibility
39- warns := []check {
40- mounts , // TODO (runc v1.x.x): make this an error instead of a warning
41- }
42- for _ , c := range warns {
43- if err := c (config ); err != nil {
44- logrus .WithError (err ).Warn ("invalid configuration" )
45- }
46- }
4738 return nil
4839}
4940
@@ -262,16 +253,72 @@ func cgroupsCheck(config *configs.Config) error {
262253 return nil
263254}
264255
256+ func checkIDMapMounts (config * configs.Config , m * configs.Mount ) error {
257+ if ! m .IsIDMapped () {
258+ return nil
259+ }
260+
261+ if ! m .IsBind () {
262+ return fmt .Errorf ("gidMappings/uidMappings is supported only for mounts with the option 'bind'" )
263+ }
264+ if config .RootlessEUID {
265+ return fmt .Errorf ("gidMappings/uidMappings is not supported when runc is being launched with EUID != 0, needs CAP_SYS_ADMIN on the runc parent's user namespace" )
266+ }
267+ if len (config .UidMappings ) == 0 || len (config .GidMappings ) == 0 {
268+ return fmt .Errorf ("not yet supported to use gidMappings/uidMappings in a mount without also using a user namespace" )
269+ }
270+ if ! sameMapping (config .UidMappings , m .UIDMappings ) {
271+ return fmt .Errorf ("not yet supported for the mount uidMappings to be different than user namespace uidMapping" )
272+ }
273+ if ! sameMapping (config .GidMappings , m .GIDMappings ) {
274+ return fmt .Errorf ("not yet supported for the mount gidMappings to be different than user namespace gidMapping" )
275+ }
276+ if ! filepath .IsAbs (m .Source ) {
277+ return fmt .Errorf ("mount source not absolute" )
278+ }
279+
280+ return nil
281+ }
282+
265283func mounts (config * configs.Config ) error {
266284 for _ , m := range config .Mounts {
285+ // We upgraded this to an error in runc 1.2. We might need to
286+ // revert this change if some users haven't still moved to use
287+ // abs paths, in that please move this check inside
288+ // checkIDMapMounts() as we do want to ensure that for idmap
289+ // mounts anyways.
267290 if ! filepath .IsAbs (m .Destination ) {
268291 return fmt .Errorf ("invalid mount %+v: mount destination not absolute" , m )
269292 }
293+ if err := checkIDMapMounts (config , m ); err != nil {
294+ return fmt .Errorf ("invalid mount %+v: %w" , m , err )
295+ }
270296 }
271297
272298 return nil
273299}
274300
301+ // sameMapping checks if the mappings are the same. If the mappings are the same
302+ // but in different order, it returns false.
303+ func sameMapping (a , b []configs.IDMap ) bool {
304+ if len (a ) != len (b ) {
305+ return false
306+ }
307+
308+ for i := range a {
309+ if a [i ].ContainerID != b [i ].ContainerID {
310+ return false
311+ }
312+ if a [i ].HostID != b [i ].HostID {
313+ return false
314+ }
315+ if a [i ].Size != b [i ].Size {
316+ return false
317+ }
318+ }
319+ return true
320+ }
321+
275322func isHostNetNS (path string ) (bool , error ) {
276323 const currentProcessNetns = "/proc/self/ns/net"
277324
0 commit comments