# Configure

> Every setting, from flags, environment variables, a TOML file, or defaults, and how secrets stay out of process lists.

From `docs/server.md` in tensile-tools/tensile-auth at commit `e66760d` (v0.4.1-7-ge66760d). The HTML page is https://auth.tensile.tools/docs/server/configure.

Settings come from, in order of precedence: flags, then `TENSILE_AUTH_` environment variables, then a TOML file, then defaults. `--config` or `TENSILE_AUTH_CONFIG` names the file.

- **Variables.** Each key maps to `TENSILE_AUTH_` and its path in upper case, with `__` between sections. For example, `passwords.mailer_url` is `TENSILE_AUTH_PASSWORDS__MAILER_URL`. A list is comma-separated.
- **Flags.** Each key maps to a flag: its path with `_` replaced by `-`, for example `--ops-listen`.
- **Secrets.** `database_url`, `master_key`, `passwords.mailer_url`, and `rate_limits.backend` can be read from a file with the `_FILE` suffix, for example `TENSILE_AUTH_MASTER_KEY_FILE=/run/secrets/master_key`. Their flags take only the file form, such as `--master-key-file`, so a secret never appears in a process list.
- **Unknown keys stop the server.** A key in the file, or a `TENSILE_AUTH_` variable, that matches no setting is refused, so a misspelled setting fails at startup instead of being ignored.

To check a configuration without serving, run `tensile-auth-server check`. It runs every startup check, including the database and the master key, and exits with 0 or 1.

