Skip to content

Commit

Permalink
runtimetest: add masked paths 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 74a274e
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 @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
Expand Down Expand Up @@ -191,6 +192,29 @@ func validateSysctls(spec *rspec.Spec) error {
return nil
}

func validateMaskedPaths(spec *rspec.Spec) error {
fmt.Println("validating maskedPaths")
for _, maskedPath := range spec.Linux.MaskedPaths {
fi, err := os.Stat(maskedPath)
if err != nil {
return err
}
if fi.Mode()&0444 != 0 {
f, err := os.Open(maskedPath)
if err != nil {
return err
}
defer f.Close()
b := make([]byte, 1)
_, err = f.Read(b)
if err != io.EOF {
return fmt.Errorf("%v should not be readable", maskedPath)
}
}
}
return nil
}

func main() {
spec, err := loadSpecConfig()
if err != nil {
Expand All @@ -203,6 +227,7 @@ func main() {
validateHostname,
validateRlimits,
validateSysctls,
validateMaskedPaths,
}

for _, v := range validations {
Expand Down

0 comments on commit 74a274e

Please sign in to comment.