Blog

Workload identity in Nomad without Vault: a practical setup

Nov 25, 2026 By Nomatron

A tested, practical setup for Nomad workload identity without Vault: the identity block, NOMAD_TOKEN, the Task API socket, Nomad Variables and job-attached ACL policies.

Title: Workload Identity, beside a stack of five blocks, from the bottom: Task, identity { env = true }, NOMAD_TOKEN, Task API socket and Nomad API.

Workload identity is one of the best things to happen to Nomad security; however, most of the examples you’ll find start with Vault or Consul. What if you don’t run either? What if all you want is for a task to read its own configuration, or call the Nomad API, without anyone pasting an ACL token into a jobspec?

Good news: you don’t need Vault for any of that. Nomad gives every task an identity out of the box, and with a few lines of jobspec, that identity becomes a credential the task can use against Nomad itself.

In this post, you’ll expose a task’s workload identity, call the Nomad API through the Task API socket, read Nomad Variables with the access every task gets for free, and grant more access with a policy attached to a job. We’ll finish with a complete jobspec you can run, and an honest look at where the Nomad Autoscaler stands.

What is workload identity?

Every task that Nomad runs gets a workload identity: a JSON Web Token (JWT), signed by the Nomad servers, that says who the task is. That part needs no setup, and nothing in this post needs more. The server option oidc_issuer only matters when something outside Nomad, such as a cloud provider, has to verify the token: setting it adds an iss (issuer) claim to the token and turns on the OIDC discovery endpoint, /.well-known/openid-configuration, which tells verifiers where to find the public signing keys (/.well-known/jwks.json). Choose the value carefully, because changing it later invalidates existing identities. The token’s claims name the namespace, job, allocation and task:

json
{
  "aud": "nomadproject.io",
  "nomad_namespace": "default",
  "nomad_job_id": "wi-demo",
  "nomad_allocation_id": "<ALLOCATION_ID>",
  "nomad_task": "reader"
}

Think of it as a badge printed for each task at the door. Nomad checks the badge, not a shared password, so there’s nothing for you to create, store or rotate by hand.

Nomad always creates this default identity, and uses it internally. What it doesn’t do is hand it to your task. You opt in, per task, with an identity block.

How it works

Here’s the whole flow, end to end:

  1. You add an identity block to a task, asking for the token as an environment variable, a file, or both.
  2. When the allocation starts, Nomad puts the JWT in NOMAD_TOKEN and/or ${NOMAD_SECRETS_DIR}/nomad_token.
  3. The task calls the local Nomad agent through the Task API, a Unix socket at ${NOMAD_SECRETS_DIR}/api.sock, and presents the token.
  4. Nomad works out what the identity may do. Every workload identity gets an implicit policy: read and list access to Nomad Variables under its own nomad/jobs/<job> paths, plus read access to Nomad service registrations.
  5. If you’ve attached extra ACL policies to the job, group or task with nomad acl policy apply -job, Nomad adds those too.

Nothing in that flow involves Vault, Consul, or an ACL token you have to create, store or rotate.

Before you start

You’ll need:

  • A Nomad cluster with ACLs enabled. For trying things out, nomad agent -dev -acl-enabled on a Linux machine is enough. Run nomad acl bootstrap once, and keep the management token in a file or your secret store.
  • A management token in NOMAD_TOKEN for the setup commands, since nomad acl policy apply requires one.
  • curl on the client, for the Task API example.
  • The right Nomad version for the features you use:
FeatureMinimum Nomad version
Workload identity, Nomad Variables and the implicit nomad/jobs access1.4.0
Policies attached with -job, -group and -task1.4.0
The identity block (env, file) and the Task API socket1.5.0
Multiple named identities, ttl, change_mode1.7.0
filepath on the identity block1.9.0

Note: early 1.4 and 1.5 releases had security fixes for workload-associated policies (1.4.6 and 1.5.1). Run a current, supported release.

Every example in this post was tested on Nomad 2.1.1, with the exec driver.

Exposing the identity to a task

The first step is to ask for the default identity in the task. This block goes inside the task:

