Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jobspec using validation with missing constraint causes panic #12513

Closed
shoenig opened this issue Apr 8, 2022 · 1 comment · Fixed by #16018
Closed

Jobspec using validation with missing constraint causes panic #12513

shoenig opened this issue Apr 8, 2022 · 1 comment · Fixed by #16018
Assignees
Labels
stage/accepted Confirmed, and intend to work on. No timeline committment though. theme/hcl type/bug
Milestone

Comments

@shoenig
Copy link
Member

shoenig commented Apr 8, 2022

While looking over #12508 I had a typo in my own example and triggered a panic of the CLI. A missing condition in the validation block of a variable block gets through jobspec validation itself, and causes a NPE.

variable "image_id" {
  type          = string
  description   = "Check on image names."

  validation {
    # condition  =   substr(var.image_id, 0, 4) == "foo-" 
    error_message = "Must use a foo image."
  }
}

job "example" {
  datacenters = ["dc1"]

  group "cache" {
    network {
      port "db" {
        to = 6379
      }
    }

    task "redis" {
      driver = "docker"
      config {
        image = "${var.image_id}"
        ports = ["db"]
      }
    }
  }
}
➜ nomad job run -var 'image_id=foo-' example.nomad
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x1be87d9]

goroutine 1 [running]:
github.com/hashicorp/nomad/jobspec2.(*Variable).validateValue(0xc000909ea0, {{0x25b2ed8, 0x3}, {{{0x2b067c8, 0xc0004bcd69}}, {0x1fa0820, 0xc000b4d1b0}}, {0x7f03143459f0, 0xc000c304e0}})
	github.com/hashicorp/nomad/jobspec2/types.variables.go:99 +0x359
github.com/hashicorp/nomad/jobspec2.(*Variable).Value(0x120)
	github.com/hashicorp/nomad/jobspec2/types.variables.go:159 +0x145
github.com/hashicorp/nomad/jobspec2.Variables.Values(0xc0003a1730)
	github.com/hashicorp/nomad/jobspec2/types.variables.go:176 +0xd9
github.com/hashicorp/nomad/jobspec2.(*jobConfig).decodeBody(0xc0003a1730, {0x2b054c0, 0xc0002d3550})
	github.com/hashicorp/nomad/jobspec2/types.config.go:68 +0x2da
github.com/hashicorp/nomad/jobspec2.decode(0xc0003a1730)
	github.com/hashicorp/nomad/jobspec2/parse.go:105 +0xc9
github.com/hashicorp/nomad/jobspec2.ParseWithConfig(0xc0002d2f20)
	github.com/hashicorp/nomad/jobspec2/parse.go:44 +0xe5
github.com/hashicorp/nomad/command.(*JobGetter).ApiJobWithArgs(0xc000b930f0, {0x7ffcdd7e7319, 0xd}, {0xc000b4cce0, 0x1, 0x1}, {0x0, 0x0, 0x0}, 0x1)
	github.com/hashicorp/nomad/command/helpers.go:455 +0x76d
github.com/hashicorp/nomad/command.(*JobRunCommand).Run(0xc000b93040, {0xc00004e210, 0x3, 0x3})
	github.com/hashicorp/nomad/command/job_run.go:218 +0x68e
github.com/mitchellh/cli.(*CLI).Run(0xc000496640)
	github.com/mitchellh/cli@v1.1.2/cli.go:262 +0x5f8
main.RunCustom({0xc00004e1f0, 0x1f76220, 0xc0000001a0})
	github.com/hashicorp/nomad/main.go:115 +0x33d
main.Run(...)
	github.com/hashicorp/nomad/main.go:85
main.main()
	github.com/hashicorp/nomad/main.go:81 +0x50
@shoenig shoenig added type/bug theme/hcl stage/accepted Confirmed, and intend to work on. No timeline committment though. labels Apr 8, 2022
@tgross tgross added this to the 1.5.0 milestone Feb 1, 2023
@tgross tgross self-assigned this Feb 1, 2023
@tgross
Copy link
Member

tgross commented Feb 1, 2023

Fixed in #16018 which will ship in Nomad 1.5.0 (with backports)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stage/accepted Confirmed, and intend to work on. No timeline committment though. theme/hcl type/bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants