2021-12-15 18:59:36 +00:00
---
layout: docs
page_title: Vault as the Service Mesh Certificate Provider on Kubernetes
description: >-
Using Vault as the provider for the Service Mesh certificates on Kubernetes.
---
# Vault as the Service Mesh Certificate Provider on Kubernetes
2022-06-17 16:23:54 +00:00
This topic describes how to configure the Consul Helm chart to use TLS certificates issued by Vault for Consul service mesh communication.
2021-12-15 18:59:36 +00:00
-> **Note:** This feature requires Consul 1.11 or higher. As of v1.11,
2023-05-05 17:41:40 +00:00
Consul allows using Kubernetes auth methods to configure the service mesh CA.
2021-12-15 18:59:36 +00:00
This allows for automatic token rotation once the renewal is no longer possible.
2023-05-05 17:41:40 +00:00
~> **Compatibility note:** If you use Vault 1.11.0+ as Consul's service mesh CA, versions of Consul released before Dec 13, 2022 will develop an issue with Consul control plane or service mesh communication ([GH-15525](https://github.com/hashicorp/consul/pull/15525)). Use or upgrade to a [Consul version that includes the fix](https://support.hashicorp.com/hc/en-us/articles/11308460105491#01GMC24E6PPGXMRX8DMT4HZYTW) to avoid this problem.
2022-11-17 16:51:43 +00:00
2022-04-07 18:16:24 +00:00
## Overview
2022-12-19 18:32:25 +00:00
2023-01-25 16:52:43 +00:00
To use Vault as the service mesh certificate provider on Kubernetes, you will complete a modified version of the steps outlined in the [Data Integration](/consul/docs/k8s/deployment-configurations/vault/data-integration) section.
2022-04-07 18:16:24 +00:00
2022-07-15 16:35:42 +00:00
Complete the following steps once:
2022-04-07 18:16:24 +00:00
1. Create a Vault policy that authorizes the desired level of access to the secret.
2022-07-15 16:35:42 +00:00
Repeat the following steps for each datacenter in the cluster:
2022-04-07 18:16:24 +00:00
1. Create Vault Kubernetes auth roles that link the policy to each Consul on Kubernetes service account that requires access.
2022-06-17 16:23:54 +00:00
1. Update the Consul on Kubernetes helm chart.
## Prerequisites
Prior to setting up the data integration between Vault and Consul on Kubernetes, you will need to have:
2023-01-25 16:52:43 +00:00
1. Read and completed the steps in the [Systems Integration](/consul/docs/k8s/deployment-configurations/vault/systems-integration) section of [Vault as a Secrets Backend](/consul/docs/k8s/deployment-configurations/vault).
2. Read the [Data Integration Overview](/consul/docs/k8s/deployment-configurations/vault/data-integration) section of [Vault as a Secrets Backend](/consul/docs/k8s/deployment-configurations/vault).
2022-04-07 18:16:24 +00:00
2022-07-15 16:35:42 +00:00
## Create Vault policy
2022-04-07 18:16:24 +00:00
2023-01-25 16:52:43 +00:00
To configure [Vault as the provider](/consul/docs/connect/ca/vault) for the Consul service mesh certificates,
2021-12-15 18:59:36 +00:00
you will first need to decide on the type of policy that is suitable for you.
2023-01-25 16:52:43 +00:00
To see the permissions that Consul would need in Vault, please see [Vault ACL policies](/consul/docs/connect/ca/vault#vault-acl-policies)
2021-12-15 18:59:36 +00:00
documentation.
2022-07-15 16:35:42 +00:00
## Create Vault Authorization Roles for Consul
2022-04-07 18:16:24 +00:00
Next, you will create Kubernetes auth roles for the Consul servers:
2021-12-15 18:59:36 +00:00
```shell-session
2022-01-21 19:01:48 +00:00
$ vault write auth/kubernetes/role/consul-server \
2021-12-15 18:59:36 +00:00
bound_service_account_names=<Consul server service account> \
bound_service_account_namespaces=<Consul installation namespace> \
2023-05-05 17:41:40 +00:00
policies=<service mesh CA policy> \
2021-12-15 18:59:36 +00:00
ttl=1h
```
To find out the service account name of the Consul server,
2022-01-12 23:05:01 +00:00
you can run:
2021-12-15 18:59:36 +00:00
```shell-session
2022-09-30 16:13:44 +00:00
$ helm template --release-name ${RELEASE_NAME} --show-only templates/server-serviceaccount.yaml hashicorp/consul -f values.yaml
2021-12-15 18:59:36 +00:00
```
2022-07-15 16:35:42 +00:00
## Update Consul on Kubernetes Helm chart
2023-05-05 17:41:40 +00:00
Now you can configure the Consul Helm chart to use Vault as the service mesh (connect) CA provider:
2022-01-21 19:01:48 +00:00
<CodeBlockConfig filename="values.yaml">
2021-12-15 18:59:36 +00:00
```yaml
global:
secretsBackend:
vault:
enabled: true
consulServerRole: consul-server
consulClientRole: consul-client
consulCARole: consul-ca
connectCA:
address: <the address of the Vault server>
rootPKIPath: <the path to root PKI>
intermediatePKIPath: <the path to intermediate PKI>
ca:
secretName: <vaultCASecret>
```
2022-01-21 19:01:48 +00:00
</CodeBlockConfig>
2021-12-15 18:59:36 +00:00
The `address` you provide to the `connectCA` configuration can be a Kubernetes DNS
address if the Vault cluster is running the same Kubernetes cluster.
The `rootPKIPath` and `intermediatePKIPath` should be the same as the ones
2023-05-05 17:41:40 +00:00
defined in your service mesh CA policy. Behind the scenes, Consul will authenticate to Vault using a Kubernetes
2023-01-25 16:52:43 +00:00
service account using the [Kubernetes auth method](/vault/docs/auth/kubernetes) and will use the Vault token for any API calls to Vault. If the Vault token can not be renewed, Consul will re-authenticate to
2022-01-12 23:05:01 +00:00
generate a new Vault token.
2021-12-15 18:59:36 +00:00
The `vaultCASecret` is the Kubernetes secret that stores the CA Certificate that is used for Vault communication. To provide a CA, you first need to create a Kubernetes secret containing the CA. For example, you may create a secret with the Vault CA like so:
2022-01-21 19:01:48 +00:00
```shell-session
$ kubectl create secret generic vault-ca --from-file vault.ca=/path/to/your/vault/ca
2021-12-15 18:59:36 +00:00
```
### Secondary Datacenters
2023-05-05 17:41:40 +00:00
To configure Vault as the service mesh (connect) CA in secondary datacenters, you need to make sure that the Root CA path is the same,
2021-12-15 18:59:36 +00:00
but the intermediate is different for each datacenter. In the `connectCA` Helm configuration for a secondary datacenter,
you can specify a `intermediatePKIPath` that is, for example, prefixed with the datacenter
for which this configuration is intended (e.g. `dc2/connect-intermediate`).