hcl
identity {
  env  = true # put the JWT in NOMAD_TOKEN
  file = true # write the JWT to ${NOMAD_SECRETS_DIR}/nomad_token
}

This block doesn’t create a new identity. Because it has no name, it exposes the default one that Nomad already made for the task.

Key points to note:

  • env = true sets NOMAD_TOKEN in the task’s environment. Most Nomad tooling reads NOMAD_TOKEN automatically, which makes this the easiest option.
  • file = true writes the token to secrets/nomad_token in the task directory. Prefer the file for anything that might log or dump its environment.
  • filepath (Nomad 1.9 and later) puts the file somewhere else, relative to the task’s working directory.
  • The default identity has no TTL, and you can’t set one on it. In our test on Nomad 2.1.1, the token had no expiry claim.
  • If you set task.user, the token file is readable only by that user. Otherwise it’s readable by anyone in the task, protected by the permissions on the secrets directory.

Checkpoint: inside the task, NOMAD_TOKEN is set, ${NOMAD_SECRETS_DIR}/nomad_token exists, and the two hold the same JWT.

Calling the Nomad API through the Task API

Your task now has a credential. Next, it needs somewhere to send it.

Every task gets a Unix socket at ${NOMAD_SECRETS_DIR}/api.sock that leads to the local Nomad agent’s HTTP API. It works whatever the task’s network setup is, and it doesn’t need mTLS, because the traffic never leaves the node. It does always require authentication, even if ACLs are disabled, and the anonymous policy never applies through it.

Here’s a call that reads one of the job’s own variables. It sends the token as a header on standard input, so the token isn’t passed as a command-line argument:

bash
printf 'Authorization: Bearer %s\n' "$(cat "$NOMAD_SECRETS_DIR/nomad_token")" |
  curl -sS --unix-socket "$NOMAD_SECRETS_DIR/api.sock" -H @- \
    "http://localhost/v1/var/nomad/jobs/wi-demo"

The -H @- tells curl to read headers from stdin. The hostname in the URL doesn’t matter, since the socket decides where the request goes; localhost is the usual convention.

Note: you’ll see examples that pass Authorization: Bearer ${NOMAD_TOKEN} as a command-line argument. That works, but command-line arguments are visible to anything that can list processes on the node. Reading the header from stdin or a file keeps the token out of the command line.

If your task image includes the nomad binary, you may not need curl. In our test on Nomad 2.1.1, pointing NOMAD_ADDR at the socket worked, and the CLI picked up NOMAD_TOKEN from the environment:

bash
export NOMAD_ADDR="unix://${NOMAD_SECRETS_DIR}/api.sock"
nomad var get -item greeting nomad/jobs/wi-demo

Checkpoint: a request for the job’s own variable returns HTTP 200. A request for something you haven’t granted, such as /v1/jobs, returns 403.

Reading Nomad Variables without a policy

The implicit policy means a task can read its own variables with no extra setup. For a task named reader, in a group named app, in a job named wi-demo, Nomad grants read and list access to:

  • nomad/jobs
  • nomad/jobs/wi-demo
  • nomad/jobs/wi-demo/app
  • nomad/jobs/wi-demo/app/reader

That’s in the job’s own namespace only.

So the easiest way to give a job its configuration is to store it at one of those paths. Write it as an operator, with the values on stdin rather than on the command line:

bash
printf '{"Items":{"greeting":"hello"}}' |
  nomad var put -in=json nomad/jobs/wi-demo -

For a real secret, read the JSON from a file or your secret manager instead of typing the value.

The task can then render it with a template block, with no token handling of its own:

hcl
template {
  data        = <<-EOT
    {{ with nomadVar "nomad/jobs/wi-demo" }}GREETING={{ .greeting }}{{ end }}
  EOT
  destination = "${NOMAD_SECRETS_DIR}/app.env"
  env         = true
}

This renders the variable into a file in the secrets directory and loads it as environment variables. Templates use the task’s workload identity behind the scenes, so this works even without an identity block. You only need the identity block when your own code talks to Nomad.

