Skip to content

Commit

Permalink
Merge pull request #72 from Mashimiao/add-hostname-bundle-validation
Browse files Browse the repository at this point in the history
validation: add hostname validation
  • Loading branch information
Mrunal Patel committed May 24, 2016
2 parents 4675b7d + 124c7ff commit dcd628f
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 @@ -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) {
Expand Down Expand Up @@ -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).")
}
Expand All @@ -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])
Expand Down

0 comments on commit dcd628f

Please sign in to comment.