Poststop task workload identities are rejected when the allocation is terminal
Nomad version
Nomad v2.0.7 BuildDate 2026-09-17T17:24:03Z Revision 9dcbdc5e64ecc4ec63e42b225af729c87c87cf83
Operating system and Environment details
- Linux 7.1.13-2-MANJARO
- local nomad dev server with ACLs enabled (
nomad agent -dev -acl-enabled) - Task API accessed through
${NOMAD_SECRETS_DIR}/api.sock
Issue
poststop tasks cannot use their own Nomad workload identity to access the nomad API after the main task has failed.
The poststop task has a separate workload identity, bound to its own nomad_task claim, but authentication seems to be rejected based on allocation status, not task status.
It appears this is related to these lines of code. They only check if the allocation as a whole is terminal, and not if the task the workload identity belongs to is still running.
Additionally, an allocation is marked as "failed" as soon as one of its tasks
Reproduction steps
- Have the main task exit with an exit code != 0
- Try to access the nomad API (via /secrets/api.sock) using the workload identity
${NOMAD_TOKEN}
Expected Result
Both the main and poststop task can authenticate with the Nomad API.
Actual Result
The poststop task is denied API access.
Job file
job "reproduction" {
type = "batch"
group "reproduction" {
reschedule {
attempts = 0
unlimited = false
}
task "main" {
driver = "docker"
config {
image = "curlimages/curl"
command = "sh"
args = [
"-c",
"curl -s --unix-socket \"${NOMAD_SECRETS_DIR}/api.sock\" -H \"Authorization: Bearer ${NOMAD_TOKEN}\" --fail-with-body \"localhost/v1/services\" 2>&1; exit 1"
]
}
restart {
attempts = 0
}
identity {
env = true
}
}
task "poststop" {
driver = "docker"
config {
image = "curlimages/curl"
command = "sh"
args = [
"-c",
"curl -s --unix-socket \"${NOMAD_SECRETS_DIR}/api.sock\" -H \"Authorization: Bearer ${NOMAD_TOKEN}\" --fail-with-body \"localhost/v1/services\" 2>&1"
]
}
lifecycle {
hook = "poststop"
}
restart {
attempts = 0
}
identity {
env = true
}
}
}
}The main task logs only [] (because I have no services defined), while the poststop task logs Server error authenticating request. I've tested this with other endpoints as well. All had the same issue.
Nomad Server logs
For the main task's API call:
[DEBUG] http: request complete: method=GET path=/v1/services duration="233.553µs"For the poststop API call:
[ERROR] http: error authenticating built API request: error="allocation is terminal" url=/v1/services method=GETSource: hashicorp/nomad