Use Client Certificates for XDCR Authentication
An XDCR source cluster can authenticate with its target cluster by presenting a client certificate and private key, instead of a username and password.
Understanding Client-Certificate Authentication for XDCR
When you create a fully secure XDCR reference, the source cluster authenticates with the target cluster in one of two ways: with a username and password, or with a client certificate and its private key. This page explains the second way.
In this exchange, the source cluster acts as the client and the target cluster acts as the server. The client certificate is the certificate that the source cluster presents to the target cluster. See Defining Client and Server.
This page is for administrators who receive their certificates from a security team or a certificate authority, rather than create them. To create test certificates yourself, see Configure Client Certificates.
Before the source cluster can authenticate with a client certificate, the target cluster must:
-
Have a user whose name matches the username in the client certificate, with the Full Admin or XDCR Inbound role.
-
Have client-certificate handling enabled, with a path that tells Couchbase Server where to find the username in the certificate.
-
Trust the root certificate that issued the client certificate, and every intermediate certificate between them.
A fully secure reference also needs the root certificate of the target cluster. The source cluster uses this certificate to verify the target cluster’s nodes. It’s a different certificate from the root certificate that issued the client certificate, unless one certificate authority issued both.
The steps below take you through this setup on the target cluster, and then create the reference on the source cluster.
Example Certificate Files
The steps on this page use a typical bundle that a security team issues for a client certificate request:
file1.pem file2.pem file3.pem file4.key
The .key file is the client private key.
Step 1 shows how to tell which .pem file is the root certificate, which is the intermediate certificate, and which is the client certificate.
Your bundle might contain more than one intermediate certificate.
Step 1: Identify the Certificates and the Username
-
Display the contents of each
.pemfile:openssl x509 -text -noout -in file1.pem openssl x509 -text -noout -in file2.pem openssl x509 -text -noout -in file3.pem -
Use the following fields to identify each certificate:
Certificate Issuer and Subject Basic Constraints Key Usage Root certificate
The same
CA:TRUECertificate Sign, CRL Sign
Intermediate certificate
Different
CA:TRUECertificate Sign, CRL Sign
Client certificate
Different
CA:FALSEDigital Signature, with the Extended Key Usage TLS Web Client Authentication
-
In the client certificate, find the username. The username is usually in the Subject Alternative Name, and sometimes in the Subject Common Name. For example, the following client certificate holds the username in an email Subject Alternative Name:
Certificate: Data: ... Issuer: C = UA, O = MyCompany, OU = People, CN = ClientSigningCA ... Subject: C = UA, O = MyCompany, OU = People, CN = clientuser ... X509v3 extensions: X509v3 Basic Constraints: CA:FALSE X509v3 Extended Key Usage: TLS Web Client Authentication X509v3 Key Usage: Digital Signature X509v3 Subject Alternative Name: email:xdcruser@mycompany.comIn this example, the username is
xdcruser: Step 3 configures the target cluster to take the part of the email address that comes before the@character.A client certificate can also hold the username in its Subject Common Name only. See Deprecation of Subject Common Name.
-
Copy or rename the files so that their names show what each one is. The names themselves don’t matter. For example:
cp file1.pem ca.pem cp file2.pem int.pem cp file3.pem clientuser.pem cp file4.key clientuser.key -
Verify that the root and intermediate certificates validate the client certificate:
openssl verify -trusted ca.pem -untrusted int.pem clientuser.pemIf the certificates form a valid chain, the command returns:
clientuser.pem: OK
Step 2: Create the User on the Target Cluster
On the target cluster, check whether a user with the username from Step 1 exists. If the user doesn’t exist, create it. See Add a User.
Give the user the Full Admin role, or the XDCR Inbound role for the target bucket or for all buckets on the target cluster.
Step 3: Enable Client-Certificate Handling on the Target Cluster
On the target cluster, set Require Client Certificate to Enable or Mandatory, and add a path that matches where your client certificates hold the username. See Enable Client-Certificate Handling for the UI, CLI, and REST API procedures.
Mandatory requires every client of the target cluster to authenticate with a certificate. Enable also accepts clients that authenticate with a username and password.
For the example certificate in Step 1, add the following path:
| Path | Prefix | Delimiter |
|---|---|---|
|
(blank) |
|
The default path is subject.cn, which reads the username from the Subject Common Name.
If your client certificates hold the username in a Subject Alternative Name, add a path for it.
Add a path for every place where your client certificates can hold the username.
For an explanation of paths, prefixes, and delimiters, see Specifying Usernames for Client Certificate Authentication.
Step 4: Make the Target Cluster Trust the Client Certificate
The target cluster must trust the root certificate that issued the client certificate, and every intermediate certificate in between. You can supply the intermediate certificates in either of two ways:
-
Load the intermediate certificates into the trust store. Load the root certificate and the intermediate certificates into the target cluster’s trust store. In Step 5, supply the client certificate on its own. If your certificate authority later issues client certificates from a new intermediate certificate, load that intermediate certificate too.
-
Supply the intermediate certificates in a chain. Load only the root certificate into the target cluster’s trust store. In Step 5, supply a chain file that starts with the client certificate and continues with each intermediate certificate in order, ending with the one that the root certificate signed. The chain must be in the correct order, or authentication fails.
cat clientuser.pem int.pem > chain.pem
To load certificates into the trust store, copy them into the inbox/CA directory on a target cluster node, and then call Load Root Certificates on that node.
For example, on Linux, to load the root and intermediate certificates:
sudo mkdir -p /opt/couchbase/var/lib/couchbase/inbox/CA
sudo cp ca.pem int.pem /opt/couchbase/var/lib/couchbase/inbox/CA/
sudo chown couchbase /opt/couchbase/var/lib/couchbase/inbox/CA/*.pem
curl -X POST http://localhost:8091/node/controller/loadTrustedCAs \
-u Administrator:password
-
Run the commands on the target cluster node whose
inbox/CAdirectory holds the certificates. -
Replace
Administrator:passwordwith the credentials of a Full Admin on the target cluster. -
For the
inbox/CAlocation on Windows and macOS, see Load Root Certificates.
After loading, the certificates appear under Trusted Root Certificates on the target cluster’s Security > Certificates screen.
Step 5: Create the Reference on the Source Cluster
On the source cluster, create a fully secure reference that authenticates with the client certificate and private key.
Supply the client certificate as clientuser.pem if you loaded the intermediate certificates into the trust store, or as chain.pem if you created a chain in Step 4.
Don’t supply a username and password: the reference uses either a username and password or a client certificate, not both.
In the UI, follow Specify Root and Client Certificates, and Client Private Key.
With the REST API, run a command like the following:
curl -X POST -u Administrator:password \
http://source.example.com:8091/pools/default/remoteClusters \
-d name=TargetCluster \
-d hostname=target.example.com:8091 \
-d secureType=full \
--data-urlencode "certificate=$(cat ./target-ca.pem)" \
--data-urlencode "clientCertificate=$(cat ./clientuser.pem)" \
--data-urlencode "clientKey=$(cat ./clientuser.key)"
-
Replace
Administrator:passwordwith the credentials of a user on the source cluster with the Full Admin, Cluster Admin, or XDCR Admin role. -
Replace
source.example.comwith a node of the source cluster, andtarget.example.comwith a node of the target cluster. -
Replace
TargetClusterwith a name for the reference. -
For
target-ca.pem, use the root certificate of the target cluster. See Certificates. -
For
clientuser.pem, usechain.peminstead if you created a chain in Step 4.
For all parameters, see Creating or Editing a Reference.
Troubleshoot Client-Certificate Authentication
If the target cluster rejects the client certificate, the source cluster reports an authentication error when you save the reference. Check the following on the target cluster:
-
The username that the path from Step 3 extracts from the certificate matches the user from Step 2.
-
The user has the Full Admin role, or the XDCR Inbound role for the target bucket.
-
Require Client Certificate is set to Enable or Mandatory.
-
The trust store holds the root certificate that issued the client certificate.
-
The trust store holds every intermediate certificate, or the source cluster supplied them in a chain in the correct order.
After you correct the setup, save the reference again.