Skip to content

script checks: use check ID from group service hook#27453

Merged
tgross merged 2 commits intomainfrom
NMD1054-script-check-interpolation
Feb 4, 2026
Merged

script checks: use check ID from group service hook#27453
tgross merged 2 commits intomainfrom
NMD1054-script-check-interpolation

Conversation

@tgross
Copy link
Copy Markdown
Member

@tgross tgross commented Feb 2, 2026

Script checks are registered in Consul at the group service hook, then executed and heartbeat by the Nomad client in the script check hook. But not all fields in the task environment are available for interpolation at the time the group service hook runs, and the hash we use for the check ID includes all fields post-interpolation. The script check hook intends to use the original uninterpolated check ID, but the service it's reading this value from has been interpolated with the full task environment at this point. Using the uninterpolated check from the task group would be incorrect anyways, as the group service check has interpolated before creating the ID used to register the check.

Ideally we'd interpolate values available at submit-time and generate an immutable service ID and check ID based on that. But for backwards compatibility with existing registered services, we'll need to fix this at the script check instead.

Have the group service check record every check ID it creates in the allochook resources. Thread these down to the script check taskrunner hook and use the stored values as an override of the check ID we use for TTL updates.

Fixes: #26952
Ref: https://hashicorp.atlassian.net/browse/NMD-1054

Testing & Reproduction steps

Run Consul and a dev server, and do the usual nomad setup consul -y configuration. Deploy the following jobspec and observe that both script checks and TCP checks work as expected. Note the NOMAD_ALLOC_IP_www value is key here; just using the NOMAD_JOB_NAME doesn't trigger the bug because that's interpolated at the group level.

jobspec
job "example" {

  group "group" {

    network {
      mode = "bridge"
      port "www" {
        to = 8001
      }
    }

    service {
      name = "${NOMAD_JOB_NAME}-svc"
      port = "www"

      check {
        name      = "${NOMAD_JOB_NAME}-tcp-check"
        type     = "tcp"
        port     = "www"
        interval = "10s"
        timeout  = "2s"
      }

      check {
        name      = "${NOMAD_JOB_NAME}-script-check"
        type      = "script"
        command   = "/bin/sh"
        interval  = "5s"
        timeout   = "1s"
        task      = "httpd"
        args = ["-c", "echo ${NOMAD_ALLOC_IP_www}"]
      }
    }


    task "httpd" {
      driver = "docker"

      config {
        image   = "busybox:1"
        command = "httpd"
        args    = ["-vv", "-f", "-p", "8001", "-h", "/local"]
        ports   = ["www"]
      }
    }
  }
}

Contributor Checklist

  • Changelog Entry If this PR changes user-facing behavior, please generate and add a
    changelog entry using the make cl command.
  • Testing Please add tests to cover any new functionality or to demonstrate bug fixes and
    ensure regressions will be caught.
  • Documentation If the change impacts user-facing functionality such as the CLI, API, UI,
    and job configuration, please update the Nomad product documentation, which is stored in the
    web-unified-docs repo. Refer to the web-unified-docs contributor guide for docs guidelines.
    Please also consider whether the change requires notes within the upgrade
    guide
    . If you would like help with the docs, tag the nomad-docs team in this PR.

Reviewer Checklist

  • Backport Labels Please add the correct backport labels as described by the internal
    backporting document.
  • Commit Type Ensure the correct merge method is selected which should be "squash and merge"
    in the majority of situations. The main exceptions are long-lived feature branches or merges where
    history should be preserved.
  • Enterprise PRs If this is an enterprise only PR, please add any required changelog entry
    within the public repository.
  • If a change needs to be reverted, we will roll out an update to the code within 7 days.

Changes to Security Controls

Are there any changes to security controls (access controls, encryption, logging) in this pull request? If so, explain.

@tgross tgross added theme/consul type/bug backport/ent/1.8.x+ent Changes are backported to 1.8.x+ent backport/ent/1.10.x+ent backport to 1.10.x+ent release line backport/1.11.x backport to 1.11.x release line labels Feb 2, 2026
@tgross tgross force-pushed the NMD1054-script-check-interpolation branch from 7dee55e to 5f43ab5 Compare February 2, 2026 21:58
@tgross tgross force-pushed the NMD1054-script-check-interpolation branch from 5f43ab5 to 3bc1744 Compare February 3, 2026 15:48
Script checks are registered in Consul at the group service hook, then executed
and heartbeat by the Nomad client in the script check hook. But not all fields
in the task environment are available for interpolation at the time the group
service hook runs, and the hash we use for the check ID includes all fields
post-interpolation. The script check hook intends to use the original
uninterpolated check ID, but the service it's reading this value from has been
interpolated with the full task environment at this point. Using the
uninterpolated check from the task group would be incorrect anyways, as the
group service check has interpolated before creating the ID used to register the
check.

Ideally we'd interpolate values available at submit-time and generate an
immutable service ID and check ID based on that. But for backwards compatibility
with existing registered services, we'll need to fix this at the script check
instead.

Have the group service check record every check ID it creates in the
allochook resources. Thread these down to the script check taskrunner hook and
use the stored values as an override of the check ID we use for TTL updates.

Fixes: #26952
Ref: https://hashicorp.atlassian.net/browse/NMD-1054
@tgross tgross force-pushed the NMD1054-script-check-interpolation branch from 3bc1744 to a12288b Compare February 3, 2026 16:06
@tgross tgross marked this pull request as ready for review February 3, 2026 16:40
@tgross tgross requested review from a team as code owners February 3, 2026 16:40
jrasell
jrasell previously approved these changes Feb 4, 2026
Copy link
Copy Markdown
Member

@jrasell jrasell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I've left a couple of inline comments, but I don't see those as blocking.

Comment thread client/allocrunner/taskrunner/script_check_hook.go Outdated
Comment thread client/allocrunner/group_service_hook.go Outdated
@tgross tgross merged commit ca7b8fe into main Feb 4, 2026
37 checks passed
@tgross tgross deleted the NMD1054-script-check-interpolation branch February 4, 2026 14:59
tgross added a commit that referenced this pull request Feb 5, 2026
In #27453 we fixed a bug in script check hook interpolation by recording the
check IDs for each check in the group service hook and then passing that to the
script check hook via alloc hook resources. But this change did not account for
checks being updated in-place, so the script check hook reads the old check IDs
and fails. This was caught by nightly E2E testing.

Record the updated check IDs in the group service hook as well. Expand the group
service tests to include updating the checks.

Ref: #27453
Ref: https://hashicorp.atlassian.net/browse/NMD-1054
Ref: https://github.com/hashicorp/nomad-e2e/actions/runs/21699934682/job/62586402991
tgross added a commit that referenced this pull request Feb 6, 2026
In #27453 we fixed a bug in script check hook interpolation by recording the
check IDs for each check in the group service hook and then passing that to the
script check hook via alloc hook resources. But this change did not account for
checks being updated in-place, so the script check hook reads the old check IDs
and fails. This was caught by nightly E2E testing.

Record the updated check IDs in the group service hook as well. Expand the group
service tests to include updating the checks.

Ref: #27453
Ref: https://hashicorp.atlassian.net/browse/NMD-1054
Ref: https://github.com/hashicorp/nomad-e2e/actions/runs/21699934682/job/62586402991
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport/ent/1.8.x+ent Changes are backported to 1.8.x+ent backport/ent/1.10.x+ent backport to 1.10.x+ent release line backport/1.11.x backport to 1.11.x release line theme/consul type/bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Script checks failing due to inconsistent checkID generation

2 participants