Skip to content

Commit

Permalink
feat(check): add a check for symlinks in roots-dir path (#521)
Browse files Browse the repository at this point in the history
stacker tries to avoid symlinks to minimize unexpected behaviors, so add
check for that.

Signed-off-by: Ramkumar Chinchani <rchincha@cisco.com>
  • Loading branch information
rchincha authored Oct 5, 2023
1 parent d9f849b commit 4016f63
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion cmd/stacker/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"io/fs"
"os"
"os/exec"
"path/filepath"

"github.com/pkg/errors"
"github.com/pkg/xattr"
Expand All @@ -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)
Expand Down

0 comments on commit 4016f63

Please sign in to comment.