identity Block
Placement | job -> group -> service -> identity job -> group -> task -> identity job -> group -> task -> service -> identity |
The identity
block allows a task access to its Workload Identity via an
environment variable or file. Nomad will create a default identity for all
workloads, but it is not exposed to a task. You may also set additional
identities intended for use with external applications such as Vault, Consul, or
OIDC authentication.
For example, the following will expose the default Workload Identity as an environment variable and file to the task, and a second Workload Identity configured for a third-party OIDC provider:
identity
Parameters
name
(string: "default")
- The name of the workload identity, which must be unique per task. Only oneidentity
block in a task can omit thename
field.aud
([]string: nil)
- The audience field for the workload identity. This should always be set for non-default identities.change_mode
(string: "noop")
- Specifies the behavior Nomad should take when the token changes.change_signal
(string: "")
- Specifies the signal to send to the task as a string like"SIGHUP"
or"SIGUSR1"
. This option is required if thechange_mode
issignal
.env
(bool: false)
- If true the workload identity will be available in the task'sNOMAD_TOKEN
environment variable.file
(bool: false)
- If true the workload identity will be available in the task's filesystem via the pathsecrets/nomad_token
. If thetask.user
parameter is set, the token file will only be readable by that user. Otherwise the file is readable by everyone but is protected by parent directory permissions.filepath
(string: "")
- If not empty and file istrue
, the workload identity will be available at the specified location relative to the task working directory instead of theNOMAD_SECRETS_DIR
.ttl
(string: "")
- The lifetime of the identity before it expires. The client will renew the identity at roughly half the TTL. This is specified using a label suffix like "30s" or "1h". You may not set a TTL on the default identity. You should always set a TTL for non-default identities.
Task API
It can be convenient to combine workload identity with Nomad's Task API for enabling tasks to access the Nomad API.
Workload Identities for Consul
Jobs that need access to Consul can use Nomad workload identities for
authentication. These identities are specified as additional identity
blocks
inside the task or service that will access Consul.
You can configure Nomad servers to automatically add default identities for
Consul using the consul.service_identity
and consul.task_identity
agent configuration. Upon job registration, the Nomad server updates tasks that
have a consul
or template
block and services that use the Consul
service provider to include the default identities.
You can also specify these identities directly in the job. When provided, they
override the default identities configured in the Nomad servers. Identities for
tasks must have a name
that follows the pattern
consul_<cluster name>
. Identities for services do not need to specify a
name
.
In Nomad Community Edition, <cluster_name>
is always default
, so the task
identity name should be consul_default
.
Nomad Enterprise supports multiple Consul clusters. The value of <cluster_name>
must be the same as the consul.cluster
value for the task.
Refer to Nomad Workload Identities section of the Consul integration documentation for more information.
Workload Identities for Vault
Jobs that need access to Vault can use Nomad workload identities for
authentication. These identities are specified as additional identity
blocks
inside the task that will access Vault.
You can configure Nomad servers to automatically add default identities for
Vault using the vault.default_identity
agent configuration. Upon job
registration, the Nomad server updates tasks that have a vault
block to
include the default identity.
You can also specify these identities directly in the job. When provided, they
override the default identity configured in the Nomad servers. The identity
name
must follow the pattern vault_<cluster name>
.
In Nomad Community Edition, <cluster_name>
is always default
, so the
identity name should be vault_default
.
Nomad Enterprise supports multiple Vault clusters. The value of <cluster_name>
must be the same as the vault.cluster
value for the task.
Refer to Nomad Workload Identities section of the Vault integration documentation for more information.