Skip to content

Commit

Permalink
validation: add hostname 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 20, 2016
1 parent 037ba51 commit b62e1cc
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func bundleValidate(spec rspec.Spec, rootfs string) {
checkPlatform(spec.Platform)
checkProcess(spec.Process, rootfs)
checkMounts(spec.Mounts, rootfs)
checkLinux(spec.Linux, rootfs)
checkLinux(spec.Linux, spec.Hostname, rootfs)
}

func checkSemVer(version string) {
Expand Down Expand Up @@ -152,7 +152,9 @@ func checkProcess(process rspec.Process, rootfs string) {
}

//Linux only
func checkLinux(spec rspec.Linux, rootfs string) {
func checkLinux(spec rspec.Linux, hostname string, rootfs string) {
utsExist := false

if len(spec.UIDMappings) > 5 {
logrus.Fatalf("Only 5 UID mappings are allowed (linux kernel restriction).")
}
Expand All @@ -163,9 +165,15 @@ func checkLinux(spec rspec.Linux, rootfs string) {
for index := 0; index < len(spec.Namespaces); index++ {
if !namespaceValid(spec.Namespaces[index]) {
logrus.Fatalf("Namespace %s is invalid.", spec.Namespaces[index])
} else if spec.Namespaces[index].Type == rspec.UTSNamespace {
utsExist = true
}
}

if !utsExist && hostname != "" {
logrus.Fatalf("New UTS namespace should to be created.")
}

for index := 0; index < len(spec.Devices); index++ {
if !deviceValid(spec.Devices[index]) {
logrus.Fatalf("Device %s is invalid.", spec.Devices[index].Path)
Expand Down

0 comments on commit b62e1cc

Please sign in to comment.