Note: Nomad Variables are designed for small pieces of configuration, and Nomad stores their root encryption key on the servers. They’re a good fit for app settings and modest secrets, but they aren’t meant to replace a dedicated secrets manager. If you want that root key protected by an external key management service, Nomad 1.8.3 and later can wrap it through a keyring block in the server configuration, with AWS KMS, Azure Key Vault, Google Cloud KMS or Vault’s Transit secrets engine. Only the Transit option involves Vault; the cloud services don’t. Nomad Community Edition allows only one active keyring at a time; having several active at once, so the cluster keeps working if one KMS is unavailable, needs Nomad Enterprise. Refer to the Nomad keyring configuration docs for details.

Granting more access with a job-attached policy

Sooner or later, a job needs something outside its own paths, such as a variable shared by several jobs. That’s where workload-associated policies come in.

Write a normal ACL policy. This one grants read access to everything under shared/ in the default namespace:

hcl
namespace "default" {
  variables {
    path "shared/*" {
      capabilities = ["read"]
    }
  }
}

Then attach it to the job when you create it:

bash
nomad acl policy apply \
  -namespace default -job wi-demo \
  -description "wi-demo: read shared variables" \
  wi-demo-shared-read shared-read.policy.hcl

The -job flag ties the policy to the job’s workload identities instead of to a token. You can narrow it further:

  • -job applies to every task in the job.
  • -group (with -job) applies to every task in one group.
  • -task (with -job and -group) applies to a single task. This is the tightest option, and the one to prefer when only one task needs the access.

-namespace is required with all three.

A few behaviors worth knowing, which we confirmed in testing:

  • No restart needed. Attaching or deleting a policy changed what a running allocation could do on its very next request.
  • Names must match exactly. A policy attached to -task other gave the reader task nothing.
  • The most specific rule wins. An exact-path rule in an attached policy overrides the implicit access; a wildcard rule doesn’t.

Checkpoint: after attaching the policy, a request for shared/config from the task returns 200 instead of 403.

The complete jobspec

Here’s everything together. This batch job exposes its identity, renders a variable through a template, and calls the Task API three times: once for its own variable, once for a shared variable that needs a policy, and once for something it should never get:

hcl
job "wi-demo" {
  type = "batch"

  group "app" {
    task "reader" {
      driver = "exec"

      config {
        command = "/bin/sh"
        args    = ["${NOMAD_TASK_DIR}/check.sh"]
      }

      # Expose the default workload identity to the task.
      identity {
        env  = true # NOMAD_TOKEN
        file = true # ${NOMAD_SECRETS_DIR}/nomad_token
      }

      # Render a variable from the job's own path into the environment.
      template {
        data        = <<-EOT
          {{ with nomadVar "nomad/jobs/wi-demo" }}GREETING={{ .greeting }}{{ end }}
        EOT
        destination = "${NOMAD_SECRETS_DIR}/app.env"
        env         = true
      }

      # A small script that calls the Task API over its Unix socket.
      template {
        destination = "${NOMAD_TASK_DIR}/check.sh"
        perms       = "0755"
        data        = <<-EOT
          #!/bin/sh
          set -u
          SOCK="$NOMAD_SECRETS_DIR/api.sock"

          call() {
            # Send the token as a header on stdin, so it isn't passed in argv.
            printf 'Authorization: Bearer %s\n' "$(cat "$NOMAD_SECRETS_DIR/nomad_token")" |
              curl -sS --unix-socket "$SOCK" -H @- \
                -o /dev/null -w "%%{http_code}  $1\n" "http://localhost$1"
          }

          echo "GREETING from template: $GREETING"
          [ -n "$NOMAD_TOKEN" ] && echo "NOMAD_TOKEN is set"
          [ -S "$SOCK" ] && echo "Task API socket: $SOCK"

          call /v1/var/nomad/jobs/wi-demo   # implicit access
          call /v1/var/shared/config        # needs a policy
          call /v1/jobs                     # not granted
        EOT
      }

      resources {
        cpu    = 100
        memory = 64
      }
    }
  }
}

One line deserves a closer look:

hcl
-o /dev/null -w "%%{http_code}  $1\n" "http://localhost$1"

