11package main
22
33import (
4+ "bufio"
45 "encoding/json"
56 "fmt"
67 "io/ioutil"
78 "os"
89 "path"
910 "path/filepath"
1011 "reflect"
12+ "runtime"
1113 "strings"
1214 "unicode"
1315 "unicode/utf8"
@@ -21,6 +23,7 @@ import (
2123var bundleValidateFlags = []cli.Flag {
2224 cli.StringFlag {Name : "path" , Value : "." , Usage : "path to a bundle" },
2325 cli.BoolFlag {Name : "hooks" , Usage : "Check specified hooks exist and are executable on the host." },
26+ cli.BoolFlag {Name : "hook-specific" , Usage : "Check host specified configs." },
2427}
2528
2629var (
@@ -80,17 +83,21 @@ var bundleValidateCommand = cli.Command{
8083 }
8184
8285 hooksCheck := context .Bool ("hooks" )
83- bundleValidate (spec , rootfsPath , hooksCheck )
86+ hostCheck := context .Bool ("host-specific" )
87+ bundleValidate (spec , rootfsPath , hooksCheck , hostCheck )
8488 logrus .Infof ("Bundle validation succeeded." )
8589 return nil
8690 },
8791}
8892
89- func bundleValidate (spec rspec.Spec , rootfs string , hooksCheck bool ) {
93+ func bundleValidate (spec rspec.Spec , rootfs string , hooksCheck bool , hostCheck bool ) {
9094 checkMandatoryField (spec )
9195 checkSemVer (spec .Version )
9296 checkPlatform (spec .Platform )
9397 checkProcess (spec .Process , rootfs )
98+ if hostCheck && spec .Platform .OS == "linux" && runtime .GOOS == "linux" {
99+ checkMounts (spec .Mounts )
100+ }
94101 checkLinux (spec )
95102 checkHooks (spec .Hooks , hooksCheck )
96103}
@@ -192,6 +199,47 @@ func checkProcess(process rspec.Process, rootfs string) {
192199 }
193200}
194201
202+ func supportedMountTypes () (map [string ]bool , error ) {
203+ supportedTypes := make (map [string ]bool )
204+ f , err := os .Open ("/proc/filesystems" )
205+ if err != nil {
206+ return supportedTypes , err
207+ }
208+ defer f .Close ()
209+
210+ s := bufio .NewScanner (f )
211+ for s .Scan () {
212+ if err := s .Err (); err != nil {
213+ return supportedTypes , err
214+ }
215+
216+ text := s .Text ()
217+ parts := strings .Split (text , "\t " )
218+ if len (parts ) > 1 {
219+ supportedTypes [parts [1 ]] = true
220+ } else {
221+ supportedTypes [parts [0 ]] = true
222+ }
223+ }
224+
225+ supportedTypes ["bind" ] = true
226+
227+ return supportedTypes , nil
228+ }
229+
230+ func checkMounts (mounts []rspec.Mount ) {
231+ supportedTypes , err := supportedMountTypes ()
232+ if err != nil {
233+ logrus .Fatal (err )
234+ }
235+
236+ for _ , mount := range mounts {
237+ if ! supportedTypes [mount .Type ] {
238+ logrus .Fatalf ("Unsupported mount type %q" , mount .Type )
239+ }
240+ }
241+ }
242+
195243//Linux only
196244func checkLinux (spec rspec.Spec ) {
197245 utsExists := false
0 commit comments