| Key | Default | Meaning |
|---|---|---|
| `database_url` | None; required | A `postgres://` URL, or `sqlite:///absolute/path` for a single node |
| `origins` | None; required | The app's public origins, for example `https://app.example.com`. Each must use `https://`, except on localhost |
| `rp_id` | The host of the first origin | The passkey relying party ID. It must be the host of every origin or a parent domain of it, and contain a dot |
| `rp_name` | `rp_id` | The name some authenticators show |
| `master_key` | None; required | 32 random bytes in standard base64 |
| `listen` | `:8080` | The API listener |
| `ops_listen` | `:9090` | The ops port, which serves [`/livez` and `/readyz`](/docs/server/operate#monitor). It must differ from `listen` |
| `trusted_proxies` | Empty | CIDRs whose `X-Forwarded-For` the server trusts for the client's address |
| `preset` | `standard@1` | The preset that sets the sign-in methods and session lengths. `tensile-auth-preset -all` lists them |
| `migrate` | `auto` | `auto`, `check`, or `off`; see [Upgrade](/docs/server/operate#upgrade) |
| `shutdown_timeout` | `8s` | How long in-flight requests get after `SIGTERM` |
| `passwords.enabled` | `true` | `false` serves passkeys only; set `preset` to `passkey-only@1` with it |
| `passwords.mailer_url` | None | Required with passwords: an `smtp://` or `smtps://` URL, or an `https://` webhook to the app. `smtp://` requires STARTTLS outside loopback; see [Mail](/docs/server/configure#mail) |
| `passwords.accept_bcrypt` | `false` | Verifies bcrypt hashes imported from another product, and replaces each with Argon2id at its first sign-in |
| `cache.enabled` | `true` | On Postgres, caches token lookups and clears every replica's cache through `LISTEN/NOTIFY` |
| `rate_limits.backend` | `postgres` on Postgres, `memory` on SQLite | `postgres`, `memory` for a single node, or a `redis://` or `rediss://` URL. It sets where the counters live, not the limits; see [Rate limits](/docs/server/configure#rate-limits) |
| `sessions.default_scopes` | Empty | The scopes of every session when no hook sets them |
| `hooks.url` | None | The app's endpoint for the sign-up and session scopes hooks |
| `webhooks.url` | None | The app's endpoint for events |
| `admin.allowed_networks` | Empty, which allows any | CIDRs whose clients may reach `/admin/` |
| `oauth.enabled` | `false` | Mounts the OAuth and OpenID Connect provider; see [OAuth](/docs/guides/oauth) |
| `log.format` | `json` | `json` or `text` |

A configuration file looks like this. Keep secrets out of it and pass them with `_FILE` variables:

```toml
origins = ["https://app.example.com"]
preset = "passkey-only@1"
trusted_proxies = ["10.0.0.0/8"]

[passwords]
enabled = false

[webhooks]
url = "https://app.example.com/hooks/auth"
```

## Mail

With passwords on, the server sends the confirmation, reset, and notice emails through `passwords.mailer_url`, in one of these forms:

- **`smtps://user:password@host`** connects with TLS from the first byte, on port 465 by default.
- **`smtp://user:password@host`** connects on port 587 by default, and requires STARTTLS with a certificate valid for `host`. The server refuses to send through an SMTP server that doesn't offer STARTTLS, except on a loopback host: `localhost` or a loopback address, such as `127.0.0.1`.
- **`https://`** posts each message to the app as a webhook signed like [hooks and webhooks](/docs/server/webhooks), and the app sends it. `http://` works only on a loopback host.

The `from` query parameter sets the sender, for example `?from=Acme%20%3Cno-reply@acme.example%3E`. It defaults to `no-reply@` and `rp_id`.

A delivery that fails never changes the answer, so the answer can't reveal which addresses get mail: a sign-up still answers 202. The server logs the failure at error level as `the mailer failed`, with the reason, for example `mailer: the SMTP server doesn't offer STARTTLS; use smtps:// or a server that does`. When a person gets no email, read the server's log first.

For a mailbox on your computer during development, run a local SMTP server that keeps every message, such as [Mailpit](https://mailpit.axllent.org/), which listens for SMTP on port 1025 and shows the mail on port 8025:

- **The binary.** Run Mailpit on the same computer, and set `passwords.mailer_url` to `smtp://localhost:1025`. Plain SMTP works there, because `localhost` is a loopback host.
- **The image.** Inside the container, `localhost` is the container itself, so run Mailpit in the server container's network. Publish Mailpit's web port on the server container, and set the mailer to `smtp://localhost:1025`:

  ```sh
  docker run -d --name tensile-auth \
    -p 127.0.0.1:8080:8080 -p 127.0.0.1:8025:8025 \
    -v tensile-auth-data:/home/nonroot \
    -v "$HOME/tensile-auth-dev/master_key:/run/secrets/master_key:ro" \
    -e TENSILE_AUTH_DATABASE_URL=sqlite:///home/nonroot/auth.db \
    -e TENSILE_AUTH_MASTER_KEY_FILE=/run/secrets/master_key \
    -e TENSILE_AUTH_ORIGINS=http://localhost:3000 \
    -e TENSILE_AUTH_PASSWORDS__MAILER_URL=smtp://localhost:1025 \
    ghcr.io/tensile-tools/tensile-auth-server:v0.4.1
  docker run -d --name mailpit --network container:tensile-auth axllent/mailpit
  ```

  Then open `http://localhost:8025`.

`tensile-auth-server dev` writes each email to standard error instead, but it serves no `/v1/` API and refuses `oauth.enabled`, so an app that uses the SDK can't use it.

## Rate limits

The server applies the library's fixed limits to sign-in and sign-up attempts. No setting changes them: `rate_limits.backend` sets only where the counters live. Each limit is a burst, then a steady rate, and an answer over a limit is 429 `throttled` with `Retry-After`. These are the limits that sign-up and sign-in meet:

| Action | For each client address | For each email address |
|---|---|---|
| Email and password sign-up, and a password reset request | 5, then 1 every 12 minutes | 3, then 1 every 20 minutes |
| Email and password sign-in | 10 a minute | 10, then 20 an hour |
| Each step of a passkey sign-up or sign-in | 10 a minute | None |

For example, a sixth sign-up from one address within a few minutes answers 429 with `Retry-After: 720`.

To start again while you test, restart the server. With SQLite, the counters live in memory by default, so a restart clears them: `docker restart tensile-auth` for the image. Each client is one address, so behind a proxy that doesn't pass the client's address, every person shares one count; see [Put the server behind the app's proxy](/docs/server/reverse-proxy).
