# Your own Cloudflare Tunnel

## Agent prompt

```text
Help me put my own Slatebox behind a Cloudflare Tunnel in my own Cloudflare account. Ask me for the public hostname (a name on a domain in my Cloudflare account, no port, no path) and where Slatebox runs. Walk me through creating the tunnel in the Cloudflare dashboard: service http://localhost:7070 and HTTP Host Header set to the hostname. Tell me to save the tunnel token in a file only I can read, then give me the exact command: npx slatebox install --cloudflare-tunnel <hostname> --cloudflare-tunnel-token-file <file>. Never ask me to paste a tunnel token or an API token into this conversation.

Read the official guide at https://docs.slatebox.com/Installation/own-cloudflare-tunnel.md first. Tell me what you verified and which steps I still need to do.

If your client cannot fetch the documentation, read the same published file at https://raw.githubusercontent.com/Slatebox/slatebox-docs/retype/Installation/own-cloudflare-tunnel.md.
```

Put your own Slatebox on a name in your own domain, such as `https://boards.example.com`, through a Cloudflare Tunnel in your own Cloudflare account. The container connects out to Cloudflare, so nothing is opened on your machine or router, and Slatebox is not in the path.

HTTPS ends at Cloudflare; your slates, files and database stay on your server. [What stays on your server](what-stays-on-your-server.md)

You need a Cloudflare account with your domain on it. Without one, a free team address does the same with nothing to set up. [Team addresses](team-addresses.md)

## Paste a tunnel token

1. In the Cloudflare dashboard, open **Zero Trust** › **Networks** › **Tunnels** and create a tunnel of type **Cloudflared**. Name it after the server.
2. Copy its token and save it in a file only you can read, such as `tunnel-token` with mode 0600. You get no further use from the install commands Cloudflare shows: the Slatebox container runs the connector itself.
3. Add a **Public hostname**: your hostname, such as `boards.example.com`, with service type `HTTP` and URL `localhost:7070`.
4. Under that hostname's **HTTP Settings**, set **HTTP Host Header** to the same hostname.
5. Run the installer:

<!-- tabs -->

```sh Shell
npx slatebox install --cloudflare-tunnel boards.example.com \
  --cloudflare-tunnel-token-file ./tunnel-token
```

<!-- /tabs -->

The installer checks the token where you run it and shows only the tunnel's id, never the token. It sets `SLATEBOX_URL=https://boards.example.com` and keeps the token with the install's other secrets: `secrets.env` with mode 0600, or a Kubernetes Secret mounted at `/data/tunnel/token`. You can delete your `tunnel-token` file afterwards.

Once Slatebox starts, the installer checks that `https://boards.example.com` answers as this server. It ends with the one-time setup link for the first account, and a QR code for [phones](phones-for-your-own-server.md).

The hostname is a public name with dots, without a port, a path or a wildcard. From a script or a coding agent, `--cloudflare-tunnel-token-env NAME` reads the token from an environment variable instead of a file.

## Let the installer create the tunnel

The installer can create the tunnel, its public hostname and its DNS record for you. Give it a Cloudflare API token with only these permissions:

| Permission | Scope |
| --- | --- |
| Account › Cloudflare Tunnel › Edit | Your account |
| Zone › DNS › Edit | The one zone that holds the hostname |

<!-- tabs -->

```sh Shell
export CLOUDFLARE_API_TOKEN=your-scoped-token   # in your own terminal
npx slatebox install --cloudflare-tunnel boards.example.com \
  --cloudflare-api-token-env CLOUDFLARE_API_TOKEN
```

<!-- /tabs -->

- The API token is used once, during the install, and never saved. Delete it in Cloudflare afterwards.
- The installer creates a tunnel named after the install, routes the hostname to `http://localhost:7070` with the HTTP Host Header set, and adds a proxied DNS record.
- It refuses when a DNS record for the hostname already exists, so it never replaces one of yours.
- Running it again finds the same tunnel by name and changes nothing.
- `--cloudflare-api-token-file <file>` reads the API token from a file instead.

## What the installer sets

With your own tunnel, the server is reachable from the internet, so the installer chooses the safe defaults:

| Setting | Default with a tunnel | Change it with |
| --- | --- | --- |
| Phones | On | `--mobile off`, or **Admin** › **Phones** |
| Sign-up | Invited people only | `--signup open` |
| Keycloak's admin console | Closed on the public address | `SLATEBOX_SSO_ADMIN=open` together with `SLATEBOX_SSO_ADMIN_PUBLIC=yes` (installer: `--sso-admin open --sso-admin-public`) |

The review before the install says it plainly, for example: "Reachable from: the internet at https://boards.example.com through Cloudflare (HTTPS ends at Cloudflare). Phone app: on. Sign-up: invite only."

## Manage the tunnel

<!-- tabs -->

```sh Shell
slatebox tunnel status   # the address, the tunnel's id and its connections
slatebox tunnel token    # give the install a new tunnel token, after you refresh it in Cloudflare
slatebox tunnel off      # stop using the tunnel; Slatebox keeps running on this computer
```

<!-- /tabs -->

More than one connection you do not recognize suggests the token was copied: refresh it in Cloudflare and run `slatebox tunnel token`.

## Moving an existing server to the tunnel

Your data stays when the address changes, but everything tied to the old address stops working. The installer lists it and asks before it changes anything:

- Passkeys: people sign in with their password or single sign-on, then add a passkey again.
- Phones, connected apps and agents signed in with the old address: they sign in again.
- Single sign-on: providers you set up in Keycloak need the new address as their redirect address.
- Links people saved or shared with the old address.

With `--yes` (a script or an agent), the installer makes this move only with `--confirm-address-change`.

## Troubleshooting

| What you see | Fix |
| --- | --- |
| "Slatebox is set up for another address" (421) | The public hostname or its HTTP Host Header is not the host in `SLATEBOX_URL`. |
| Cloudflare error 1033 or 530 | The connector is not running. `slatebox tunnel status`, then `slatebox logs --service tunnel`. The server must reach Cloudflare on port 7844, TCP and UDP, outbound. |
| Cloudflare error 502 | The hostname's service is not `http://localhost:7070`. |
| A Cloudflare Access sign-in page | Access is in front of the hostname. The phone app and the API cannot sign in through it: take Access off this hostname. |
| The installer says the address answers for another issuer | `SLATEBOX_URL` and the hostname differ. Run the installer again with the tunnel's public hostname in `--cloudflare-tunnel <hostname>`. |

Phones: [Phones for your own server](phones-for-your-own-server.md) · Every option: [the install guide](install-with-docker.md)
