Skip to content

Commit

Permalink
runtimetest: add root filesystem validation
Browse files Browse the repository at this point in the history
Signed-off-by: Ma Shimiao <mashimiao.fnst@cn.fujitsu.com>
  • Loading branch information
Ma Shimiao committed May 28, 2016
1 parent 366a66e commit d9b2746
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions cmd/runtimetest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,38 @@ func validateSysctls(spec *rspec.Spec) error {
return nil
}

func testWriteAccess(path string) error {
tmpfile, err := ioutil.TempFile(path, "Test")
if err != nil {
return err
}

tmpfile.Close()
os.RemoveAll(filepath.Join(path, tmpfile.Name()))

return nil
}

func validateRootFS(spec *rspec.Spec) error {
fmt.Println("validating root")
if spec.Root.Readonly {
err := testWriteAccess("/")
if err == nil {
return fmt.Errorf("Rootfs should be readonly")
}
}

return nil
}

func main() {
spec, err := loadSpecConfig()
if err != nil {
logrus.Fatalf("Failed to load configuration: %q", err)
}

validations := []validation{
validateRootFS,
validateProcess,
validateCapabilities,
validateHostname,
Expand Down

0 comments on commit d9b2746

Please sign in to comment.