The doubled %% is HCL escaping. Inside a heredoc, %{ starts an HCL template directive, so %%{ is how you write a literal %{ for curl’s -w option.

We tested with the exec driver, which is available on any Linux client, and repeated the test with the Docker driver (Docker 26.1.5 and the curlimages/curl:8.11.1 image). For Docker, we switched the driver, replaced command = "/bin/sh" with image = "curlimages/curl:8.11.1" and entrypoint = ["/bin/sh"], and renamed the job to wi-demo-docker, which also moves its variable path to nomad/jobs/wi-demo-docker. Apart from that variable path, the identity block, the templates and the check script were unchanged. NOMAD_TOKEN was set, the socket was at /secrets/api.sock, and the three calls returned the same status codes as the exec run: 200, 403 and 403.

Running it

Create the two variables, then run the job before attaching any policy:

bash
printf '{"Items":{"greeting":"hello"}}' |
  nomad var put -in=json nomad/jobs/wi-demo -
printf '{"Items":{"api_url":"https://api.example.internal"}}' |
  nomad var put -in=json shared/config -

nomad job run wi-demo.nomad.hcl
nomad alloc logs <ALLOCATION_ID>

You should see:

text
GREETING from template: hello
NOMAD_TOKEN is set
Task API socket: /secrets/api.sock
200  /v1/var/nomad/jobs/wi-demo
403  /v1/var/shared/config
403  /v1/jobs

The task can read its own variable, but not the shared one, and it can’t list jobs. Now attach the policy from the previous section and run the job again:

text
200  /v1/var/nomad/jobs/wi-demo
200  /v1/var/shared/config
403  /v1/jobs

The shared variable is now readable, and everything else is still denied. That’s least privilege, with no token to copy into the jobspec or rotate by hand.

Keeping it tight

A few habits make this setup safer in production:

  • Expose the identity only to tasks that need it. Templates don’t need the identity block, so many tasks never need one.
  • Prefer file over env for code that might print its environment, and set task.user so only that user can read the token and use the socket.
  • Attach policies at the narrowest level, usually -task, and grant only the capabilities a task actually uses.
  • Attached policies are matched by name. If you delete a job and someone later creates a different job with the same name in the same namespace, its tasks get the same attached policies. Clean up policies when you retire a job.

What about the Nomad Autoscaler?

There isn’t a documented jobspec for running the autoscaler with workload identity yet, so this section sticks to what the documentation covers. For a setup we tested, see the experimental appendix at the end of this post.

Here’s what the Nomad Autoscaler documentation covers today:

  • The autoscaler authenticates with an ACL token. Its nomad block takes the SecretID of an ACL token in token.
  • There’s a policy disposition built for it. A namespace policy of policy = "scale" covers fetching scaling policies, scaling jobs and submitting recommendations.
  • High availability needs a little more. When you run several autoscaler instances, the policy also needs write on the variable lock path, nomad-autoscaler/lock by default.

What isn’t documented is any way for the autoscaler to use a workload identity or the Task API instead of a token. There’s an open, accepted enhancement request for exactly that in the autoscaler’s repository, which notes that its Nomad client would need to support the Task API socket first.

So, for now, the documented setup is an ACL token with the scale policy, and the HA lock rules if you need them. Deliver that token to the autoscaler from your secret store, for example rendered into its configuration file at start-up. Keep it out of command-line flags, and rotate it like any other machine credential.

If workload identity support lands in the autoscaler, it should fit neatly into the pattern in this post. Until it’s documented, the appendix at the end of this post shows an experimental setup we tested on Nomad 2.1.1 with Nomad Autoscaler 0.6.0. Treat it as a starting point for your own testing.

Summary

In this post, we used Nomad’s built-in workload identity without Vault or Consul. We exposed a task’s default identity with the identity block, as NOMAD_TOKEN and as a file in the secrets directory. We called the Nomad API through the Task API socket without putting the token on a command line, and read the job’s own Nomad Variables through the implicit policy, both directly and from a template. We granted access to shared variables with a policy attached by nomad acl policy apply -job, and saw it take effect without a restart. Finally, we looked at the Nomad Autoscaler, whose documented setup still uses an ACL token, and, in an experimental appendix, at an undocumented setup we tested that uses workload identity instead.

Nomatron is a deployment control plane for Nomad, built for planning, approving and applying jobs from Git, so patterns like this one can be reviewed and rolled out consistently.

Want to see how Nomatron fits into your Nomad workflow? Get early access

Appendix (experimental): the Nomad Autoscaler with workload identity

Experimental. This setup isn’t documented. Workload identity support for the Nomad Autoscaler is an open enhancement request (hashicorp/nomad-autoscaler#601). We ran it once, on a single-node dev agent. Treat it as a starting point for your own testing, not a production recipe. It may stop working in a later Nomad or Autoscaler release.

In our test on Nomad 2.1.1 with Nomad Autoscaler 0.6.0, the autoscaler ran as a Nomad job and scaled another job using only its workload identity. There was no ACL token in its configuration or on its command line. Three settings do the work:

  • identity { env = true } puts the task’s workload identity in NOMAD_TOKEN.
  • NOMAD_ADDR = "unix://${NOMAD_SECRETS_DIR}/api.sock" in the task’s env block points the autoscaler’s Nomad client at the Task API socket.
  • The autoscaler’s nomad block sets neither address nor token, so both come from the environment.

Here’s the job we ran:

hcl
job "autoscaler" {
  type = "service"

  group "autoscaler" {
    count = 1

    task "autoscaler" {
      driver = "exec"

      # Pinned release from releases.hashicorp.com, verified by checksum.
      artifact {
        source      = "https://releases.hashicorp.com/nomad-autoscaler/0.6.0/nomad-autoscaler_0.6.0_linux_amd64.zip"
        destination = "local/bin"
        options {
          checksum = "sha256:1d404b456a36a477a8c8cf26de2f79c1ad13510d0b241036f056e0675addeb15"
        }
      }

      # Expose the default workload identity as NOMAD_TOKEN.
      identity {
        env = true
      }

      # Point the Nomad API client at the Task API socket.
      env {
        NOMAD_ADDR = "unix://${NOMAD_SECRETS_DIR}/api.sock"
      }

      config {
        command = "local/bin/nomad-autoscaler"
        args    = ["agent", "-config", "${NOMAD_TASK_DIR}/autoscaler.hcl"]
      }

      # No address or token here: both come from the environment.
      template {
        destination = "${NOMAD_TASK_DIR}/autoscaler.hcl"
        data        = <<-EOT
          log_level = "debug"

          http {
            bind_address = "127.0.0.1"
            bind_port    = 18080
          }

          nomad {
            namespace = ["default"]
          }

          policy {
            default_evaluation_interval = "10s"
          }

          target "nomad-target" {
            driver = "nomad-target"
          }

          strategy "fixed-value" {
            driver = "fixed-value"
          }
        EOT
      }

      resources {
        cpu    = 100
        memory = 128
      }
    }
  }
}

Then attach a policy to the autoscaler job. We granted the scale policy in the default namespace, which covers listing and reading scaling policies and scaling jobs:

hcl
namespace "default" {
  policy = "scale"
}
bash
nomad acl policy apply -namespace default -job autoscaler \
  -description "autoscaler scale (workload-attached)" \
  autoscaler-scale wi-autoscaler.policy.hcl

What we saw:

  • Before the policy was attached, the autoscaler started, but every attempt to list scaling policies failed with 403 (Permission denied). A task’s implicit policy isn’t enough.
  • Within 20 seconds of attaching the policy, with no restart, the autoscaler picked up the scaling policy of a test job and scaled its group from 1 to 2 with the fixed-value strategy. nomad job scaling-events recorded “scaling up because fixed value is 2”, and both allocations were running.
  • The autoscaler’s process arguments were only agent -config /local/autoscaler.hcl.

What we didn’t test: metrics-driven policies through the Nomad APM plugin (its docs say it needs read-job, and node read for cluster metrics), high availability (which needs a variable lock policy), other namespaces, Nomad Autoscaler Enterprise, and long-running behavior.

HashiCorp, Nomad, Vault and Consul are trademarks of HashiCorp. Nomatron is not affiliated with or endorsed by HashiCorp. Other names may be trademarks of their respective owners.