---
title: "Configuration reference"
description: "Every environment variable NHI Security reads: sign-in mode, databases, encryption keys, secret storage, scheduled discovery, rate limits and backups."
keywords: ["NHI Security environment variables", "AUTH_MODE", "CREDENTIAL_ENCRYPTION_KEY", "SECRET_STORE", "DISCOVERY_SCHEDULER_ENABLED", "TRUSTED_PROXIES", "RATE_LIMIT_MAX"]
---

This page lists what you can set on an NHI Security deployment and what each setting changes. It is for whoever operates the deployment. The existing pages call that person "your deployment operator"; if you run NHI Security yourself, that is you. [Deploy NHI Security](/nhi-security/deploy) describes the services these variables configure.

## How configuration is read

The API validates its whole environment once, at startup, and refuses to start if any value is invalid. The error names the failing variable and the reason and never prints the value, so a misconfiguration cannot leak a secret into a log.

With Docker Compose you set most variables in `nhi/deploy/.env.production`, copied from `.env.production.example`. Compose reads that file with `--env-file`, which does not expand shell syntax: write literal values, with no `$(...)`, no `${OTHER}` and no quotes unless the quotes are part of the value. The Compose file composes some API variables for you (the three database URLs, `CORS_ALLOWED_ORIGINS`, `API_HOST`, `API_PORT`), so in that shape you set the inputs listed under [Compose-only variables](#compose-only-variables) instead.

### Combinations that refuse to start

| Condition | Result |
|---|---|
| `AUTH_MODE=trustivan` with no `TRUSTIVAN_API_ORIGIN` | Refused |
| `APP_ENV` is `production` or `staging` and `CREDENTIAL_ENCRYPTION_KEY` is not random (fewer than 16 distinct byte values, which catches zero-filled and hand-typed keys) | Refused |
| `APP_ENV` is `production` or `staging` and `RATE_LIMIT_DISABLED=true` | Refused |
| `APP_ENV` is `production` or `staging` and `MOCK_DATA=true` | Refused |

## Deployment identity and network

| Variable | Default | What it does |
|---|---|---|
| `APP_ENV` | `local` | `local`, `demo`, `staging` or `production`. Decides the defaults of `MOCK_DATA` and `DISCOVERY_SCHEDULER_ENABLED`, and whether demonstration seeding is permitted (only `local` and `demo`). `deploy.sh` refuses anything but `production` or `staging` |
| `NODE_ENV` | `development` | `development`, `test` or `production`. The shipped images set `production` |
| `API_HOST` | `127.0.0.1` | Address the API binds. The Compose file sets `0.0.0.0` inside the container |
| `API_PORT` | `4000` | Port the API listens on |
| `CORS_ALLOWED_ORIGINS` | `http://localhost:3000` | Comma-separated origins allowed to call the API. A state-changing request from any other origin is refused. Never a wildcard |
| `TRUSTED_PROXIES` | empty | Addresses, CIDR ranges, or the aliases `private_ranges` and `loopback`, whose `X-Forwarded-For` and `X-Real-IP` headers the API believes. See below |
| `DOCS_URL` | `https://docs.trustivan.com` | Where the console's **Documentation** link points. Must be an absolute `http` or `https` URL. Empty removes the link |

### Trusted proxies

Left empty, the API records the address that opened the socket and ignores forwarding headers entirely, which is correct when clients reach the API directly. Behind the shipped console and edge, every request would then be attributed to the console's container. Set `TRUSTED_PROXIES=private_ranges` in that topology, which is what the production Compose file defaults to.

The value is load-bearing for three things: the `sourceIp` on [audit records](/nhi-security/governance-and-audit), the runtime gate's `source_address_unrecognised` rule (which has no address to compare without it), and which bucket a caller's rate limit is counted in. Widen it only to networks you operate. Anything it covers can write any source address it likes into your audit trail.

## Sign-in

| Variable | Default | What it does |
|---|---|---|
| `AUTH_MODE` | `local` | `local` for NHI Security's own password sign-in, `trustivan` when TRUSTIVAN AppSec signs people in. Set the same value on the API and the console |
| `TRUSTIVAN_API_ORIGIN` | none | Where the API asks `GET /api/v1/me/context`. Required in `trustivan` mode, ignored otherwise. An origin only: scheme, host and port, with no path, query or credentials |
| `TRUSTIVAN_CONTEXT_TTL_MS` | `30000` | How long one successful answer from TRUSTIVAN is reused, from `0` (no reuse) to `60000`. This is the longest a removed member or a changed role keeps working in NHI Security. A refusal or an outage is never reused |

[Deploy NHI Security](/nhi-security/deploy#choose-a-sign-in-mode) compares the two modes.

## Database

| Variable | Default | What it does |
|---|---|---|
| `DATABASE_URL` | required | The owner connection, used only to run migrations |
| `DATABASE_APP_URL` | required | The organization-scoped connection. Must be a `NOSUPERUSER`, `NOBYPASSRLS` role, or row-level security does not apply |
| `DATABASE_PLATFORM_URL` | required | The platform-scoped connection, used for operator requests. Holds no privileges on organization tables |
| `DATABASE_POOL_MAX` | `10` | Connections per pool, per process, from `1` to `100`. Raising it past what PostgreSQL's `max_connections` allows produces refused connections, not more throughput |

The running API never needs the owner credential. The production Compose file gives the `api` service the application login in `DATABASE_URL` as well, so that no code path in it can connect as the owner.

## Encryption keys and secret storage

| Variable | Default | What it does |
|---|---|---|
| `CREDENTIAL_ENCRYPTION_KEY` | required | Base64 of 32 random bytes (`openssl rand -base64 32`). The top of the key hierarchy and the only part that is not in the database. It wraps a separate data key per stored secret rather than encrypting material directly |
| `CREDENTIAL_ENCRYPTION_KEY_ID` | `k1` | A short lowercase name for the key above, recorded in clear beside every record it protects |
| `CREDENTIAL_ENCRYPTION_RETIRED_KEYS` | empty | JSON mapping earlier key ids to their keys, for example `{"k1":"<base64 32 bytes>"}`. Decrypt-only: nothing is ever written under a retired key |
| `SECRET_STORE` | `both` | Where a connector's [credentials reference](/nhi-security/connectors#credentials-references) resolves: `database`, `environment` or `both`. The production example sets `database` |
| `CONNECTOR_SECRETS` | empty | The environment-backed store: a JSON object of reference name to a flat map of named values, for example `{"aws-production":{"externalId":"..."}}` |
| `CONNECTOR_ENDPOINT_SUFFIXES` | empty | Comma-separated host suffixes that connectors for self-hosted providers may additionally reach, such as `k8s.example.com`. A bare top-level domain is refused |

<Warning>
Losing `CREDENTIAL_ENCRYPTION_KEY` makes every stored connector credential permanently unreadable. There is no recovery path. Keep a copy somewhere your database backups are not: a backup stored beside its key protects nothing, and a backup without its key restores an estate you cannot synchronize.
</Warning>

### Choosing a secret store

- **`database`** stores material encrypted, versioned and rotatable, and a new credential needs no restart. Entries are created through the API. See [Credentials and rotation](/nhi-security/credentials-and-rotation).
- **`environment`** reads only `CONNECTOR_SECRETS`. It cannot version or rotate anything, and changing an entry means restarting the API.
- **`both`** reads the database first and falls back to `CONNECTOR_SECRETS`. Registering a reference through the API is refused when configuration already defines that name, so the two stores can never disagree about one reference.

An entry with no values still has to exist. A connector that authenticates as the deployment's own identity needs `{"aws-production":{}}`, so that a mistyped reference fails loudly instead of resolving to "no credentials needed".

### Connector endpoint suffixes

Providers with a fixed home, such as AWS and GitHub, reach only hosts fixed in code. Self-hosted providers do not have one, so this setting is how you permit a host such as your own Vault or GitLab. The decision deliberately sits with the deployment and never with an organization filling in a connector form. Whatever you list, private, loopback, link-local and cloud metadata addresses stay refused: the setting can permit a public host, never an internal one. [Connectors](/nhi-security/connectors#endpoints) lists which providers it applies to.

### Rotating the encryption key

<Steps>
  <Step title="Generate a new key and give it a new id">
    Set `CREDENTIAL_ENCRYPTION_KEY` to the new key and `CREDENTIAL_ENCRYPTION_KEY_ID` to a new name, such as `k2`.
  </Step>
  <Step title="Keep the old key readable">
    Add the previous key to `CREDENTIAL_ENCRYPTION_RETIRED_KEYS` under its old id: `{"k1":"<the previous key>"}`. Two keys must never share an id.
  </Step>
  <Step title="Restart the API">
    New records are written under `k2`. Existing records still open under `k1`.
  </Step>
</Steps>

That is as far as the shipped tooling goes. Re-wrapping existing records under the new key is implemented inside the secret store and is deliberately not an API route, and no command or script calls it today. Until you re-wrap by other means, the old key has to stay in `CREDENTIAL_ENCRYPTION_RETIRED_KEYS`, and a backup taken before the rotation needs that key configured before anything in it can be read.

## Scheduled discovery

| Variable | Default | What it does |
|---|---|---|
| `DISCOVERY_SCHEDULER_ENABLED` | `true` when `APP_ENV=production`, otherwise `false` | Whether background work runs: connectors are synchronized without anyone asking, access-review deadlines are enforced, the lifecycle sweep sets `stale` and `orphaned`, and [webhook](/nhi-security/webhooks) deliveries are sent. An explicit value always wins. Manual synchronization and **Send test** work either way |
| `DISCOVERY_SCHEDULER_TICK_MS` | `300000` (5 minutes) | How often the scheduler looks for due connectors, from 10 seconds to 1 hour |
| `DISCOVERY_SYNC_INTERVAL_MS` | `21600000` (6 hours) | How long after a successful run a connector is due again, from 1 minute to 7 days |
| `DISCOVERY_MAX_RUNS_PER_TICK` | `5` | How many connectors one tick collects from, from `1` to `100`. Collection is synchronous, so this bounds how long a tick occupies the process |

Turn the scheduler on after your connectors are registered and their first manual synchronization has succeeded, so the schedule starts against something known to work. The overlay that runs NHI Security beside AppSec sets it to `false`. [Discovery and synchronization](/nhi-security/discovery#scheduled-discovery) describes what a scheduled run does.

## Rate limits and logging

| Variable | Default | What it does |
|---|---|---|
| `RATE_LIMIT_WINDOW_MS` | `60000` | The window the general limit counts over. At least `1000` |
| `RATE_LIMIT_MAX` | `300` | Requests per window, per route, per caller address. Each route counts separately, so a caller who reaches its limit on one route can still use the others |
| `RATE_LIMIT_DISABLED` | `false` | Switches rate limiting off. Exists for test suites and is refused in `production` and `staging` |
| `LOG_LEVEL` | `info` | `fatal`, `error`, `warn`, `info`, `debug` or `trace` |
| `LOG_PRETTY` | `false` | Human-readable logs instead of structured JSON |

Four routes carry a tighter limit of their own that these variables do not change: sign-in, password change and invitation acceptance allow 10 requests a minute per address, and operator sign-in allows 5. Counters are held in each API process, which is one reason the API runs as a single replica.

The console's own server-side reads are counted against the person who caused them, not against the console. They forward `X-Forwarded-For` and `X-Real-IP` the way its `/api` proxy does, which the API believes only when `TRUSTED_PROXIES` covers the console. With every hop trusted and no client address recorded, those reads fall back to the console's address again. The console also keeps the brand it read for 30 seconds and goes on showing the last brand it read successfully when the API answers `429`, `5xx` or not at all, so a throttled brand read does not replace the console with an error page. A console that has never read a brand still shows none.

## Remediation

| Variable | Default | What it does |
|---|---|---|
| `REMEDIATION_EXECUTION_ENABLED` | `false` | Whether an approved remediation may be carried out against a provider. Proposals, approvals and dry runs work without it; the final step is refused with `execution_not_enabled` |

The production Compose file does not pass this variable to the API, so setting it in `.env.production` alone changes nothing. Enabling execution means editing the Compose file too. See [Remediation](/nhi-security/remediation#execution-is-off-by-default).

## Demonstration data

| Variable | Default | What it does |
|---|---|---|
| `MOCK_DATA` | `true` when `APP_ENV` is `local` or `demo`, otherwise `false` | Generates a synthetic estate at startup. Findings and gate decisions on it are real outputs over synthetic inputs. Refused in `production` and `staging` |
| `MOCK_DATA_PROFILE` | `large` | `minimal`, `medium` or `large`. Read only when `MOCK_DATA` is true |
| `DEMO_USER_PASSWORD` | none | A fixed password, 12 to 256 characters, for locally seeded demonstration accounts. Unset, the seeder generates one per account and prints it once |

## Console

The console reads four variables of its own.

| Variable | Default | What it does |
|---|---|---|
| `API_ORIGIN` | `http://127.0.0.1:4000` | Where the console forwards `/api/*`. Read at run time, not at build time |
| `AUTH_MODE` | `local` | Must match the API's value. Set on the API alone, the console still renders but sends a visitor with no session to its own sign-in page and hides the **AppSec \| NHI Security** switch |
| `PORT` | `3100` | Port the console listens on |
| `HOSTNAME` | set to `0.0.0.0` by the Compose file | Address the console binds |

The console's base path, `/nhi`, is fixed in the build and is the same in both sign-in modes.

## Compose-only variables

These are read by `nhi/deploy/docker-compose.prod.yml`, not by the API.

| Variable | Default | What it does |
|---|---|---|
| `PUBLIC_DOMAIN` | required | The hostname Caddy serves and requests a certificate for |
| `PUBLIC_ORIGIN` | required | The same host with its scheme. Becomes the API's `CORS_ALLOWED_ORIGINS`. If it does not match the address people actually use, every write fails while reads keep working |
| `TLS_EMAIL` | required | Where the certificate authority sends expiry warnings |
| `POSTGRES_DB` | `angusham` | Database name |
| `POSTGRES_OWNER_USER` | `angusham_owner` | The owner role |
| `POSTGRES_OWNER_PASSWORD` | required | Used by migrations only |
| `POSTGRES_APP_PASSWORD` | required | Password of `angusham_app_login` |
| `POSTGRES_PLATFORM_PASSWORD` | required | Password of `angusham_platform_login` |
| `CADDY_HTTP_PORT`, `CADDY_HTTPS_PORT` | `80`, `443` | Host ports Caddy publishes. Change them only when something else terminates TLS in front of this stack; certificate issuance works only on the defaults |
| `IMAGE_API`, `IMAGE_WEB` | `ghcr.io/trustivan/trustivan-nhi-api:local`, `ghcr.io/trustivan/trustivan-nhi-web:local` | The image each service runs, and the name a local build is given |

The overlay for running beside AppSec (`infra/docker/nhi.override.yml`) adds `NHI_IDP_ORIGIN` (required, becomes `TRUSTIVAN_API_ORIGIN`), `NHI_API_ALIAS` and `NHI_WEB_ALIAS` (required, unique per stack) and `NHI_DOCS_URL` (optional, becomes `DOCS_URL`). The AppSec dashboard reads `NHI_WEB_URL` when it is built; empty (the default) builds it without NHI Security (`make dev` sets `http://localhost:3100`).

### Resource limits

Each container has a ceiling so one runaway service cannot take the host down. Size them against `docker stats` under real load.

| Service | Memory limit | Memory reservation | CPUs | Node heap |
|---|---|---|---|---|
| `postgres` | `POSTGRES_MEM_LIMIT` (`3g`) | `POSTGRES_MEM_RESERVATION` (`1g`) | `POSTGRES_CPUS` (`2.0`) | |
| `api` | `API_MEM_LIMIT` (`1g`) | `API_MEM_RESERVATION` (`256m`) | `API_CPUS` (`1.5`) | `API_NODE_OPTIONS` (`--max-old-space-size=768`) |
| `web` | `WEB_MEM_LIMIT` (`1g`) | `WEB_MEM_RESERVATION` (`256m`) | `WEB_CPUS` (`1.5`) | `WEB_NODE_OPTIONS` (`--max-old-space-size=768`) |
| `caddy` | `CADDY_MEM_LIMIT` (`512m`) | `CADDY_MEM_RESERVATION` (`64m`) | `CADDY_CPUS` (`1.0`) | |
| `migrate` | `MIGRATE_MEM_LIMIT` (`512m`) | | `MIGRATE_CPUS` (`1.0`) | |

Raise PostgreSQL's limit before any other. A limit below its `shared_buffers` plus per-connection memory ends in an out-of-memory kill under load.

## Backup scripts

`backup.sh`, `restore.sh` and `restore-rehearsal.sh` load `deploy/.env.production`, so these can be set there.

| Variable | Default | What it does |
|---|---|---|
| `BACKUP_PUBLIC_KEY` | none | An `age` recipient. When set, each dump is encrypted to it and the plaintext removed |
| `BACKUP_IDENTITY_FILE` | none | The `age` identity file `restore.sh` needs to read an encrypted dump |
| `BACKUP_ALERT_COMMAND` | none | A command run on backup failure, with a one-line reason as its only argument |
| `BACKUP_RETAIN_DAYS` | `14` | How many days of dumps to keep |
| `BACKUP_MIN_FREE_MB` | `2048` | Free space below which a backup refuses to start |
| `BACKUP_MIN_BYTES` | `20480` | Smallest dump accepted as real |
| `REHEARSAL_KEEP` | `0` | `1` leaves the rehearsal database in place for inspection |

`check-backup-freshness.sh` and `check-host-resources.sh` do **not** load that file. Set their variables in the environment of whatever runs them: `BACKUP_MAX_AGE_HOURS` (`26`), `BACKUP_CHECK_MIN_FREE_MB` (`4096`), `DISK_WARN_PERCENT` (`80`), `DISK_FAIL_PERCENT` (`90`) and `MEMORY_WARN_PERCENT` (`90`).

## Next steps

<Columns cols={2}>
  <Card title="Deploy NHI Security" icon="server" href="/nhi-security/deploy">
    The services, the two shapes, and what has not been proven.
  </Card>
  <Card title="Connectors" icon="plug" href="/nhi-security/connectors">
    What each connector needs registered under its credentials reference.
  </Card>
</Columns>
