# Issuance and renewal

A certificate authority (CA) is an organization that signs certificates. It signs one only after the requester proves control of every name on it. The proof is a challenge: a value the CA checks in the domain's Domain Name System (DNS) records, or a file served on the hostname. Let's Encrypt is a CA that issues certificates valid for 90 days, so a certificate stays useful only while someone renews it.

For a Workload's server certificate, Azion takes that work on: it requests the certificate from Let's Encrypt, completes the challenge, and renews the certificate before it expires. [Certificate Manager](/en/documentation/platform/certificate-manager/) is a Platform Resource that stores the certificates a Workload uses for Transport Layer Security (TLS). For where Certificate Manager acts on a request, refer to [Request path](/en/documentation/platform/certificate-manager/#request-path). A certificate you upload, or obtain from a CA through a certificate signing request (CSR), is described on [Certificates](/en/documentation/platform/certificate-manager/certificates/).

The sections cover certificate requests, domain validation, wildcard certificates, statuses, issuance time and retries, and renewal.

---

## Certificate requests

A Let's Encrypt request asks Azion to obtain a certificate for a set of hostnames. In the body of an API request, the main hostname goes in `common_name`, and optional other hostnames go in `alternative_names`, which the certificate lists as Subject Alternative Names (SANs). The body also names the authority, `lets_encrypt`, and the challenge that proves control of the names: `http` for HTTP-01 or `dns` for DNS-01. A request from the Workload form in Azion Console takes the names from the Workload's domains and the challenge from the preset you pick.

Azion generates the certificate's key. `key_algorithm` defaults to `ecc_384` on an API request and to `rsa_2048` on a request from the Workload form. For the other algorithms, refer to [Certificate fields](/en/documentation/platform/certificate-manager/certificates/#certificate-fields).

You request a certificate in Azion Console or with `POST /v4/workspace/tls/certificates/request`. [Request a Let's Encrypt certificate](/en/documentation/guides/application-security/tls-and-certificates/how-to-generate-a-lets-encrypt-certificate/) and [Request a Let's Encrypt certificate with the API](/en/documentation/guides/application-security/tls-and-certificates/how-to-generate-a-lets-encrypt-certificate-via-api/) show the steps. For the Console presets that start a request and the name the Console gives the certificate, refer to [Let's Encrypt certificate](/en/documentation/platform/certificate-manager/certificates/#lets-encrypt-certificate).

Until Let's Encrypt issues the certificate, its entry in Certificate Manager holds a temporary certificate that Azion generates. The certificate is listed in Certificate Manager from the request on, and the `id` the API returns identifies it when you check its status.

This diagram follows a request from you to the Workload that presents the certificate. Solid arrows carry requests and checks, and dotted arrows carry answers. Each label starts with the number of the step it belongs to.

```mermaid
%%{init: {"layout": "elk", "elk": {"preset": "modelOrder", "keepEntryNodeOnTop": true}, "themeVariables": {"fontSize": "13px"}, "flowchart": {"nodeSpacing": 24, "rankSpacing": 36, "padding": 8, "wrappingWidth": 150, "useMaxWidth": true}, "sequence": {"width": 120, "actorMargin": 30, "useMaxWidth": true}}}%%
flowchart TD
  You(["You, in Azion Console or the API"])
  CM["Certificate Manager"]
  LE[["Let's Encrypt"]]
  Host["hostname on Azion"]
  DNS[["domain's DNS zone"]]
  WL["Workload"]
  You -->|"1. request"| CM
  CM -.->|"2. id"| You
  CM -->|"3. certificate request"| LE
  LE -->|"4. HTTP-01: fetch the file"| Host
  CM -->|"4. DNS-01: write the TXT record"| DNS
  LE -->|"4. DNS-01: read the TXT record"| DNS
  LE -.->|"5. signed certificate"| CM
  CM -->|"6. bound in tls.certificate"| WL
```

1. You request the certificate from the Workload form or Certificate Manager in Azion Console, or with `POST /v4/workspace/tls/certificates/request`.
2. The API answers with the certificate's `id`, and Azion schedules the issuance.
3. Azion requests the certificate from Let's Encrypt for every name on the request.
4. Let's Encrypt validates each name through the challenge. For HTTP-01, it fetches a file on the hostname, which Azion serves. For DNS-01, it reads the `_acme-challenge` TXT record that Azion writes, in an Edge DNS zone or through the Canonical Name (CNAME) record you add at another DNS provider.
5. Let's Encrypt issues the certificate, and Certificate Manager stores it.
6. A Workload with the certificate bound in `tls.certificate` presents it in the TLS handshake for the Workload's custom domains.

Azion requests Let's Encrypt certificates for domains and subdomains registered in the DNS. Every name on the request must also belong to a domain the account has permission for. Otherwise, the request is refused with `This account cannot use certain common or alternative names because it does not have permission for their domain names.` An `azion.app` hostname is refused too, even one that a Workload of the account holds.

---

## Domain validation

Let's Encrypt validates every name on a request before it issues the certificate, and the request's challenge decides how. Azion supports both challenges, HTTP-01 and DNS-01, for a domain whose DNS is hosted in [Edge DNS](/en/documentation/platform/edge-dns/) or at another DNS provider.

With HTTP-01, Let's Encrypt validates the hostname through a file served for it, and Azion runs the service that answers the challenge. No name needs a TXT record or any other change in the domain's zone, so HTTP-01 suits an account that manages many domains and hostnames.

The hostname must already point to Azion when you send an HTTP-01 request. Every alternative name on the request must point to Azion too, or the issuance fails. Azion schedules the issuance even when no Workload with the hostname is published and active.

With DNS-01, Let's Encrypt validates the hostname through a TXT record in the domain's DNS, under the hostname's `_acme-challenge` name. Who prepares the DNS depends on where the zone is hosted:

- When the zone is in Edge DNS, Azion generates the TXT record and inserts it into the zone. The challenge completes with no action from you.
- When another DNS provider hosts the zone, you add one CNAME record per hostname at that provider. Its name is `_acme-challenge.<your-domain>`, and its value is `<your-domain>.letsencrypt.azion.com`. For example, `_acme-challenge.www.example.com` points to `www.example.com.letsencrypt.azion.com`.

For the records step by step, refer to [Request a Let's Encrypt certificate](/en/documentation/guides/application-security/tls-and-certificates/how-to-generate-a-lets-encrypt-certificate/). To add an `_acme-challenge` TXT record yourself, refer to [Add the Let's Encrypt TXT record](/en/documentation/guides/application-security/tls-and-certificates/lets-encrypt-record/).

Each challenge fits a different situation:

| Challenge | `challenge` value | Use it when                                                                         |
| --------- | ----------------- | ----------------------------------------------------------------------------------- |
| HTTP-01   | `http`            | You do not control the domain's DNS records, and the domain already points to Azion |
| DNS-01    | `dns`             | You control the DNS records, need a wildcard name, or cannot access the web server  |

The two challenges trade a dependency on traffic for a dependency on DNS. For example, during a move to Azion, a DNS-01 request can obtain the certificate for `www.example.com` while the hostname still points to the previous provider. An HTTP-01 request can obtain it only after the hostname points to Azion.

---

## Wildcard certificates

A wildcard name, such as `*.example.com`, lets one certificate cover subdomains that you do not list one by one. A wildcard certificate goes through the DNS-01 challenge, and Azion requests and renews it automatically.

Automatic issuance needs the domain's zone configured and active in Edge DNS, which gives Azion control over the `_acme-challenge` TXT record the validation needs. When the zone is not active in Edge DNS, Azion cannot automate the validation, and you complete it manually.

A certificate can carry a wildcard name alone or next to specific names. A subdomain that the wildcard already covers needs no entry of its own: with `*.example.com` on the certificate, `blog.example.com` need not be listed.

A Workload, by contrast, lists each hostname in full. Its domains refuse a wildcard entry with `The domain does not conform to the format defined in RFC 1035.` The Workload form requests a certificate for the Workload's domains, so it cannot request a wildcard name. To request one with the DNS-01 challenge, refer to [Request a Let's Encrypt certificate with the API](/en/documentation/guides/application-security/tls-and-certificates/how-to-generate-a-lets-encrypt-certificate-via-api/).

One wildcard certificate in place of one certificate per subdomain means fewer distinct certificates to issue. That lowers the chance of reaching the issuance limits of the Let's Encrypt service, which [Certificate Manager limits](/en/documentation/platform/certificate-manager/limits/) links. The cost is the dependency on Edge DNS that automatic issuance brings. For when one certificate shared by many subdomains is a risk, refer to [Certificate Manager best practices](/en/documentation/platform/certificate-manager/best-practices/).

---

## Statuses

A Let's Encrypt certificate reports where its issuance stands in the read-only `status` field. The values follow the certificate from the request to its use on a Workload.

This diagram follows a certificate from the accepted request to the states it can end in. Each label starts with the number of the step it belongs to.

```mermaid
%%{init: {"layout": "elk", "elk": {"preset": "modelOrder", "keepEntryNodeOnTop": true}, "themeVariables": {"fontSize": "13px"}, "flowchart": {"nodeSpacing": 24, "rankSpacing": 36, "padding": 8, "wrappingWidth": 150, "useMaxWidth": true}, "sequence": {"width": 120, "actorMargin": 30, "useMaxWidth": true}}}%%
flowchart TD
  Req["Let's Encrypt request accepted"]
  Pending["certificate: pending"]
  Challenge["certificate: challenge_verification"]
  Active["certificate: active"]
  Inactive["certificate: inactive"]
  Failed["certificate: failed, see status_detail"]
  Expired["certificate: expired"]
  Req -->|"1. issuance scheduled"| Pending
  Pending -->|"2. challenge waits for validation"| Challenge
  Challenge -->|"3. issued, bound to a Workload"| Active
  Challenge -->|"3. issued, not bound"| Inactive
  Challenge -->|"4. validation fails"| Failed
  Active -->|"5. validity ends"| Expired
```

1. The API accepts the request, and Azion schedules the issuance. A certificate is `pending` while Azion processes its issuance or renewal.
2. `challenge_verification` means the DNS-01 or HTTP-01 challenge is waiting for validation.
3. Once issued, the certificate reads `active` while it is bound to a Workload in `tls.certificate`, and `inactive` while it is bound to none.
4. When validation fails, the certificate reads `failed`, and it keeps that status between the retries of the issuance. The `status_detail` field carries the reason, such as `An error has occurred while issuing the requested certificate. Please verify the following domains CNAME: www.example.com`.
5. Once its `validity` date passes, the certificate reads `expired` and no longer protects traffic.

You can bind a certificate to a Workload before Let's Encrypt issues it, but HTTPS on the Workload's domains may not work until the certificate validates. In Azion Console, the Workload's **Digital Certificate** field then warns "This certificate is pending validation and HTTPS may not work until it’s validated". For a failed certificate, it warns "This digital certificate failed and HTTPS cannot be used until the issue is resolved".

For the full status table, with uploaded certificates and the icons of the Azion Console list, refer to [Statuses](/en/documentation/platform/certificate-manager/certificates/#statuses).

---

## Issuance time and retries

Azion makes the first attempt to obtain a Let's Encrypt certificate up to 5 minutes after you save the certificate settings. When an attempt fails, Azion retries on a schedule that spaces the attempts further apart the longer the failure lasts. The schedule raises the chance of success while it stays within the limits of the Let's Encrypt service.

The first 5 retries come at increasing intervals of about 5 to 30 minutes, and they resolve most failures that DNS propagation or a temporarily unavailable service causes.

Azion records why an attempt failed in `status_detail`, which the API returns with the certificate and Azion Console shows beside the certificate's error icon. For example, a mistyped `_acme-challenge` CNAME at your DNS provider fails the first attempts, and `status_detail` names the hostname whose CNAME to check. Once you correct the record, a later attempt in the schedule can obtain the certificate. For symptoms and their fixes, refer to [Troubleshoot Certificate Manager](/en/documentation/platform/certificate-manager/troubleshooting/).

---

## Renewal

Azion renews a Let's Encrypt certificate automatically before its 90-day validity ends. Renewal starts 30 days before expiration, when the certificate becomes eligible for renewal. Azion monitors the certificates it requested, completes the challenge again as renewal approaches, and updates the certificate. The `renewed_at` field records when Azion last renewed it.

The renewal needs no maintenance window, and the certificate keeps its quotas, billing, and permissions. Wildcard certificates renew the same way.

Renewal depends on the validation passing again, so Azion renews a certificate only while its validation settings stay valid and up to date. For example, a DNS-01 certificate for a zone at another provider fails to renew once its `_acme-challenge` record is deleted. An HTTP-01 certificate needs its hostnames to keep pointing to Azion.

Azion stops renewing a certificate in these cases:

- You bind a certificate you uploaded in its place on the Workload.
- You change the domains the certificate was requested for. Azion creates another certificate from the changed set, and the old one is not renewed.
- You delete the certificate, or the domain it was requested for is removed from Azion. Each of these two events also deactivates a managed certificate.

A certificate unbound from its Workload stays in Certificate Manager, and you can bind it again while it remains valid.

Automatic renewal removes the expiration date as a task, at the cost of a dependency. The validation path that obtained the certificate has to keep working for as long as a Workload uses it.

Azion does not renew a certificate you upload. To replace one before it expires, refer to [Certificate Manager best practices](/en/documentation/platform/certificate-manager/best-practices/).

---

## Related resources

- [Certificates](/en/documentation/platform/certificate-manager/certificates.md): Every field of a Let's Encrypt request, the full status table, and the key algorithms Azion generates.
- [Request a Let's Encrypt certificate](/en/documentation/guides/application-security/tls-and-certificates/how-to-generate-a-lets-encrypt-certificate.md): The steps to request a Let's Encrypt certificate and prepare the DNS records its challenge needs.
- [Add the Let's Encrypt TXT record](/en/documentation/guides/application-security/tls-and-certificates/lets-encrypt-record.md): The steps to add the TXT record that a DNS-01 challenge checks.
- [Troubleshoot Certificate Manager](/en/documentation/platform/certificate-manager/troubleshooting.md): Symptoms of a certificate that fails to issue or renew, with their causes and fixes.
