From 124c7ffa41b4e34967be23d4380503fa01e28fb6 Mon Sep 17 00:00:00 2001 From: Ma Shimiao Date: Thu, 19 May 2016 15:52:54 +0800 Subject: [PATCH] validation: add hostname validation Signed-off-by: Ma Shimiao --- validate.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/validate.go b/validate.go index 4d5b5972f..429b09b40 100644 --- a/validate.go +++ b/validate.go @@ -86,7 +86,7 @@ func bundleValidate(spec rspec.Spec, rootfs string) { checkSemVer(spec.Version) checkPlatform(spec.Platform) checkProcess(spec.Process, rootfs) - checkLinux(spec.Linux, rootfs) + checkLinux(spec.Linux, spec.Hostname, rootfs) } func checkSemVer(version string) { @@ -154,7 +154,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) { + utsExists := false + if len(spec.UIDMappings) > 5 { logrus.Fatalf("Only 5 UID mappings are allowed (linux kernel restriction).") } @@ -165,9 +167,15 @@ func checkLinux(spec rspec.Linux, rootfs string) { for index := 0; index < len(spec.Namespaces); index++ { if !namespaceValid(spec.Namespaces[index]) { logrus.Fatalf("namespace %v is invalid.", spec.Namespaces[index]) + } else if spec.Namespaces[index].Type == rspec.UTSNamespace { + utsExists = true } } + if !utsExists && hostname != "" { + logrus.Fatalf("Hostname requires a new UTS namespace to be specified as well") + } + for index := 0; index < len(spec.Devices); index++ { if !deviceValid(spec.Devices[index]) { logrus.Fatalf("device %v is invalid.", spec.Devices[index])