> ## Documentation Index
> Fetch the complete documentation index at: https://latchkey.getgalaxy.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Latchkey configuration

> Environment variables for the Latchkey server and for products that integrate with it.

Latchkey reads configuration from environment variables, one per value,
matching Filament and Alchemy.

## Server

| Variable | Purpose |
| - | - |
| `LATCHKEY_SERVER_ADDR` | Address the server listens on, `:8080` by default |
| `LATCHKEY_OIDC_ISSUER` | The users' identity provider. Its keys are found through OIDC discovery and verify bearer tokens. |
| `LATCHKEY_OIDC_AUDIENCE` | Audience every token must carry, such as `latchkey`. Required. |
| `LATCHKEY_OIDC_SUBJECT_CLAIM` | Claim that names the subject, `sub` by default |
| `LATCHKEY_OIDC_TENANT_CLAIM` | Claim that names the caller's tenant, such as `org_id`. Required with `LATCHKEY_OIDC_ISSUER`. |
| `LATCHKEY_OIDC_SERVICE_RULE` | A `claim=value` pair that marks an app token from this issuer, such as `idtyp=app` for Entra |
| `LATCHKEY_SERVICE_ISSUER` | Issuer of product and Management tokens, the cluster's OIDC issuer in Kubernetes. Must differ from `LATCHKEY_OIDC_ISSUER`. |
| `LATCHKEY_DOMAINS` | Domain name to owner identity, as comma-separated `domain=service:id` pairs such as `filament=service:system:serviceaccount:t-123:filament,alchemy=service:alchemy`. The only source of domain owners. Change it and redeploy to move a domain. |
| `LATCHKEY_OPERATORS` | Instance operators, as comma-separated `service:id` identities such as `service:management` |
| `LATCHKEY_BOOTSTRAP_TENANT` | Tenant to provision at startup. Set it with `LATCHKEY_BOOTSTRAP_ADMIN`. |
| `LATCHKEY_BOOTSTRAP_ADMIN` | The bootstrap tenant's first Admin, such as `user:derek`. It is bound only when the tenant is created, so an Admin's later changes survive every restart. |
| `LATCHKEY_MAX_STALENESS` | How long a replica may go without confirming a tenant's policy against the database before checks in that tenant answer `UNAVAILABLE`, as a Go duration such as `90s`. `5m` by default. |
| `LATCHKEY_DIRECTORY_OWNER` | The only caller `DirectoryService` accepts, such as `service:management`. Unset, nobody may call it. See [Directory sync](https://latchkey.getgalaxy.io/pages/guides/usage/directory-sync.md). |
| `LATCHKEY_MTLS_CA_FILE` | CA for client certificates, after V1 |
| `LATCHKEY_MTLS_SUBJECT_FROM` | Where a client certificate's subject comes from, such as `spiffe_id`, after V1 |

`server -migrate` applies datastore migrations and exits.

Owners, operators and the directory owner must be service identities with no
tenant, as the security model describes. The server refuses to start with a
`user:` owner, operator or directory owner, and a caller from inside a tenant
never holds their rights, even with the same id.

## Datastore

| Variable | Purpose |
| - | - |
| `LATCHKEY_DATASTORE` | `postgres`, the default, or `sqlite` |
| `LATCHKEY_POSTGRES_DSN` | Postgres connection string. Use `latchkey_owner` credentials for `server -migrate` and `latchkey_app` credentials at runtime. |
| `LATCHKEY_SQLITE_PATH` | Path to `latchkey.db` when the datastore is `sqlite` |

## Metrics

The server reads the standard OpenTelemetry variables. With no endpoint set
it exports nothing.

| Variable | Purpose |
| - | - |
| `OTEL_EXPORTER_OTLP_ENDPOINT` | Where to send metrics over OTLP. `OTEL_EXPORTER_OTLP_METRICS_ENDPOINT` does the same for metrics alone. |
| `OTEL_EXPORTER_OTLP_PROTOCOL` | `grpc`, the default, or `http/protobuf`. `OTEL_EXPORTER_OTLP_METRICS_PROTOCOL` overrides it. |
| `OTEL_METRICS_EXPORTER` | Set to `none` to turn metrics off |
| `OTEL_SDK_DISABLED` | Set to `true` to turn metrics off |
| `OTEL_SERVICE_NAME` | The service name metrics carry. `latchkey` by default. |

Headers, timeout, compression and resource attributes come from their
standard variables too. See
[Observability](https://latchkey.getgalaxy.io/pages/guides/deployment/observability.md#metrics-and-traces)
for what is exported.

## Admin UI

| Variable | Purpose |
| - | - |
| `LATCHKEY_UI_OIDC_CLIENT_ID` | The admin UI's client at the users' identity provider. Set it to turn on the UI's sign-in. It needs `LATCHKEY_OIDC_ISSUER` and `LATCHKEY_OIDC_TENANT_CLAIM`, and the UI reads its token with the same claim names as the API. Unset, the UI the server serves says sign-in is not configured and loads nothing. In Galaxy Cloud the cloud shell mounts the UI and signs people in itself. |

Register the client as a public client that uses PKCE, with the redirect URI
`https://<latchkey host>/auth/callback`. The UI requests the audience in
`LATCHKEY_OIDC_AUDIENCE`, and its access tokens must carry that audience and
the tenant claim. See
[Security](https://latchkey.getgalaxy.io/pages/guides/concepts/security.md#admin-ui) for the hosts the UI may
call.

## Galaxy products

Galaxy products link to each other, so the admin UI can open Filament or
Alchemy and send people back. Set the same variables on every product. A
product links only to the products that are set, and it sends people back
only to their origins. Each value is an absolute http or https URL without
query or fragment, and an invalid one stops the server at start.

| Variable | Purpose |
| - | - |
| `GALAXY_ALCHEMY_URL` | Where Alchemy's UI is served, such as `https://alchemy.example.com` |
| `GALAXY_FILAMENT_URL` | Where Filament's UI is served, such as `https://filament.example.com` |
| `GALAXY_LATCHKEY_URL` | Where Latchkey's admin UI is served, such as `https://latchkey.example.com` |

## Products

| Variable | Purpose |
| - | - |
| `LATCHKEY_MODE` | `off`, `shadow`, `remote` or `embedded`, read by `latchkey.ConfigFromEnv`. See [Turning it on](https://latchkey.getgalaxy.io/pages/guides/usage/integrating.md#turning-it-on). |
| `LATCHKEY_ADDR` | Address of the Latchkey service in `shadow` and `remote` mode |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.