> For the complete documentation index, see [llms.txt](https://wiki.datadike.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wiki.datadike.com/pam/administration/certificates/renewal.md). Agents can also search and read this documentation through its [MCP server](https://wiki.datadike.com/~gitbook/mcp).

# Renew and deploy certificates

Renew SSL/TLS certificates through ACME or through a CSR signed by your internal CA, and install them on Nginx, Apache or IIS with a configuration test and automatic rollback.

## What this is and when to use it

A certificate in the inventory can be renewed by the solution and installed on the server that presents it. There are two ways to obtain the new certificate:

| Method                  | How the certificate is obtained                                                                                                                    | Use it for                                                                                                 |
| ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
| **ACME (automatic)**    | The solution generates the key, requests the certificate from the CA, proves control of each name and receives the certificate, with no human step | Let's Encrypt, ZeroSSL, internal CAs with an ACME server, commercial CAs with ACME                         |
| **CSR for internal CA** | The solution generates the key and a certificate signing request (CSR). Your CA signs it and you upload the signed certificate                     | Internal CAs without ACME, such as Active Directory Certificate Services, and any CA with a manual process |

With either method, the solution can then **deploy** the certificate to the asset: Nginx and Apache on Linux over SSH, and IIS on Windows over WinRM.

Renewal can run on demand, with **Renew now** or **Generate CSR**, or by itself a set number of days before expiration.

## Before you start

* The certificate already in the inventory and linked to its **Asset**. See [Monitor SSL/TLS certificates](https://wiki.datadike.com/pam/administration/certificates/monitoring.md).
* A role with permission to renew certificates.
* For **ACME (automatic)**: an ACME account; see [Connect an ACME certificate authority](https://wiki.datadike.com/pam/administration/certificates/acme-accounts.md). The deployment must also be configured, because the CA validates each name by fetching a file the solution places on the server. Every name must be a DNS name reachable by the CA on port 80. Wildcard names (`*.example.com`) cannot be issued this way.
* For the deployment, an account on the asset registered under **Accounts › Accounts**:
  * **Linux**: an SSH account that can write the certificate files and reload the web server, directly or with **Use sudo**.
  * **Windows**: a WinRM account in the local Administrators group. Port 5985 or 5986 open from the solution.
* The paths of the certificate, key and chain files that the web server configuration already points to. The solution replaces the files; it does not edit the web server configuration.

## Steps

### Configure renewal and deployment

1. Open **Environment › Certificates**, open the certificate's menu and choose **Edit**.
2. Under **Renewal**, choose **How to renew**: **ACME (automatic)** or **CSR for internal CA**.
3. For ACME, choose the **ACME account**.
4. Choose the **Key type** of the new certificate.
5. Under **Deployment**, choose the server type: **Nginx (Linux, SSH)**, **Apache (Linux, SSH)** or **IIS (Windows, WinRM)**. Choose **No deployment** if you will install the certificate yourself.
6. Choose the **Account on the asset**. The list shows the accounts of the asset linked to the certificate.
7. Fill in the fields for the server type:
   * **Nginx**: **Certificate file** and **Key file**. The certificate file receives the certificate followed by the intermediate chain.
   * **Apache**: **Certificate file** and **Key file**, and **Chain file** only if your configuration uses `SSLCertificateChainFile` (Apache before 2.4.8). Leave **Chain file** empty and the chain goes into the certificate file.
   * **IIS**: the **IIS site** name, as shown in IIS Manager.
   * **ACME on Linux**: **Web root (ACME)**, the directory the site serves at `/`. The validation files are written under `.well-known/acme-challenge/` in that directory. On IIS the site's own root is used.
8. Turn on **Use sudo** if the account needs it to write the files and reload the server.
9. To renew without anyone's action, turn on **Automatic renewal** and set **Renew how many days before**.
10. Save.

### Renew with ACME

1. Open the certificate. The **Renewal** panel shows the method and the history.
2. Click **Renew now**.

The renewal runs in the background. **Step by step**, in the renewal history, shows each stage as it happens: key generated, order placed, names validated, certificate issued, files installed, configuration tested, server reloaded, new certificate confirmed on the endpoint.

### Renew with a CSR

1. Open the certificate and click **Generate CSR**. The solution generates the private key, keeps it encrypted, and creates the CSR with the names of the current certificate.
2. Click **Copy CSR** or **Download CSR**, and submit it to your CA.
3. When the CA returns the signed certificate, click **Upload signed certificate** and paste it in PEM. Paste the intermediate chain right after it.
4. Tick **Deploy on the asset as soon as it is received** to install it straight away, or leave it off and click **Deploy** later, in a maintenance window.

The solution refuses a signed certificate that does not match the private key it generated, and records the refusal.

### What happens during deployment

On **Nginx and Apache**:

1. The current files are backed up next to the originals.
2. The new files are written. Files that already exist keep their owner, group and permissions.
3. The configuration is tested with `nginx -t` or `apachectl -t`.
4. If the test **fails**, the previous files are restored, the server is not reloaded, and the renewal fails with the output of the test.
5. If the test passes, the server is reloaded without dropping connections.

On **IIS**, the certificate and its key are imported into the computer's **Personal** store (`LocalMachine\My`) and the HTTPS binding of the site, on the certificate's port and host name, is pointed to the new certificate. If the binding does not exist, it is created, with SNI when a host name is set.

In every case, the solution then connects to the endpoint and confirms that it is presenting the new certificate. The renewal is only marked **Deployed** after that confirmation.

### Automatic renewal

The daily check starts a renewal for each certificate with **Automatic renewal** on, when the days left reach **Renew how many days before**.

* With **ACME**, the whole flow runs, deployment included.
* With **CSR**, the solution generates the CSR and notifies the recipients. The rest waits for the signed certificate to be uploaded.
* After a failed attempt, the next one starts the following day.

## What you should see

The renewal history of the certificate shows each attempt with its trigger (manual or automatic), status and dates. The statuses are **Pending**, **Awaiting signed certificate**, **Issuing**, **Issued**, **Deploying**, **Deployed**, **Failed** and **Canceled**.

After a successful deployment, the certificate card shows the new expiration date and the status returns to **Valid**.

The recipients of the **Certificate renewal** notification are told when a certificate is issued or deployed, when a renewal fails, and when the automatic renewal has generated a CSR that is waiting for your CA. Set the recipients under **System settings › Notifications › Subscription**.

## How to verify it worked

1. In the renewal history, the attempt must be **Deployed**, and **Step by step** must end with the confirmation that the endpoint presents the new certificate.
2. From any machine that reaches the endpoint, read the certificate the server presents and compare the fingerprint and the end date with the ones the solution shows:

   ```bash
   openssl s_client -connect host.example.com:443 -servername host.example.com </dev/null 2>/dev/null \
     | openssl x509 -noout -fingerprint -sha256 -enddate
   ```
3. Open **Audit › Console › Certificates** and search for the certificate. You must see **Renewal started**, **Certificate received** and **Certificate deployed**, each with the user who acted, or **System** for an automatic renewal.

## Common errors

| Symptom                                                                    | Cause                                                                                                                      | Fix                                                                                                                |
| -------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------ |
| **Renew now** refused: the ACME validation needs the deployment configured | ACME selected with **No deployment**                                                                                       | Configure the deployment. The validation file has to be placed on the server                                       |
| Refused: only DNS names without wildcard                                   | A name in the certificate is a wildcard or an IP address                                                                   | Use **CSR for internal CA** for that certificate                                                                   |
| Failed while validating the names                                          | The CA could not fetch the validation file over HTTP on port 80, or **Web root (ACME)** is not the directory served at `/` | Open port 80 from the CA to the server and correct **Web root (ACME)**                                             |
| Failed: the configuration test failed, previous files restored             | The new files break the web server configuration, for example a key path the configuration does not use                    | Read the test output in **Step by step**, correct the file paths, and deploy again                                 |
| Failed: the server still presents the previous certificate                 | The server was reloaded but serves the certificate from another path, or a load balancer in front of it terminates TLS     | Point **Certificate file** and **Key file** to the paths the configuration uses. For a load balancer, deploy there |
| **Signed certificate refused**                                             | The certificate does not match the key of this renewal, or the CA returned it in DER                                       | Upload the certificate signed for this CSR, in PEM. If the CSR is lost, cancel the renewal and generate a new one  |
| IIS: site not found                                                        | **IIS site** does not match the site name in IIS Manager                                                                   | Copy the exact name from IIS Manager                                                                               |
| WinRM connection refused                                                   | Port 5985/5986 closed, or the account is not a local administrator                                                         | Open the port and use an account in the local Administrators group                                                 |

## Field reference

| Field                      | What it does                                                                          | Accepted values                                                                              | Default            |
| -------------------------- | ------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- | ------------------ |
| How to renew               | Renewal method                                                                        | **ACME (automatic)**, **CSR for internal CA**                                                | Empty: not renewed |
| ACME account               | CA that issues the certificate. ACME only                                             | An ACME account                                                                              | —                  |
| Key type                   | Key of the new certificate                                                            | RSA 2048, RSA 3072, RSA 4096, ECDSA P-256, ECDSA P-384                                       | RSA 2048           |
| Automatic renewal          | Starts the renewal from the daily check                                               | On, off                                                                                      | Off                |
| Renew how many days before | Days before expiration at which the automatic renewal starts                          | Days                                                                                         | 30                 |
| Deployment                 | Server type the certificate is installed on                                           | **No deployment**, **Nginx (Linux, SSH)**, **Apache (Linux, SSH)**, **IIS (Windows, WinRM)** | **No deployment**  |
| Account on the asset       | Account used to connect to the asset                                                  | An account of the linked asset                                                               | —                  |
| Use sudo                   | Writes the files and reloads the server with sudo. Linux only                         | On, off                                                                                      | Off                |
| Certificate file           | Path of the certificate on the server. Linux only                                     | Absolute path                                                                                | —                  |
| Key file                   | Path of the private key on the server. Linux only                                     | Absolute path                                                                                | —                  |
| Chain file                 | Path of a separate chain file. Apache only                                            | Absolute path, or empty                                                                      | Empty              |
| Web root (ACME)            | Directory served at `/`, where the validation files are written. Linux with ACME only | Absolute path                                                                                | —                  |
| IIS site                   | Site whose HTTPS binding receives the certificate. IIS only                           | Site name                                                                                    | —                  |

## Related pages

* [Monitor SSL/TLS certificates](https://wiki.datadike.com/pam/administration/certificates/monitoring.md)
* [Connect an ACME certificate authority](https://wiki.datadike.com/pam/administration/certificates/acme-accounts.md)
* [Certificate and PGP key audit](https://wiki.datadike.com/pam/administration/audit/certificate-and-key-audit.md)
* [Managed accounts](https://wiki.datadike.com/pam/administration/accounts/managed-accounts.md)
