consul: provide CONSUL_HTTP_TOKEN env var to tasks (#20519)

When available, we provide an environment variable `CONSUL_TOKEN` to tasks, but
this isn't the environment variable expected by the Consul CLI. Job
specifications like deploying an API Gateway become noticeably nicer if we can
instead provide the expected env var.
This commit is contained in:
Tim Gross
2024-05-03 11:30:33 -04:00
committed by GitHub
parent cd9e032855
commit f41bc468eb
3 changed files with 33 additions and 25 deletions

3
.changelog/20519.txt Normal file
View File

@@ -0,0 +1,3 @@
```release-note:improvement
consul: provide tasks that have Consul tokens the CONSUL_HTTP_TOKEN environment variable
```

View File

@@ -80,6 +80,7 @@ func (h *consulHook) Prestart(ctx context.Context, req *interfaces.TaskPrestartR
env := map[string]string{
"CONSUL_TOKEN": token.SecretID,
"CONSUL_HTTP_TOKEN": token.SecretID,
}
resp.Env = env

View File

@@ -1,7 +1,7 @@
### Job-related variables
| Variable | Description |
|--------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|--------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `NOMAD_ALLOC_DIR` | The path to the shared `alloc/` directory. See the [Runtime Task Directories documentation][taskdirs] for more information. |
| `NOMAD_TASK_DIR` | The path to the task `local/` directory. See the [Runtime Task Directories documentation][taskdirs] for more information. |
| `NOMAD_SECRETS_DIR` | Path to the task's `secrets/` directory. See the [Runtime Task Directories documentation][taskdirs] for more information. |
@@ -23,8 +23,11 @@
| `NOMAD_NAMESPACE` | Namespace in which the allocation is running |
| `NOMAD_REGION` | Region in which the allocation is running |
| `NOMAD_META_<key>` | The metadata value given by `key` on the task's metadata. Any character in a key other than `[A-Za-z0-9_.]` will be converted to `_`. <br/> **Note:** this is different from [`${meta.<key>}`](/nomad/docs/runtime/interpolation#node-variables-) which are keys in the node's metadata. |
| `CONSUL_HTTP_TOKEN` | The tasks' Consul token. See [Consul Integration][consul] documentation for more details. |
| `CONSUL_TOKEN` | The tasks' Consul token. See [Consul Integration][consul] documentation for more details. This variable is deprecated and exists only for backwards compatibility. |
| `VAULT_TOKEN` | The task's Vault token. See the [Vault Integration][vault] documentation for more details |
### Network-related Variables
| Variable | Description |
@@ -66,3 +69,4 @@ names such as `NOMAD_ADDR_<task>_<label>`
[taskdirs]: /nomad/docs/runtime/environment#task-directories
[network-block]: /nomad/docs/job-specification/network
[vault]: /nomad/docs/integrations/vault-integration
[consul]: /nomad/docs/integrations/consul-integration