2018-06-24 21:55:26 +00:00
---
2020-04-07 18:55:19 +00:00
layout: docs
page_title: Connect - Certificate Management
2020-04-13 18:40:26 +00:00
sidebar_title: Built-In CA
2020-04-07 18:55:19 +00:00
description: >-
Consul ships with a built-in CA system so that Connect can be easily enabled
out of the box. The built-in CA generates and stores the root certificate and
private key on Consul servers. It can also be configured with a custom
certificate and private key if needed.
2018-06-24 21:55:26 +00:00
---
# Built-In CA
Consul ships with a built-in CA system so that Connect can be
easily enabled out of the box. The built-in CA generates and stores the
root certificate and private key on Consul servers. It can also be
configured with a custom certificate and private key if needed.
If Connect is enabled and no CA provider is specified, the built-in
CA is the default provider used. The provider can be
2020-04-09 23:46:54 +00:00
[updated and rotated](/docs/connect/ca#root-certificate-rotation)
2018-06-24 21:55:26 +00:00
at any point to migrate to a new provider.
-> This page documents the specifics of the built-in CA provider.
2020-04-09 23:46:54 +00:00
Please read the [certificate management overview](/docs/connect/ca)
2018-06-24 21:55:26 +00:00
page first to understand how Consul manages certificates with configurable
CA providers.
## Configuration
The built-in CA provider has no required configuration. Enabling Connect
alone will configure the built-in CA provider and will automatically generate
a root certificate and private key:
```hcl
connect {
enabled = true
}
```
2019-11-21 17:40:29 +00:00
The configuration options are listed below. Note, the
first key is the value used in API calls and the second key (after the `/`)
is used if you're adding configuring to the agent's configuration file.
2018-06-24 21:55:26 +00:00
2020-04-06 20:27:35 +00:00
- `PrivateKey` / `private_key` (`string: ""`) - A PEM-encoded private key
for signing operations. This must match the private key used for the root
certificate if it is manually specified. If this is blank, a private key
is automatically generated.
2018-06-24 21:55:26 +00:00
2020-04-06 20:27:35 +00:00
- `RootCert` / `root_cert` (`string: ""`) - A PEM-encoded root certificate
to use. If this is blank, a root certificate is automatically generated
using the private key specified. If this is specified, the certificate
must be a valid
[SPIFFE SVID signing certificate](https://github.com/spiffe/spiffe/blob/master/standards/X509-SVID.md)
and the URI in the SAN must match the cluster identifier created at
bootstrap with the ".consul" TLD. The cluster identifier can be found
2020-04-09 23:46:54 +00:00
using the [CA List Roots endpoint](/api/connect/ca#list-ca-root-certificates).
2018-06-24 21:55:26 +00:00
2020-04-09 23:46:54 +00:00
There are also [common CA configuration options](/docs/agent/options#common-ca-config-options)
2018-07-16 09:46:23 +00:00
that are supported by all CA providers.
2018-06-24 21:55:26 +00:00
## Specifying a Custom Private Key and Root Certificate
By default, a root certificate and private key will be automatically
generated during the cluster's bootstrap. It is possible to configure
the Consul CA provider to use a specific private key and root certificate.
This is particularly useful if you have an external PKI system that doesn't
currently integrate with Consul directly.
2020-04-09 23:46:54 +00:00
To view the current CA configuration, use the [Get CA Configuration endpoint](/api/connect/ca#get-ca-configuration):
2018-06-24 21:55:26 +00:00
2020-05-19 18:32:38 +00:00
```shell-session
2018-06-24 21:55:26 +00:00
$ curl localhost:8500/v1/connect/ca/configuration
{
"Provider": "consul",
"Config": {
2018-07-16 09:46:23 +00:00
"LeafCertTTL": "72h",
2020-01-17 22:27:13 +00:00
"RotationPeriod": "2160h",
"IntermediateCertTTL": "8760h"
2018-06-24 21:55:26 +00:00
},
"CreateIndex": 5,
"ModifyIndex": 5
}
```
This is the default Connect CA configuration if nothing is explicitly set when
Connect is enabled - the PrivateKey and RootCert fields have not been set, so those have
been generated (as seen above in the roots list).
There are two ways to have the Consul CA use a custom private key and root certificate:
2020-04-09 23:46:54 +00:00
either through the `ca_config` section of the [Agent configuration](/docs/agent/options#connect_ca_config) (which can only be used during the cluster's
initial bootstrap) or through the [Update CA Configuration endpoint](/api/connect/ca#update-ca-configuration).
2018-06-24 21:55:26 +00:00
2020-04-06 20:27:35 +00:00
Currently consul requires that root certificates are valid [SPIFFE SVID Signing certificates](https://github.com/spiffe/spiffe/blob/master/standards/X509-SVID.md) and that the URI encoded
2018-06-24 21:55:26 +00:00
in the SAN is the cluster identifier created at bootstrap with the ".consul" TLD. In this
example, we will set the URI SAN to `spiffe://36cb52cd-4058-f811-0432-6798a240c5d3.consul`.
In order to use the Update CA Configuration HTTP endpoint, the private key and certificate
must be passed via JSON:
2020-05-19 18:32:38 +00:00
```shell-session
2018-06-24 21:55:26 +00:00
$ jq -n --arg key "$(cat root.key)" --arg cert "$(cat root.crt)" '
{
"Provider": "consul",
"Config": {
2018-07-16 09:46:23 +00:00
"LeafCertTTL": "72h",
2018-06-24 21:55:26 +00:00
"PrivateKey": $key,
"RootCert": $cert,
2020-01-17 22:27:13 +00:00
"RotationPeriod": "2160h",
"IntermediateCertTTL": "8760h"
2018-06-24 21:55:26 +00:00
}
}' > ca_config.json
```
The resulting `ca_config.json` file can then be used to update the active root certificate:
2020-05-19 18:32:38 +00:00
```shell-session
2018-06-24 21:55:26 +00:00
$ cat ca_config.json
{
"Provider": "consul",
"Config": {
2018-07-16 09:46:23 +00:00
"LeafCertTTL": "72h",
2018-06-24 21:55:26 +00:00
"PrivateKey": "-----BEGIN RSA PRIVATE KEY-----\nMIIEpAIBAAKCAQEArqiy1c3pbT3cSkjdEM1APALUareU...",
"RootCert": "-----BEGIN CERTIFICATE-----\nMIIDijCCAnKgAwIBAgIJAOFZ66em1qC7MA0GCSqGSIb3...",
2020-01-17 22:27:13 +00:00
"RotationPeriod": "2160h",
"IntermediateCertTTL": "8760h"
2018-06-24 21:55:26 +00:00
}
}
$ curl --request PUT --data @ca_config.json localhost:8500/v1/connect/ca/configuration
...
[INFO] connect: CA rotated to new root under provider "consul"
```
The cluster is now using the new private key and root certificate. Updating the CA config
this way also triggered a certificate rotation.