> For the complete documentation index, see [llms.txt](https://docs.cennso.com/cennso/cdm/latest/llms.txt) (all documentation: [llms.txt](https://docs.cennso.com/llms.txt)). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cennso.com/cennso/cdm/latest/guides/configure-cdm-tls-certificate.md).

# Configure the CDM TLS certificate

CDM Node terminates the TLS connections that Core Clusters open on the leafnode port 6237. It uses the certificate from the `cdm-tls-cert` Secret in the `cennso-system` namespace. Cennso does not create this Secret. You create a cert-manager `Certificate` resource that issues it.

This guide explains how to issue the certificate and how to change it later. If CDM is reachable under more than one domain, for example a private and a public one, the certificate must cover each of them.

## Prerequisites

- The cert-manager extension is installed on the Management Cluster.
- A cert-manager `ClusterIssuer` that uses a publicly trusted certificate authority. Core Cluster agents trust the default certificate authorities and have no setting for a custom one.
- A DNS-01 solver on the `ClusterIssuer` when the certificate contains wildcard names. Certificate authorities issue wildcard certificates only after a DNS-01 challenge.
- The CDM domain from [Configure Cennso Data Mesh](https://docs.cennso.com/cennso/cennso/latest/configuration/cdm-configuration.md). If you use a public CDM domain, you need it as well.

## Domain name rules

Core Clusters connect to CDM Node with the domain from the `CDM_NODE_ENDPOINT` value, for example `tls://cdm-node.test.example.net:6237`. The certificate must contain a name that matches this domain. Follow these rules when you list the names:

- A wildcard name matches exactly one DNS label. The name `*.test.example.net` matches `cdm-node.test.example.net` but not `cdm-node.public.test.example.net`. Add a second wildcard `*.public.test.example.net` for the public domain.
- Cover every domain that Core Clusters use to reach CDM Node.
- Cover every host that an Application Load Balancer (ALB) serves with `cennso-system/cdm-tls-cert` as its default certificate. For an example, see [Set up a private connection between clusters in IBM Cloud](https://docs.cennso.com/cennso/cennso/latest/user-guides/private-networking.md).

## Steps

1. Create a file named `cdm-tls-cert.yaml` with the following `Certificate` resource. Replace `{CLUSTER_ISSUER_NAME}` with the name of your `ClusterIssuer` and adjust the domain names:

   ```yaml
   apiVersion: cert-manager.io/v1
   kind: Certificate
   metadata:
     name: cdm-tls-cert
     namespace: cennso-system
   spec:
     secretName: cdm-tls-cert
     issuerRef:
       name: {CLUSTER_ISSUER_NAME}
       kind: ClusterIssuer
     dnsNames:
       - '*.test.example.net'
       - '*.public.test.example.net'
   ```

2. (Optional) If the `cdm-tls-cert` Secret already exists, save a copy of it:

   > [!WARNING]
   > When cert-manager issues the certificate, it replaces the content of an existing `cdm-tls-cert` Secret. The backup file contains the private key. Store it in a secure place.

   ```bash
   kubectl -n cennso-system get secret cdm-tls-cert -o yaml > cdm-tls-cert-backup.yaml
   ```

3. Apply the resource:

   ```bash
   kubectl apply -f cdm-tls-cert.yaml
   ```

4. Wait until cert-manager issues the certificate:

   ```bash
   kubectl -n cennso-system wait --for=condition=Ready certificate/cdm-tls-cert --timeout=300s
   ```

   The command prints the following line when the issue succeeds:

   ```text
   certificate.cert-manager.io/cdm-tls-cert condition met
   ```

CDM Node serves the new certificate after its pods restart. With CDM Node 1.7.0 or later, the restart starts by itself. For earlier versions, see [Apply a renewed certificate](#apply-a-renewed-certificate).

## Verification

To check that CDM Node serves a certificate that matches your domain, run the following command with your CDM domain:

```bash
openssl s_client -connect cdm-node.test.example.net:6237 -servername cdm-node.test.example.net -verify_hostname cdm-node.test.example.net </dev/null 2>&1 | grep Verification
```

Sample output:

```text
Verification: OK
```

To list the names in the certificate that CDM Node serves, run:

```bash
openssl s_client -connect cdm-node.test.example.net:6237 -servername cdm-node.test.example.net </dev/null 2>/dev/null | openssl x509 -noout -ext subjectAltName
```

Sample output:

```text
X509v3 Subject Alternative Name:
    DNS:*.test.example.net, DNS:*.public.test.example.net
```

> [!NOTE]
> If the verification fails, see [Certificate is not ready](https://docs.cennso.com/cennso/cdm/latest/troubleshooting/certificate-not-ready.md), [TLS handshake fails](https://docs.cennso.com/cennso/cdm/latest/troubleshooting/tls-handshake-failure.md), or [CDM Node serves an old certificate](https://docs.cennso.com/cennso/cdm/latest/troubleshooting/stale-certificate.md).

## Add a domain name later

To add a domain name, for example when you expose CDM on a public domain, edit the `Certificate` resource:

1. Add the name to `spec.dnsNames` in `cdm-tls-cert.yaml`. For a public domain `cdm-node.public.test.example.net`, add `'*.public.test.example.net'`.

2. Apply the resource:

   ```bash
   kubectl apply -f cdm-tls-cert.yaml
   ```

cert-manager issues a new certificate for the changed list. Public certificate authorities limit how often they issue certificates for the same names. Add all names in one change.

## Apply a renewed certificate

CDM Node reads the certificate when it starts and keeps it in memory. A renewed or re-issued certificate reaches CDM Node only after its pods restart.

CDM Node 1.7.0 and later restart automatically. The Reloader component watches the `cdm-tls-cert` Secret and restarts the `cdm-node` pods one at a time. The restart takes about one minute.

For earlier CDM Node versions, restart the pods yourself after each issue:

```bash
kubectl -n cennso-system rollout restart statefulset cdm-node
```

To wait for the restart to finish, run:

```bash
kubectl -n cennso-system rollout status statefulset cdm-node
```

The command prints `partitioned roll out complete: 3 new pods have been updated...` when all pods run again.

## Next steps

- [Configure mixed network connectivity for Core Clusters](https://docs.cennso.com/cennso/cennso/latest/user-guides/mixed-network-connectivity.md)
- [Configure Cennso Data Mesh](https://docs.cennso.com/cennso/cennso/latest/configuration/cdm-configuration.md)
