---
title: "Configuration"
description: "Every environment variable Key Guardian reads."
source: "Key Guardian"
---
Key Guardian reads its configuration from environment variables, and from a `.env` file in its
working directory if there is one. Everything else, such as key slots, Intel Trust Authority and
policies, is set in the console and stored in the database.

## Required

| Variable         | Meaning                                                                                          |
| ---------------- | ------------------------------------------------------------------------------------------------ |
| `SECRET_KEY`     | Signs session cookies. At least 32 random bytes: `openssl rand -hex 32`.                          |
| `ENCRYPTION_KEY` | The software key slot, a Fernet key. Unset, Key Guardian writes a key file to its data directory on first start and logs a warning. Always set it in production. |

## Database

| Variable                                                               | Meaning                       |
| ---------------------------------------------------------------------- | ----------------------------- |
| `DB_TYPE`                                                              | `postgresql`, `mysql` or `sqlite`. |
| `PG_HOST`, `PG_PORT`, `PG_DB`, `PG_USER`, `PG_PASSWORD`                | PostgreSQL connection.        |
| `MYSQL_HOST`, `MYSQL_PORT`, `MYSQL_DB`, `MYSQL_USER`, `MYSQL_PASSWORD` | MySQL connection.             |
| `DATABASE_URL`                                                         | Instead of the parts above, for example `postgresql://user:pass@host:5432/db` or `sqlite:////app/web/instance/vcomp.db`. |

Key Guardian creates and migrates its tables on start-up.

## Server

| Variable             | Default                   | Meaning                                                                    |
| -------------------- | ------------------------- | -------------------------------------------------------------------------- |
| `PUBLIC_URL`         | from the `Host` header    | External base URL, such as `https://guardian.example.com`. Used for sign-in redirects and Mac enrollment. |
| `SECURE_COOKIES`     | `false`                   | Mark the session cookie `Secure`. Set to `true` behind HTTPS.              |
| `KG_TRUSTED_PROXIES` | none                      | Comma-separated proxy addresses or CIDR ranges. For requests from these, rate limits use the client address in `X-Forwarded-For`. Without it, every client behind the proxy shares one budget. |
| `BIND_ADDR`          | `0.0.0.0:80` in the image | Listen address.                                                            |
| `INSTANCE_PATH`      | `/app/web/instance`       | Data directory: SQLite database, generated key file and file store.        |
| `FILE_STORE_PATH`    | `$INSTANCE_PATH/files`    | Where uploaded reference files are kept.                                   |
| `MAX_UPLOAD_BYTES`   | 200 MiB                   | Largest file upload.                                                       |
| `CAPE_PRIMITIVES`    | `/app/cape-primitives`    | The policy engine's building blocks, shipped in the image.                 |
| `RUST_LOG`           | `info`                    | Log filter.                                                                |

Each client may make 120 requests a minute, and 10 a minute to sign-in and Mac renewal. Over the
limit, Key Guardian answers `429` with `Retry-After: 60`.

## Accounts and sign-in

| Variable                                   | Meaning                                                                         |
| ------------------------------------------ | ------------------------------------------------------------------------------- |
| `ADMIN_USER_IDS`                           | Comma-separated account IDs that are administrators. When set, it overrides the administrator setting in the console. |
| `GOOGLE_CLIENT_ID`, `GOOGLE_CLIENT_SECRET` | Turn on Google sign-in, and turn off self-registration. The redirect URI is `<PUBLIC_URL>/auth/google/callback`. |

## Key custody credentials

Key slots are set up in the console. Only the credentials to reach them go in the environment. See
[Key custody](../administration/key-custody.mdx).

| Variable                                                    | For                                             |
| ----------------------------------------------------------- | ----------------------------------------------- |
| `AZURE_TENANT_ID`, `AZURE_CLIENT_ID`, `AZURE_CLIENT_SECRET` | Azure Key Vault with a service principal.       |
| `AZURE_CERT_PATH`                                           | A certificate instead of `AZURE_CLIENT_SECRET`. |
| `YUBIHSM_PASSWORD`                                          | The YubiHSM 2 authentication key's password.    |

With an Azure managed identity or workload identity, you need no Azure variables.

## Mac enrollment

| Variable                           | Default                | Meaning                                                          |
| ---------------------------------- | ---------------------- | ---------------------------------------------------------------- |
| `KG_MAC_ACME_ORIGIN`               | origin of `PUBLIC_URL` | The HTTPS origin Macs enroll through, if different.              |
| `KG_MAC_CERT_VALID_DAYS`           | `90`                   | Mac certificate validity, 1 to 36500 days. Never longer than the root key's. |
| `KG_MAC_WITNESS_MAX_EVIDENCE_DAYS` | `365`                  | A Mac whose last Apple attestation is older than this needs a new token. |

## Development only

| Variable                          | Meaning                                                                      |
| --------------------------------- | ---------------------------------------------------------------------------- |
| `DEBUG_SKIP_SIGNATURE_VALIDATION` | Skip the nonce signature check. Never set it in production: anyone holding a manifest could request its secrets. |