use secure overlay dir

If there is a user writeable file in the host overlay, a user can
create arbitrary files on the host root file system. Although these
files will belong to this user, this might allow users to modify
any files.
So this patch restricts the access to the host overlay to root and
produces a warning if this was changed.
This commit is contained in:
Christian Goll
2022-04-01 11:47:45 +02:00
committed by Christian Goll
parent 2567246067
commit 95d1b23921
2 changed files with 9 additions and 0 deletions

View File

@@ -92,6 +92,14 @@ func BuildHostOverlay() error {
wwlog.Printf(wwlog.INFO, "Building overlay for %s: host\n", hostname)
idEntry.Set(hostname)
host.Id = idEntry
hostdir := OverlaySourceDir("host")
stats, err := os.Stat(hostdir)
if err != nil {
return errors.Wrap(err, "could not build host overlay ")
}
if !(stats.Mode() == os.FileMode(0750|os.ModeDir) || stats.Mode() == os.FileMode(0700|os.ModeDir)) {
wwlog.Printf(wwlog.WARN, "Permissions of host overlay dir %s are %s (750 is considered as secure)\n", hostdir, stats.Mode())
}
return BuildOverlayIndir(host, []string{"host"}, "/")
}