# Set up domains and TLS

Source: https://dropshelf.ai/docs/self-host/configure/domains-and-tls

Create the two DNS records dropshelf needs, set its base domain and public URL, and get a wildcard certificate.

Every drop is a subdomain of the dashboard's address, so dropshelf needs two DNS names and one
wildcard certificate. This page is for the operator who sets them up, on Kubernetes or on a single
host.

The `server` blocks on this page go in the server's configuration file. On a Helm install, put them
under `config:` in your values file. The `ingress` blocks are Helm values of their own.

## Prerequisites [#prerequisites]

- A domain whose DNS records you can change.
- An Ingress controller with an external address, or a reverse proxy in front of a single host.
- For a certificate from cert-manager: cert-manager in the cluster, with an issuer that solves DNS-01
  challenges.

## Create the DNS records [#create-the-dns-records]

Point two records at whatever fronts dropshelf, usually the Ingress controller's load balancer:

- `drop.example.com`, for the dashboard and the API.
- `*.drop.example.com`, for every drop.

A wildcard matches exactly one label, and a drop's name is one label. One wildcard record covers
every drop.

## Set the base domain and public URL [#set-the-base-domain-and-public-url]

Two settings name the addresses:

```yaml
server:
  baseDomain: drop.example.com
  publicBaseURL: https://drop.example.com
```

- `baseDomain` is a bare hostname, with no scheme, port or path. Drops live at
  `<name>.drop.example.com`.
- `publicBaseURL` is the dashboard's URL, with no path, query or fragment.

The host of `publicBaseURL` must equal `baseDomain`, and the server refuses to start otherwise. The
server tells the dashboard from a drop by `baseDomain`, and checks each write's origin against
`publicBaseURL`.

Use `https` wherever TLS ends in front of the server. Over `http`, the sign-in cookies lose their
`Secure` flag, so keep `http` for a trial on your own machine.

On a Helm install, the chart also takes the Ingress hosts and the certificate's names from
`config.server.baseDomain`.

## Get a wildcard certificate [#get-a-wildcard-certificate]

The certificate must cover both `drop.example.com` and `*.drop.example.com`. The chart offers two
ways to get it, and you use one of them.

### With cert-manager [#with-cert-manager]

By default the chart renders a cert-manager Certificate for both names into the Secret
`dropshelf-tls`. It asks the ClusterIssuer `letsencrypt-dns`. The issuer must solve DNS-01, because a
wildcard cannot be issued through HTTP-01.

To use your own issuer, name it in your Helm values:

```yaml
ingress:
  tls:
    certManager:
      enabled: true
      issuerRef:
        name: <issuer-name>
        kind: ClusterIssuer
```

`kind` is `ClusterIssuer` or `Issuer`.

### With your own certificate [#with-your-own-certificate]

To use a certificate from your own PKI:

1. Create a TLS Secret in the release's namespace, from a certificate that covers both names:

   ```bash
   kubectl -n dropshelf create secret tls drop-example-com-wildcard --cert=<certificate-file> --key=<key-file>
   ```

2. Name the Secret in your Helm values:

   ```yaml
   ingress:
     tls:
       existingSecret: drop-example-com-wildcard
   ```

With `existingSecret` set, the chart renders no Certificate, whatever `certManager.enabled` says.
Renewing the certificate is then yours to do.

<Callout type="warn">
Never add `cert-manager.io/cluster-issuer`, `cert-manager.io/issuer` or `kubernetes.io/tls-acme` to
`ingress.annotations`. Each one makes cert-manager create a second Certificate for the same Secret,
and the two compete over renewal. The chart refuses to render with any of them.
</Callout>

On a single host, TLS ends at your reverse proxy, which needs the same wildcard certificate. [Run on
a single host](/docs/self-host/install/single-host) shows the setup.

## Allow for preview addresses [#allow-for-preview-addresses]

Each version of a drop also has an address of its own, `v<n>--<name>.drop.example.com`, such as
`v7--lunch-votes.drop.example.com`. People who manage the drop use it to look at a version that is
not live.

A preview address is one DNS label, so the wildcard record, certificate and Ingress rule already
cover it. Only people who can manage the drop open it, and its answers carry
`Cache-Control: private, no-store`.

If anything in front of dropshelf lists exact host names, such as a CDN allowlist or a firewall rule,
let these names through too. Otherwise previews fail while the drops keep serving.

## Keep sign-in working across hosts [#keep-sign-in-working-across-hosts]

The cookie that lets a signed-in member open drops is scoped to `.drop.example.com`, so one sign-in
covers every drop host. Nothing needs setting for it beyond an `https` public URL.

Keep the replicas' clocks within a second of each other, with NTP. A sign-out compares times stamped
by different replicas. Kubernetes nodes already run a time service.

## Trust your proxy [#trust-your-proxy]

The server records each client's address in its logs. Behind a proxy, it reads that address from
`X-Forwarded-For`, but only from the ranges you trust:

```yaml
server:
  trustedProxies: ["10.0.0.0/8"]
```

Set it to the Ingress controller's pod range. Without it, the logs record the proxy's address instead
of the client's. The list is empty by default, the chart sets `10.0.0.0/8`, and every entry must be a
CIDR range.

## Confirm it worked [#confirm-it-worked]

Ask the dashboard address whether the server is ready:

```bash
curl -sS https://drop.example.com/readyz
```

A server that is reachable, with a certificate curl trusts, answers:

```text
ready
```

Then publish a drop and open `https://<name>.drop.example.com`. The browser shows the drop with a
valid certificate. On Kubernetes, `kubectl -n dropshelf get certificate dropshelf-tls` shows `True`
under `READY` once cert-manager has issued it.

## Next steps [#next-steps]

- [Connect your identity provider](/docs/self-host/configure/identity-provider)
- [Choose object storage](/docs/self-host/configure/storage)
- [Production checklist](/docs/self-host/install/production-checklist)
- [Helm chart values: ingress](/docs/reference/helm-values#ingress)
- [Configuration reference: server](/docs/reference/configuration#server)
