# Domains on Cloudflare

Source: https://openpanel.sh/docs/domains/cloudflare

Connect a Cloudflare zone with a token limited to it, and OpenPanel writes, checks and removes your own domains' DNS records there, behind Cloudflare's certificate.

When your domain's DNS is on Cloudflare, OpenPanel can write its records for you. An organization admin connects the zone once, with a Cloudflare API token that can edit DNS in that one zone and nothing else. From then on, every own domain added in the zone:

- gets its **TXT record** at `_openpanel.` and the domain, which proves the domain is yours, and is **verified by itself**: OpenPanel looks for the record every minute;
- gets a **proxied CNAME** to `edge.openpanel.sh`, so visitors see Cloudflare's certificate and Cloudflare carries their requests to OpenPanel's edge;
- loses both records when you remove the domain, or when its service or project is deleted.

OpenPanel never touches a record it did not write, and never replaces one that is already there.

## 1. Create the token [#1-create-the-token]

1. In Cloudflare, open **My Profile**, then **API Tokens**, then **Create Token**, and choose **Create Custom Token**.
2. **Permissions:** `Zone` · `Zone` · `Read`, and `Zone` · `DNS` · `Edit`. Optionally `Zone` · `Zone Settings` · `Read`, so OpenPanel can tell you the zone's SSL/TLS mode.
3. **Zone Resources:** `Include` · `Specific zone` · your domain. One zone only: OpenPanel refuses a token that reaches more than one.
4. Create the token and copy it. Cloudflare shows it once.

## 2. Set the zone's SSL/TLS mode to Full [#2-set-the-zones-ssltls-mode-to-full]

In Cloudflare, open the zone, then **SSL/TLS**, and set the encryption mode to **Full**. Cloudflare then reaches OpenPanel's edge over HTTPS and accepts the edge's own certificate.

| Mode | With OpenPanel |
|---|---|
| **Full** | Works. |
| **Full (strict)** | Works only for domains with an [uploaded certificate](/docs/domains/certificates#upload-a-certificate) that Cloudflare trusts, such as a Cloudflare Origin CA certificate. Otherwise Cloudflare refuses the edge's certificate (error 526). |
| **Flexible** or **Off** | Does not work: Cloudflare would talk plain HTTP to the edge, which only redirects to HTTPS. |

OpenPanel shows the mode Cloudflare reported beside the zone when the token may read it.

## 3. Connect the zone [#3-connect-the-zone]

<Tabs items={["Console","CLI","API"]}>
<Tab value="Console">
On the **Domains** page, under **Cloudflare zones**, choose **Connect zone** and paste the token.
</Tab>

<Tab value="CLI">
The token is read from standard input, never from the command line, where your shell's history would keep it:

```sh
printf %s "$CLOUDFLARE_TOKEN" | openpanel dns connect
```

```text
Connected example.com. Own domains you add there get their records written by OpenPanel.
```
</Tab>

<Tab value="API">
```sh
curl -X POST https://openpanel.sh/api/v1/dns-zones \
  -H "Authorization: Bearer $OPENPANEL_TOKEN" \
  -H "Content-Type: application/json" \
  -d "{\"token\": \"$CLOUDFLARE_TOKEN\"}"
```

The answer is the zone, with its `name`, Cloudflare's `zoneId` and the `sslMode` it reported. The token is never returned.
</Tab>
</Tabs>

OpenPanel asks Cloudflare whether the token is active, which zones it reaches and whether it can read their DNS, then keeps the token sealed. Connecting a zone needs the **admin** role in the organization.

## 4. Add domains [#4-add-domains]

[Add your own domain](/docs/domains/own-domain#add-the-domain) as usual. When it is in a connected zone (`app.example.com` in `example.com`, or `example.com` itself), the answer already names the zone in `dnsZoneId`, and the domain is verified within a few minutes without a **Check DNS**.

If the name already has a record in Cloudflare (an `A` record at the root, an older `CNAME`), OpenPanel writes the TXT record only and says so in `dnsProblem` and on the domain's row. Point the existing record at `edge.openpanel.sh` yourself, proxied, or delete it in Cloudflare and add the domain again.

## Replace the token or disconnect [#replace-the-token-or-disconnect]

- **Replace the token**, after you rolled it in Cloudflare: the console's **Replace token** in the zone's menu, `printf %s "$CLOUDFLARE_TOKEN" | openpanel dns token example.com`, or `PUT /api/v1/dns-zones/{zoneId}/token`. The new token must reach the same zone.
- **Disconnect** forgets the zone and its token: the console's **Disconnect**, `openpanel dns remove example.com`, or `DELETE /api/v1/dns-zones/{zoneId}`. It is refused while a domain has records OpenPanel wrote there; remove those domains first.

## What can go wrong [#what-can-go-wrong]

| Message | What it means |
|---|---|
| "This token reaches 2 zones (…). Create one limited to a single zone." | The token's Zone Resources include more than one zone. |
| "This token reaches no zone." | The token lacks `Zone` · `Zone` · `Read`. |
| "… is pending in Cloudflare: its nameservers do not point at Cloudflare yet." | Finish adding the zone in Cloudflare first. |
| "Cloudflare refused to read the DNS records of …" | The token lacks `Zone` · `DNS` · `Edit` for that zone. |
| "Cloudflare says this token is disabled." | Create a new token. |
| "… is already connected. Replace its token there instead." | The zone is connected; use **Replace token**. |

<Cards>
<Card href="/docs/domains/own-domain" title="Your own domain" description="Adding a domain and its two records." />

<Card href="/docs/domains/certificates" title="Certificates" description="Where HTTPS comes from for each kind of domain." />
</Cards>