Skip to content

Commit 19d26a6

Browse files
committed
Revert "libct/validator: Error out on non-abs paths"
This reverts commit 881e92a and adjust the code so the idmap validations are strict. We now only throw a warning and the container is started just fine. Signed-off-by: Rodrigo Campos <[email protected]>
1 parent 74c125d commit 19d26a6

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

libcontainer/configs/validate/validator.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ 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"
1516
"golang.org/x/sys/unix"
1617
)
1718

@@ -28,13 +29,22 @@ func Validate(config *configs.Config) error {
2829
sysctl,
2930
intelrdtCheck,
3031
rootlessEUIDCheck,
31-
mounts,
32+
mountsStrict,
3233
}
3334
for _, c := range checks {
3435
if err := c(config); err != nil {
3536
return err
3637
}
3738
}
39+
// Relaxed validation rules for backward compatibility
40+
warns := []check{
41+
mounts, // TODO (runc v1.x.x): make this an error instead of a warning
42+
}
43+
for _, c := range warns {
44+
if err := c(config); err != nil {
45+
logrus.WithError(err).Warn("invalid configuration")
46+
}
47+
}
3848
return nil
3949
}
4050

@@ -282,19 +292,19 @@ func checkIDMapMounts(config *configs.Config, m *configs.Mount) error {
282292

283293
func mounts(config *configs.Config) error {
284294
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.
290295
if !filepath.IsAbs(m.Destination) {
291296
return fmt.Errorf("invalid mount %+v: mount destination not absolute", m)
292297
}
298+
}
299+
return nil
300+
}
301+
302+
func mountsStrict(config *configs.Config) error {
303+
for _, m := range config.Mounts {
293304
if err := checkIDMapMounts(config, m); err != nil {
294305
return fmt.Errorf("invalid mount %+v: %w", m, err)
295306
}
296307
}
297-
298308
return nil
299309
}
300310

libcontainer/configs/validate/validator_test.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -360,10 +360,11 @@ func TestValidateMounts(t *testing.T) {
360360
isErr bool
361361
dest string
362362
}{
363-
{isErr: true, dest: "not/an/abs/path"},
364-
{isErr: true, dest: "./rel/path"},
365-
{isErr: true, dest: "./rel/path"},
366-
{isErr: true, dest: "../../path"},
363+
// TODO (runc v1.x.x): make these relative paths an error. See https://github.com/opencontainers/runc/pull/3004
364+
{isErr: false, dest: "not/an/abs/path"},
365+
{isErr: false, dest: "./rel/path"},
366+
{isErr: false, dest: "./rel/path"},
367+
{isErr: false, dest: "../../path"},
367368

368369
{isErr: false, dest: "/abs/path"},
369370
{isErr: false, dest: "/abs/but/../unclean"},
@@ -514,8 +515,7 @@ func TestValidateIDMapMounts(t *testing.T) {
514515
},
515516
},
516517
{
517-
name: "idmap mounts without abs dest path",
518-
isErr: true,
518+
name: "idmap mounts without abs dest path",
519519
config: &configs.Config{
520520
UIDMappings: mapping,
521521
GIDMappings: mapping,
@@ -530,7 +530,6 @@ func TestValidateIDMapMounts(t *testing.T) {
530530
},
531531
},
532532
},
533-
534533
{
535534
name: "simple idmap mount",
536535
config: &configs.Config{
@@ -571,7 +570,7 @@ func TestValidateIDMapMounts(t *testing.T) {
571570
config := tc.config
572571
config.Rootfs = "/var"
573572

574-
err := mounts(config)
573+
err := mountsStrict(config)
575574
if tc.isErr && err == nil {
576575
t.Error("expected error, got nil")
577576
}

0 commit comments

Comments
 (0)