Configuring a Connect CA Provider

NOTE: Instructions below should only be used for initially bootstrapping a cluster. To update the Connect CA provider on an existing cluster or to update any properties, such as tokens, of the CA provider, please use the Update CA Configuration Endpoint.

Consul has support for different certificate authority (CA) providers to be used with the Consul Service Mesh. Please see Connect Certificate Management for the information on the providers we currently support.

Generally, to configure a provider via the Consul Helm chart, you need to follow three steps:

  1. Create a configuration file containing your provider information.
  2. Create a Kubernetes secret containing the configuration file.
  3. Reference the Kubernetes secret in the server.extraVolumes value in the Helm chart.

Below we will go over this process for configuring Vault as the Connect CA. However, other providers can be configured similarly by providing the appropriate ca_config and ca_provider values for the provider you’re using.

Configuring Vault as a Connect CA

Primary Datacenter

To configure Vault as a CA provider for Consul Connect, first, create a provider configuration JSON file. Please refer to Vault as a Connect CA for the configuration options. You will need to provide a Vault token to the token property. Please refer to these docs for the permissions that the token needs to have. 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:

  1. kubectl create secret generic vault-ca --from-file vault.ca=/path/to/your/vault/ca

And then reference it like this in the provider configuration:

  1. $ cat vault-config.json
  2. {
  3. "connect": [
  4. {
  5. "ca_config": [
  6. {
  7. "address": "https://vault:8200",
  8. "intermediate_pki_path": "dc1/connect-intermediate",
  9. "root_pki_path": "connect-root",
  10. "token": "s.VgQvaXl8xGFO1RUxAPbPbsfN",
  11. "ca_file": "/consul/userconfig/vault-ca/vault.ca"
  12. }
  13. ],
  14. "ca_provider": "vault"
  15. }
  16. ]
  17. }

This example configuration file is pointing to a Vault instance running in the same Kubernetes cluster, which has been deployed with TLS enabled. Note that the ca_file is pointing to the file location based on the Kubernetes secret for the Vault CA that we have created before. We will provide that secret later in the Helm values for our Consul cluster.

NOTE: If you have used Kubernetes CA to sign Vault’s certificate, such as shown in Standalone Server with TLS, you don’t need to create a Kubernetes secret with Vault’s CA and can reference the CA directly by setting ca_file to /var/run/secrets/kubernetes.io/serviceaccount/ca.crt.

Next, create a Kubernetes secret with this configuration file.

  1. $ kubectl create secret generic vault-config --from-file=config=vault-config.json

We will provide this secret and the Vault CA secret, to the Consul server via the server.extraVolumes Helm value.

  1. # config.yaml
  2. global:
  3. name: consul
  4. server:
  5. extraVolumes:
  6. - type: secret
  7. name: vault-config
  8. load: true
  9. items:
  10. - key: config
  11. path: vault-config.json
  12. - type: secret
  13. name: vault-ca
  14. load: false
  15. connectInject:
  16. enabled: true

Finally, install the Helm chart using the above config file:

  1. $ helm install consul -f config.yaml hashicorp/consul

Verify that the CA provider is set correctly:

  1. $ kubectl exec consul-server-0 -- curl -s http://localhost:8500/v1/connect/ca/configuration | jq .
  2. {
  3. "Provider": "vault",
  4. "Config": {
  5. "Address": "https://vault:8200",
  6. "CAFile": "/consul/userconfig/vault-server-tls/vault.ca",
  7. "IntermediateCertTTL": "8760h",
  8. "IntermediatePKIPath": "connect-intermediate",
  9. "LeafCertTTL": "72h",
  10. "RootPKIPath": "connect-root",
  11. "RotationPeriod": "2160h",
  12. "Token": "s.VgQvaXl8xGFO1RUxAPbPbsfN"
  13. },
  14. "State": null,
  15. "ForceWithoutCrossSigning": false,
  16. "CreateIndex": 5,
  17. "ModifyIndex": 5
  18. }

Secondary Datacenters

To configure Vault as the Connect CA in secondary datacenters, you need to make sure that the Root CA is the same, but the intermediate is different for each datacenter. In the connect configuration for a secondary datacenter, you can specify a intermediate_pki_path that is, for example, prefixed with the datacenter for which this configuration is intended. You will similarly need to create a Vault token and a Kubernetes secret with Vault’s CA in each secondary Kubernetes cluster.

  1. {
  2. "connect": [
  3. {
  4. "ca_config": [
  5. {
  6. "address": "https://vault:8200",
  7. "intermediate_pki_path": "dc2/connect-intermediate",
  8. "root_pki_path": "connect-root",
  9. "token": "s.VgQvaXl8xGFO1RUxAPbPbsfN",
  10. "ca_file": "/consul/userconfig/vault-ca/vault.ca"
  11. }
  12. ],
  13. "ca_provider": "vault"
  14. }
  15. ]
  16. }

Note that all secondary datacenters need to have access to the same Vault instance as the primary.

Rotating Vault Tokens

Once the cluster is running, subsequent changes to the ca_provider config are ignored–even if consul reload is run or the servers are restarted.

To update any settings under this key, you must use Consul’s Update CA Configuration API or the consul connect ca set-config command.