From 4016f63ee0233384c2ea4e11cdfb7d962ecb6c7b Mon Sep 17 00:00:00 2001 From: Ramkumar Chinchani <45800463+rchincha@users.noreply.github.com> Date: Wed, 4 Oct 2023 17:31:27 -0700 Subject: [PATCH] feat(check): add a check for symlinks in roots-dir path (#521) stacker tries to avoid symlinks to minimize unexpected behaviors, so add check for that. Signed-off-by: Ramkumar Chinchani --- cmd/stacker/check.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/cmd/stacker/check.go b/cmd/stacker/check.go index 241e9344..5b58a93d 100644 --- a/cmd/stacker/check.go +++ b/cmd/stacker/check.go @@ -4,6 +4,7 @@ import ( "io/fs" "os" "os/exec" + "path/filepath" "github.com/pkg/errors" "github.com/pkg/xattr" @@ -26,12 +27,23 @@ func doCheck(ctx *cli.Context) error { return errors.Wrapf(err, "couldn't get kernel info") } - log.Infof(kernel) + log.Infof("os/kernel: %s", kernel) if err := os.MkdirAll(config.RootFSDir, 0700); err != nil { return errors.Wrapf(err, "couldn't create rootfs dir for testing") } + // internally there are many checks to avoid symlinks + evalp, err := filepath.EvalSymlinks(config.RootFSDir) + if err != nil { + return errors.Wrapf(err, "%s: unable to evaluate path for symlinks", config.RootFSDir) + } + + if evalp != config.RootFSDir { + return errors.Errorf("%s: roots dir (--roots-dir) path uses symbolic links, use %q instead", config.RootFSDir, evalp) + } + + // not all underlying filesystems are compatible fstype, err := stacker.MountInfo(config.RootFSDir) if err != nil { return errors.Wrapf(err, "%s: couldn't get fs type", config.RootFSDir)