> For AI agents: the complete documentation index is available at https://docs.hod.sh/llms.txt, the full documentation bundle is available at https://docs.hod.sh/llms-full.txt.

# Configuration

The server reads environment variables, or a TOML file with `hod-server --config FILE` (or `HOD_CONFIG`); environment variables override the file.

## Basics

| Variable                       | Default        |                                                                                                                                                                                                                                                                                              |
| ------------------------------ | -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `HOD_LISTEN`                   | `0.0.0.0:8080` |                                                                                                                                                                                                                                                                                              |
| `HOD_PUBLIC_URL`               |                | The URL forges and runners reach the server at                                                                                                                                                                                                                                               |
| `HOD_ORG`                      | `default`      |                                                                                                                                                                                                                                                                                              |
| `HOD_ADMIN_TOKEN`              | (required)     | 32+ characters                                                                                                                                                                                                                                                                               |
| `HOD_RUNNER_TOKEN`             |                | Bootstrap token protected runners register with (pool `default`): they take default-branch and tag jobs ([Runner trust](https://docs.hod.sh/self-hosting/runners.md#runner-trust)); 32+ characters. Changing or unsetting it revokes the old one at the next start, and it follows `HOD_ORG` |
| `HOD_RUNNER_TOKEN_UNPROTECTED` |                | Bootstrap token unprotected runners register with (pool `unprotected`): they take every other job, such as pull requests'. Same rules; it must differ from `HOD_RUNNER_TOKEN`                                                                                                                |
| `RUST_LOG`                     | `info`         | Log level                                                                                                                                                                                                                                                                                    |
| `HOD_LOG_FORMAT`               |                | `json` for JSON logs                                                                                                                                                                                                                                                                         |

## Database

| Variable                         | Default    |                                                                         |
| -------------------------------- | ---------- | ----------------------------------------------------------------------- |
| `DATABASE_URL`                   | (required) | Postgres 18+ ([Database](https://docs.hod.sh/self-hosting/database.md)) |
| `HOD_DATABASE_MAX_CONNECTIONS`   | `16`       | The connection pool's size                                              |
| `HOD_DATABASE_STATEMENT_TIMEOUT` | `30s`      | Postgres cancels a statement that runs longer                           |
| `HOD_DATABASE_LOCK_TIMEOUT`      | `10s`      | A statement fails if it waits longer for a lock                         |

## Jobs, storage and caches

| Variable                | Default                               |                                                                                                                                                                                                                                                     |
| ----------------------- | ------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `HOD_STORAGE`           | `file:///var/lib/hod/blobs`           | Or `s3://bucket/prefix`                                                                                                                                                                                                                             |
| `HOD_GIT_PROTOCOLS`     | `https`                               | URL schemes the server may fetch repositories with; `http` and `file` only for trusted setups and tests. Hod speaks git itself (gitoxide) over `http` and `https`; `file` runs `git-upload-pack` and `ssh` runs `ssh`, which the image doesn't have |
| `HOD_CACHE_SCOPE_LIMIT` | `10G`                                 | Size cap per cache scope                                                                                                                                                                                                                            |
| `HOD_CACHE_KEEP_DAYS`   | `7`                                   | Cache entries unused for this long are deleted                                                                                                                                                                                                      |
| `HOD_JOB_FILES_LIMIT`   | `10G`                                 | Size cap on a job's `files:` archives, in all                                                                                                                                                                                                       |
| `HOD_LOG_LIMIT`         | `100M`                                | Size cap on a job attempt's log: past it the job fails with `log_limit`, keeping what it printed before                                                                                                                                             |
| `HOD_JOB_TIMEOUT`       | `6h`                                  | How long a job without `timeout:` may run (a duration: `90m`, `1d12h`)                                                                                                                                                                              |
| `HOD_MAX_JOB_TIMEOUT`   |                                       | The longest any job may run, whatever its `timeout:`; no cap by default                                                                                                                                                                             |
| `HOD_RUNNER_DOWNLOADS`  | `/usr/share/hod/runners` in the image | The `hod-runner` builds the server hands out ([Runners](https://docs.hod.sh/self-hosting/runners.md))                                                                                                                                               |

## Connections and limits

| Variable                      | Default           |                                                                                                                                                                                                                                                                                                                                                                                         |
| ----------------------------- | ----------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `HOD_SHUTDOWN_TIMEOUT`        | `25s`             | How long a stopping server waits for requests in flight ([Stopping](https://docs.hod.sh/self-hosting/upgrading.md#stopping))                                                                                                                                                                                                                                                            |
| `HOD_MAX_CONNECTIONS`         | `4096`            | Open connections, TLS handshakes included; past it, new connections are closed at once ([Limits](#limits))                                                                                                                                                                                                                                                                              |
| `HOD_REQUEST_TIMEOUT`         | `30s`             | How long a request may take to answer; past it, `503` ([Limits](#limits))                                                                                                                                                                                                                                                                                                               |
| `HOD_MAX_REQUESTS`            | `256`             | Requests in flight for the API, the web UI and sign-in; past it, `503` with `Retry-After`                                                                                                                                                                                                                                                                                               |
| `HOD_MAX_RUNNER_REQUESTS`     | `512`             | The same for runners; each connected runner always holds one                                                                                                                                                                                                                                                                                                                            |
| `HOD_MAX_WEBHOOK_REQUESTS`    | `64`              | The same for forge webhooks                                                                                                                                                                                                                                                                                                                                                             |
| `HOD_RATE_LIMIT_SIGN_IN`      | `10`              | Sign-ins a minute per client address; past it, `429` ([Rate limits](#rate-limits)). `0` for no limit, as for the three below                                                                                                                                                                                                                                                            |
| `HOD_RATE_LIMIT_ANONYMOUS`    | `300`             | Requests a minute per client address without credentials; the same number again for requests whose credentials fail                                                                                                                                                                                                                                                                     |
| `HOD_RATE_LIMIT_CALLER`       | `1200`            | Requests a minute per signed-in user, across all their tokens and sessions                                                                                                                                                                                                                                                                                                              |
| `HOD_RATE_LIMIT_GIT`          | `120`             | Git proxy requests a minute per job                                                                                                                                                                                                                                                                                                                                                     |
| `HOD_MAX_STREAMS`             | `1024`            | Open event, log and log-row streams on this server; past it, `429` ([Stream caps](#stream-caps)). `0` for no cap, as for the two below                                                                                                                                                                                                                                                  |
| `HOD_MAX_STREAMS_PER_USER`    | `64`              | The same per signed-in user, across all their tokens and sessions                                                                                                                                                                                                                                                                                                                       |
| `HOD_MAX_STREAMS_PER_ADDRESS` | `32`              | The same per client address, for streams opened without signing in                                                                                                                                                                                                                                                                                                                      |
| `HOD_TRUSTED_PROXIES`         |                   | Reverse proxies, load balancers or CDNs in front of the server, as addresses and CIDRs, comma-separated (`10.0.0.5, 172.16.0.0/12`). `private_ranges` stands for `127.0.0.0/8`, `10.0.0.0/8`, `172.16.0.0/12`, `192.168.0.0/16`, `::1/128` and `fc00::/7`. Only from these is the client's address in `HOD_CLIENT_IP_HEADER` believed; without any, the client is the connection's peer |
| `HOD_CLIENT_IP_HEADER`        | `X-Forwarded-For` | The header the trusted proxies put the client's address in. `X-Forwarded-For` is read from the right, past the trusted proxies; any other name (`CF-Connecting-IP`, `X-Real-IP`) must hold one address that the proxy always sets. Needs `HOD_TRUSTED_PROXIES`                                                                                                                          |
| `HOD_HSTS_MAX_AGE`            | `365d`            | How long browsers keep to https for this host (`Strict-Transport-Security`), a duration such as `30d`; sent only when `HOD_PUBLIC_URL` is https. `0` turns it off ([Security headers](#security-headers))                                                                                                                                                                               |
| `HOD_OUTBOUND_ALLOW`          |                   | Addresses, CIDRs and host names that repository URLs not on a configured forge may reach although they aren't public, comma-separated (`git.lan, 10.1.0.0/16`). `private_ranges` stands for the same ranges as in `HOD_TRUSTED_PROXIES` ([Outbound requests](#outbound-requests))                                                                                                       |

## TLS, secrets and sign-in

| Variable                      | Default          |                                                                                                                                                                                                           |
| ----------------------------- | ---------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `HOD_TLS_CERT`, `HOD_TLS_KEY` |                  | PEM files to serve https; reloaded on SIGHUP ([TLS](https://docs.hod.sh/self-hosting/tls.md))                                                                                                             |
| `HOD_SECRETS_KEY_FILE`        |                  | The key stored secrets are encrypted with; without it, none can be stored ([Secrets](https://docs.hod.sh/self-hosting/secrets.md))                                                                        |
| `HOD_SECRETS_OLD_KEY_FILES`   |                  | Old keys, comma-separated, until `hod-server rotate-key` has moved off them                                                                                                                               |
| `HOD_OIDC_ISSUER_URL`         | `HOD_PUBLIC_URL` | Where clouds fetch the OIDC discovery document and JWKS ([OIDC identity](https://docs.hod.sh/self-hosting/oidc.md))                                                                                       |
| `HOD_AUTH_SERVER_ADMINS`      |                  | Server admins by identity, comma-separated (`github:<id>`, `<provider>:<subject>`); sign-in providers are `[[auth.providers]]` in the file ([Users and roles](https://docs.hod.sh/self-hosting/users.md)) |

## Forges

| Variable        | Default |                                                               |
| --------------- | ------- | ------------------------------------------------------------- |
| `HOD_FORGEJO_*` |         | [Forgejo](https://docs.hod.sh/self-hosting/forges/forgejo.md) |
| `HOD_GITLAB_*`  |         | [GitLab](https://docs.hod.sh/self-hosting/forges/gitlab.md)   |
| `HOD_GITHUB_*`  |         | [GitHub](https://docs.hod.sh/self-hosting/forges/github.md)   |

## Limits

The server protects itself without a proxy in front. Besides the settings above, these limits are fixed:

|                                  |                                                                                 |
| -------------------------------- | ------------------------------------------------------------------------------- |
| TLS handshake                    | 10 s                                                                            |
| A new connection's first request | 30 s to send its head                                                           |
| An idle connection               | HTTP/1: 30 s after the last response; HTTP/2: 60 s with no request open         |
| A client that stops reading      | its connection closes after 60 s without progress                               |
| A request body that goes quiet   | 30 s between chunks, on every route                                             |
| Request bodies                   | API: 5 MiB; runner messages: 4 MiB; blob uploads: the size they were signed for |
| HTTP/2                           | 100 concurrent streams, 16 KiB of headers; pinged every 30 s                    |

What a client sees:

- **A closed connection**, when the server has too many connections, or when the client is too slow to send a request or read a response.
- **`429 Too Many Requests`**, past a [rate limit](#rate-limits), with `Retry-After` and the problem `code` `rate_limited`; past a [stream cap](#stream-caps), with `Retry-After: 5` and the `code` `too_many_streams`.
- **`503 Service Unavailable`** with an RFC 9457 problem document ([API reference](https://docs.hod.sh/reference/api.md)). Its `code` is `overloaded`, with `Retry-After: 1`, when too many requests are in flight. It is `timeout` when a request took longer than `HOD_REQUEST_TIMEOUT`. Event streams, downloads, blob uploads, the git proxy and runners are not cut off by it. A request that times out may still have made its change, as when a connection drops.

The server raises its open-file limit to the system's maximum. If that is still too low for `HOD_MAX_CONNECTIONS`, it serves fewer connections and logs a warning: raise the limit (`ulimit -n`, or `nofile` in Docker or systemd).

### Rate limits

Each limit is a number of requests a minute, and all of them may come at once: a client that used them all gets one more every 60/N seconds.

| Limit                      | Counted per    | Counts                                                                                                                                                                                                                                                                     |
| -------------------------- | -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `HOD_RATE_LIMIT_SIGN_IN`   | client address | starting a sign-in, signing a browser in, `hod login`'s code exchange                                                                                                                                                                                                      |
| `HOD_RATE_LIMIT_ANONYMOUS` | client address | the web UI's pages, OIDC discovery, and API requests without credentials. Requests whose credentials fail count in a second bucket of the same size; once it runs out, every request with credentials from that address waits, as they are refused before they are checked |
| `HOD_RATE_LIMIT_CALLER`    | user           | API requests with good credentials; the admin token counts as one user                                                                                                                                                                                                     |
| `HOD_RATE_LIMIT_GIT`       | job            | git proxy requests with the job's token                                                                                                                                                                                                                                    |

Health checks, the web UI's static files, blob transfers, runners and forge webhooks aren't limited. An IPv6 client counts by its `/64`.

The counts are kept in memory on each server: with several servers behind a load balancer, a client may get up to the limit times the number of servers.

Behind a reverse proxy, set `HOD_TRUSTED_PROXIES`. Without it every client's address is the proxy's, and all anonymous visitors share one limit.

`hod` sends a read that got `429` or `503` once more by itself when `Retry-After` is 10 seconds or less.

### Stream caps

Event, log and log-row streams (the web UI's live updates and log view, `hod logs -f`) stay open for as long as the client keeps them. The caps limit how many are open at once: per signed-in user (the admin token counts as one user), per client address for anonymous viewers of public projects, and on the whole server. A browser tab holds one or two; `hod logs -f` holds one per running job.

Past a cap, a new stream gets `429` with `Retry-After: 5`, and streams already open are left alone. The web UI and `hod` try again by themselves. Like rate limits, the counts are kept on each server, and an IPv6 client counts by its `/64`. Behind a reverse proxy, set `HOD_TRUSTED_PROXIES`: without it, all anonymous viewers share the proxy's address, and so one cap of 32 streams.

## Outbound requests

Any org member can trigger a run of any repository URL, and the server fetches the pipeline file from it. So that nobody can use the server to reach the network behind it, a repository URL that isn't under a configured forge's URL ([Forgejo](https://docs.hod.sh/self-hosting/forges/forgejo.md), [GitLab](https://docs.hod.sh/self-hosting/forges/gitlab.md), [GitHub](https://docs.hod.sh/self-hosting/forges/github.md)):

- must resolve to public addresses only: not loopback, private (RFC 1918, `fc00::/7`), link-local, CGNAT (`100.64.0.0/10`) or other special-purpose ranges, in any form, IPv4-mapped IPv6 and NAT64 included. The addresses checked are the ones connected to, so a name that resolves differently the second time gains nothing;
- follows no redirects.

A refused URL gets one fixed message, `<host> resolves to an address Hod doesn't fetch from (private, loopback or link-local); see HOD_OUTBOUND_ALLOW`, whatever the address was.

To fetch from a git server on your own network that isn't a configured forge, allow it with `HOD_OUTBOUND_ALLOW` (`outbound_allow = [...]` in the file): by name (`git.lan`, matched exactly, and then any address it resolves to), by address or CIDR (`10.1.0.0/16`), or `private_ranges` for all of loopback and the private ranges. Cloud metadata services are never fetched from, whatever the setting says: `169.254.169.254`, `fd00:ec2::254`, `100.100.100.200` and `192.0.0.192`.

With `HTTPS_PROXY` (or `HTTP_PROXY`, `ALL_PROXY`) set, the server only sees the proxy's address, so the proxy decides what can be reached: restrict it there. The proxy's own name is allowed, even when it resolves to a private address.

`file://` URLs, which only `HOD_GIT_PROTOCOLS=file` allows, read repositories on the server's own disk and aren't checked: don't allow `file` on a server members you don't trust can reach.

Repositories on configured forges, forge APIs, sign-in providers and component registries are set by the admin and aren't checked.

## Security headers

Every response carries:

- `X-Content-Type-Options: nosniff`
- `Referrer-Policy: same-origin`: Hod's URLs, which name orgs, projects and branches, aren't sent to other sites
- `Cross-Origin-Opener-Policy: same-origin` and `Cross-Origin-Resource-Policy: same-origin`
- `Content-Security-Policy: default-src 'none'; frame-ancestors 'none'` and `X-Frame-Options: DENY`; the web UI's pages and the sign-in pages have stricter policies of their own, which still forbid framing
- `Strict-Transport-Security: max-age=31536000` when `HOD_PUBLIC_URL` is https, whether the server or a proxy in front ends TLS. It covers only this host: no `includeSubDomains`, no `preload`

API responses (`/api/`) also carry `Cache-Control: no-store`, so neither the browser nor a shared cache keeps them: some show a secret once.

API responses that set their own caching keep it: the OIDC discovery document and JWKS, and `hod-runner` downloads (`public, max-age=300`).

Blob downloads from the server's own storage are `application/octet-stream`, with `Content-Disposition: attachment`, `Content-Security-Policy: sandbox` and `Cache-Control: private, no-store`, so a browser saves them and never runs them as a page. With `s3://` storage, runners fetch blobs from the bucket, and the bucket's settings apply.

If a reverse proxy in front adds its own `Strict-Transport-Security`, set `HOD_HSTS_MAX_AGE=0`, or drop it from the proxy: two HSTS headers on one response are an error some scanners flag, and browsers use only the first.
