Skip to content

Commit 33ce0dc

Browse files
authored
Merge pull request #3971 from kinvolk/rata/abs-dest-path-warn
Revert "libct/validator: Error out on non-abs paths"
2 parents 80320b7 + ec2ffae commit 33ce0dc

File tree

4 files changed

+33
-16
lines changed

4 files changed

+33
-16
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
}

libcontainer/rootfs_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ func mountToRootfs(c *mountConfig, m mountEntry) error {
485485
if m.srcFD == nil {
486486
return fmt.Errorf("error creating mount %+v: idmapFD is invalid, should point to a valid fd", m)
487487
}
488-
if err := unix.MoveMount(*m.srcFD, "", -1, dest, unix.MOVE_MOUNT_F_EMPTY_PATH); err != nil {
488+
if err := unix.MoveMount(*m.srcFD, "", unix.AT_FDCWD, dest, unix.MOVE_MOUNT_F_EMPTY_PATH); err != nil {
489489
return fmt.Errorf("error on unix.MoveMount %+v: %w", m, err)
490490
}
491491

tests/integration/idmap.bats

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ function teardown() {
7272
[[ "$output" == *"shared"* ]]
7373
}
7474

75+
@test "idmap mount with relative path" {
76+
update_config ' .mounts |= map((select(.source == "source-1/") | .destination = "tmp/mount-1") // .)'
77+
78+
runc run test_debian
79+
[ "$status" -eq 0 ]
80+
[[ "$output" == *"=0=0="* ]]
81+
}
82+
7583
@test "idmap mount with bind mount" {
7684
update_config ' .mounts += [
7785
{

0 commit comments

Comments
 (0)