2016-11-01 05:43:51 +00:00
|
|
|
---
|
|
|
|
layout: "docs"
|
|
|
|
page_title: "Vault Integration"
|
|
|
|
sidebar_current: "docs-vault-integration"
|
|
|
|
description: |-
|
|
|
|
Learn how to integrate with HashiCorp Vault and retrieve Vault tokens for
|
|
|
|
tasks.
|
|
|
|
---
|
|
|
|
|
|
|
|
# Vault Integration
|
|
|
|
|
|
|
|
Many workloads require access to tokens, passwords, certificates, API keys, and
|
|
|
|
other secrets. To enable secure, auditable and easy access to your secrets,
|
2016-11-01 19:23:10 +00:00
|
|
|
Nomad integrates with HashiCorp's [Vault][]. Nomad servers and clients
|
2016-11-01 05:43:51 +00:00
|
|
|
coordinate with Vault to derive a Vault token that has access to only the Vault
|
2017-01-27 20:24:59 +00:00
|
|
|
policies the tasks needs. Nomad clients make the token available to the task and
|
2016-11-01 05:43:51 +00:00
|
|
|
handle the tokens renewal. Further, Nomad's [`template` block][template] can
|
|
|
|
retrieve secrets from Vault making it easier than ever to secure your
|
2016-11-01 12:53:13 +00:00
|
|
|
infrastructure.
|
2016-11-01 05:43:51 +00:00
|
|
|
|
|
|
|
Note that in order to use Vault with Nomad, you will need to configure and
|
|
|
|
install Vault separately from Nomad. Nomad does not run Vault for you.
|
|
|
|
|
|
|
|
## Vault Configuration
|
|
|
|
|
2016-11-01 19:23:10 +00:00
|
|
|
To use the Vault integration, Nomad servers must be provided a Vault token. This
|
2017-01-27 23:06:01 +00:00
|
|
|
token can either be a root token or a periodic token with permissions to create
|
|
|
|
from a token role. The root token is the easiest way to get started, but we
|
|
|
|
recommend a token role based token for production installations. Nomad servers
|
|
|
|
will renew the token automatically.
|
2016-11-01 05:43:51 +00:00
|
|
|
|
2017-01-27 20:24:59 +00:00
|
|
|
### Root Token Integration
|
2016-11-01 05:43:51 +00:00
|
|
|
|
2016-11-01 19:23:10 +00:00
|
|
|
If Nomad is given a [root
|
|
|
|
token](https://www.vaultproject.io/docs/concepts/tokens.html#root-tokens), no
|
|
|
|
further configuration is needed as Nomad can derive a token for jobs using any
|
|
|
|
Vault policies.
|
2016-11-01 05:43:51 +00:00
|
|
|
|
2017-01-27 23:06:01 +00:00
|
|
|
### Token Role based Integration
|
2016-11-01 05:43:51 +00:00
|
|
|
|
|
|
|
Vault's [Token Authentication Backend][auth] supports a concept called "roles".
|
2017-01-27 23:06:01 +00:00
|
|
|
Token roles allow policies to be grouped together and token creation to be
|
|
|
|
delegated to a trusted service such as Nomad. By creating a token role, the set
|
|
|
|
of policies that tasks managed by Nomad can access may be limited compared to
|
|
|
|
giving Nomad a root token. Token roles allow both white-list and blacklist
|
|
|
|
management of policies accessible to the role.
|
2016-11-01 05:43:51 +00:00
|
|
|
|
2017-01-27 20:24:59 +00:00
|
|
|
To configure Nomad and Vault to create tokens against a role, the following must
|
|
|
|
occur:
|
|
|
|
|
2017-01-27 23:06:01 +00:00
|
|
|
1. Create a "nomad-server" policy used by Nomad to create and manage tokens.
|
2017-01-27 20:24:59 +00:00
|
|
|
|
2017-01-27 23:06:01 +00:00
|
|
|
2. Create a Vault token role with the configuration described below.
|
2017-01-27 20:24:59 +00:00
|
|
|
|
2017-01-27 23:06:01 +00:00
|
|
|
3. Configure Nomad to use the created token role.
|
2017-01-27 20:24:59 +00:00
|
|
|
|
2017-01-27 23:06:01 +00:00
|
|
|
4. Give Nomad servers a periodic token with the "nomad-server" policy created
|
|
|
|
above.
|
2017-01-27 20:24:59 +00:00
|
|
|
|
|
|
|
#### Required Vault Policies
|
|
|
|
|
|
|
|
The token Nomad receives must have the capabilities listed below. An explanation
|
|
|
|
for the use of each capability is given.
|
|
|
|
|
|
|
|
```
|
2017-01-27 23:06:01 +00:00
|
|
|
# Allow creating tokens under "nomad-cluster" token role. The token role name
|
|
|
|
# should be updated if "nomad-cluster" is not used.
|
2017-01-27 20:24:59 +00:00
|
|
|
path "auth/token/create/nomad-cluster" {
|
|
|
|
capabilities = ["update"]
|
|
|
|
}
|
|
|
|
|
2017-01-27 23:06:01 +00:00
|
|
|
# Allow looking up "nomad-cluster" token role. The token role name should be
|
|
|
|
# updated if "nomad-cluster" is not used.
|
2017-01-27 20:24:59 +00:00
|
|
|
path "auth/token/roles/nomad-cluster" {
|
|
|
|
capabilities = ["read"]
|
|
|
|
}
|
|
|
|
|
|
|
|
# Allow looking up incoming tokens to validate they have permissions to access
|
|
|
|
# the tokens they are requesting. This is only required if
|
|
|
|
# `allow_unauthenticated` is set to false.
|
|
|
|
path "auth/token/lookup" {
|
|
|
|
capabilities = ["update"]
|
|
|
|
}
|
|
|
|
|
|
|
|
# Allow revoking tokens that should no longer exist. This allows revoking
|
|
|
|
# tokens for dead tasks.
|
|
|
|
path "auth/token/revoke-accessor" {
|
|
|
|
capabilities = ["update"]
|
|
|
|
}
|
|
|
|
|
|
|
|
# Allow checking the capabilities of our own token. This is used to validate the
|
|
|
|
# token upon startup.
|
|
|
|
path "/sys/capabilities-self" {
|
|
|
|
capabilities = ["update"]
|
|
|
|
}
|
|
|
|
|
|
|
|
# Allow our own token to be renewed.
|
|
|
|
path "auth/token/renew-self" {
|
|
|
|
capabilities = ["update"]
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
The above [`nomad-server` policy](/data/vault/nomad-server-policy.hcl) is
|
|
|
|
available for download. Below is an example of writing this policy to Vault:
|
|
|
|
|
|
|
|
```
|
|
|
|
# Download the policy
|
|
|
|
$ curl https://nomadproject.io/data/vault/nomad-server-policy.hcl -O -s -L
|
|
|
|
|
|
|
|
# Write the policy to Vault
|
|
|
|
$ vault policy-write nomad-server nomad-server-policy.hcl
|
|
|
|
```
|
|
|
|
|
2017-01-27 23:06:01 +00:00
|
|
|
#### Vault Token Role Configuration
|
2017-01-27 20:24:59 +00:00
|
|
|
|
2017-01-27 23:06:01 +00:00
|
|
|
A Vault token role must be created for use by Nomad. The token role can be used
|
|
|
|
to manage what Vault policies are accessible by jobs submitted to Nomad. The
|
|
|
|
policies can be managed as a whitelist by using `allowed_policies` in the token
|
|
|
|
role definition or as a blacklist by using `disallowed_policies`.
|
2017-01-27 20:24:59 +00:00
|
|
|
|
|
|
|
If using `allowed_policies`, task's may only request Vault policies that are in
|
|
|
|
the list. If `disallowed_policies` is used, task may request any policy that is
|
|
|
|
not in the `disallowed_policies` list. There are tradeoffs to both approaches
|
|
|
|
but generally it is easier to use the blacklist approach and add policies that
|
|
|
|
you would not like tasks to have access to into the `disallowed_policies` list.
|
|
|
|
|
2017-01-27 23:06:01 +00:00
|
|
|
An example token role definition is given below:
|
2016-11-01 05:43:51 +00:00
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
2017-01-27 20:24:59 +00:00
|
|
|
"disallowed_policies": "nomad-server",
|
2016-11-01 19:23:10 +00:00
|
|
|
"explicit_max_ttl": 0,
|
2017-01-27 20:24:59 +00:00
|
|
|
"name": "nomad-cluster",
|
2016-11-01 19:23:10 +00:00
|
|
|
"orphan": false,
|
|
|
|
"period": 259200,
|
|
|
|
"renewable": true
|
2016-11-01 05:43:51 +00:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2017-01-27 23:06:01 +00:00
|
|
|
##### Token Role Requirements
|
2017-01-27 20:24:59 +00:00
|
|
|
|
2017-01-27 23:06:01 +00:00
|
|
|
Nomad checks that token role has an appropriate configuration for use by the
|
2017-01-27 20:24:59 +00:00
|
|
|
cluster. Fields that are checked are documented below as well as descriptions of
|
|
|
|
the important fields. See Vault's [Token Authentication Backend][auth]
|
|
|
|
documentation for all possible fields and more complete documentation.
|
2016-11-01 05:43:51 +00:00
|
|
|
|
2016-11-01 19:23:10 +00:00
|
|
|
* `allowed_policies` - Specifies the list of allowed policies as a
|
2017-01-27 23:06:01 +00:00
|
|
|
comma-separated string. This list should contain all policies that jobs running
|
2017-01-27 20:24:59 +00:00
|
|
|
under Nomad should have access to.
|
|
|
|
|
2017-01-27 23:06:01 +00:00
|
|
|
* `disallowed_policies` - Specifies the list of disallowed policies as a
|
|
|
|
comma-seperated string. This list should contain all policies that jobs running
|
|
|
|
under Nomad should **not** have access to. The policy created above that
|
|
|
|
grants Nomad the ability to generate tokens from the token role should be
|
|
|
|
included in list of disallowed policies. This prevents tokens created by
|
|
|
|
Nomad from generating new tokens with different policies than those granted
|
|
|
|
by Nomad.
|
2016-11-01 05:43:51 +00:00
|
|
|
|
2017-01-27 23:06:01 +00:00
|
|
|
A regression occured in Vault 0.6.4 when validating token creation using a
|
|
|
|
token role with `disallowed_policies` such that it is not usable with
|
|
|
|
Nomad. This will be remedied in 0.6.5 and does not effect earlier versions
|
|
|
|
of Vault.
|
|
|
|
|
|
|
|
* `explicit_max_ttl` - Specifies the max TTL of a token. **Must be set to `0`** to
|
2016-11-01 19:23:10 +00:00
|
|
|
allow periodic tokens.
|
2016-11-01 05:43:51 +00:00
|
|
|
|
2016-11-01 19:23:10 +00:00
|
|
|
* `name` - Specifies the name of the policy. We recommend using the name
|
2017-01-27 23:06:01 +00:00
|
|
|
`nomad-cluster`. If a different name is chosen, replace the token role in the
|
|
|
|
above policy.
|
2016-11-01 05:43:51 +00:00
|
|
|
|
2017-01-27 23:06:01 +00:00
|
|
|
* `orphan` - Specifies whether tokens created against this token role will be
|
|
|
|
orphaned and have no parents. **Must be set to `false`**. This ensures that the
|
2016-11-01 19:23:10 +00:00
|
|
|
token can be revoked when the task is no longer needed or a node dies.
|
2016-11-01 05:43:51 +00:00
|
|
|
|
2016-11-01 19:23:10 +00:00
|
|
|
* `period` - Specifies the length the TTL is extended by each renewal in
|
|
|
|
seconds. It is suggested to set this value on the order of magnitude of 3 days
|
2017-01-27 23:06:01 +00:00
|
|
|
(259200 seconds) to avoid a large renewal request rate to Vault. **Must be set
|
|
|
|
to a positive value**.
|
2016-11-01 05:43:51 +00:00
|
|
|
|
2017-01-27 23:06:01 +00:00
|
|
|
* `renewable` - Specifies whether created tokens are renewable. **Must be set to
|
|
|
|
`true`**. This allows Nomad to renew tokens for tasks.
|
2016-11-01 05:43:51 +00:00
|
|
|
|
2017-01-27 23:06:01 +00:00
|
|
|
The above [`nomad-cluster` token role](/data/vault/nomad-cluster-role.hcl) is
|
2017-01-27 20:24:59 +00:00
|
|
|
available for download. Below is an example of writing this role to Vault:
|
|
|
|
|
|
|
|
```
|
2017-01-27 23:06:01 +00:00
|
|
|
# Download the token role
|
2017-01-27 20:24:59 +00:00
|
|
|
$ curl https://nomadproject.io/data/vault/nomad-cluster-role.json -O -s -L
|
|
|
|
|
2017-01-27 23:06:01 +00:00
|
|
|
# Create the token role with Vault
|
2017-01-27 20:24:59 +00:00
|
|
|
$ vault write /auth/token/roles/nomad-cluster @nomad-cluster-role.json
|
|
|
|
```
|
|
|
|
|
2016-11-01 05:43:51 +00:00
|
|
|
|
2016-11-01 19:23:10 +00:00
|
|
|
#### Example Configuration
|
|
|
|
|
|
|
|
To make getting started easy, the basic [`nomad-server`
|
|
|
|
policy](/data/vault/nomad-server-policy.hcl) and
|
2017-01-27 23:06:01 +00:00
|
|
|
[`nomad-cluster` role](/data/vault/nomad-cluster-role.json) described above are
|
|
|
|
available for download.
|
2016-11-01 19:23:10 +00:00
|
|
|
|
2017-01-27 23:06:01 +00:00
|
|
|
The below example assumes Vault is accessible, unsealed and the operator has
|
2016-11-01 19:23:10 +00:00
|
|
|
appropriate permissions.
|
|
|
|
|
2016-11-02 00:40:42 +00:00
|
|
|
```shell
|
2017-01-27 23:06:01 +00:00
|
|
|
# Download the policy and token role
|
2016-11-08 05:35:14 +00:00
|
|
|
$ curl https://nomadproject.io/data/vault/nomad-server-policy.hcl -O -s -L
|
2017-01-27 20:24:59 +00:00
|
|
|
$ curl https://nomadproject.io/data/vault/nomad-cluster-role.json -O -s -L
|
2016-11-01 19:23:10 +00:00
|
|
|
|
|
|
|
# Write the policy to Vault
|
|
|
|
$ vault policy-write nomad-server nomad-server-policy.hcl
|
|
|
|
|
2017-01-27 23:06:01 +00:00
|
|
|
# Create the token role with Vault
|
2017-01-27 20:24:59 +00:00
|
|
|
$ vault write /auth/token/roles/nomad-cluster @nomad-cluster-role.json
|
2016-11-01 19:23:10 +00:00
|
|
|
```
|
|
|
|
|
2017-01-27 23:06:01 +00:00
|
|
|
#### Retrieving the Token Role based Token
|
2016-11-01 05:43:51 +00:00
|
|
|
|
2017-01-27 23:06:01 +00:00
|
|
|
After the token role is created, a token suitable for the Nomad servers may be
|
2016-11-01 05:43:51 +00:00
|
|
|
retrieved by issuing the following Vault command:
|
|
|
|
|
|
|
|
```
|
2017-01-27 20:24:59 +00:00
|
|
|
$ vault token-create -policy nomad-server -period 72h
|
2016-11-01 05:43:51 +00:00
|
|
|
Key Value
|
|
|
|
--- -----
|
|
|
|
token f02f01c2-c0d1-7cb7-6b88-8a14fada58c0
|
|
|
|
token_accessor 8cb7fcb3-9a4f-6fbf-0efc-83092bb0cb1c
|
|
|
|
token_duration 259200s
|
|
|
|
token_renewable true
|
2017-01-27 20:24:59 +00:00
|
|
|
token_policies [default nomad-server]
|
2016-11-01 05:43:51 +00:00
|
|
|
```
|
|
|
|
|
2016-11-01 19:23:10 +00:00
|
|
|
The token can then be set in the server configuration's [vault block][config],
|
|
|
|
as a command-line flag, or via an environment variable.
|
2016-11-01 05:43:51 +00:00
|
|
|
|
2016-11-01 19:23:10 +00:00
|
|
|
```
|
|
|
|
$ VAULT_TOKEN=f02f01c2-c0d1-7cb7-6b88-8a14fada58c0 nomad agent -config /path/to/config
|
|
|
|
```
|
|
|
|
|
2016-11-01 05:43:51 +00:00
|
|
|
## Agent Configuration
|
|
|
|
|
|
|
|
To enable Vault integration, please see the [Nomad agent Vault
|
|
|
|
integration][config] configuration.
|
|
|
|
|
|
|
|
## Vault Definition Syntax
|
|
|
|
|
|
|
|
To configure a job to retrieve Vault tokens, please see the [`vault` job
|
|
|
|
specification documentation][vault-spec].
|
|
|
|
|
2016-11-01 12:53:13 +00:00
|
|
|
## Troubleshooting
|
2016-11-01 19:23:10 +00:00
|
|
|
|
|
|
|
Upon startup, Nomad will attempt to connect to the specified Vault server. Nomad
|
2017-01-27 23:06:01 +00:00
|
|
|
will lookup the passed token and if the token is from a token role, the token
|
|
|
|
role will be validated. Nomad will not shutdown if given an invalid Vault token,
|
|
|
|
but will log the reasons the token is invalid and disable Vault integration.
|
2016-11-01 19:23:10 +00:00
|
|
|
|
2016-11-01 05:43:51 +00:00
|
|
|
## Assumptions
|
|
|
|
|
|
|
|
- Vault 0.6.2 or later is needed.
|
|
|
|
|
|
|
|
[auth]: https://www.vaultproject.io/docs/auth/token.html "Vault Authentication Backend"
|
2017-01-27 20:24:59 +00:00
|
|
|
[config]: /docs/agent/configuration/vault.html "Nomad Vault Configuration Block"
|
|
|
|
[createfromrole]: /docs/agent/configuration/vault.html#create_from_role "Nomad vault create_from_role Configuration Flag"
|
2016-11-01 05:43:51 +00:00
|
|
|
[template]: /docs/job-specification/template.html "Nomad template Job Specification"
|
|
|
|
[vault]: https://www.vaultproject.io/ "Vault by HashiCorp"
|
|
|
|
[vault-spec]: /docs/job-specification/vault.html "Nomad Vault Job Specification"
|