# Configuration

Audience: System Administrator

Environment variables and NATS configuration requirements for deploying Pyck

This page covers the required and optional environment variables and the NATS configuration requirements.

## Required environment variables

All Pyck binaries require the following environment variable to be set:

- **`PYCK_ENV`** (required): Specifies the environment name (for example, `production`, `staging`, `dev`, `local`)
  - This variable **must be set explicitly** in your deployment configuration
  - The application will fail to start if this variable is missing or empty
  - Used for resource naming and namespace construction (for example, `pyck-{PYCK_ENV}-workers`)

Example configuration:

**Docker Compose:**

```yaml
environment:
  - PYCK_ENV=production
```

**Kubernetes ConfigMap:**

```yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: pyck-config
data:
  PYCK_ENV: "production"
```

**IMPORTANT**: As of commit `15ffdc33` (April 2026), `PYCK_ENV` has no default value. Deployments that previously relied on the implicit "local" default must now explicitly set this variable.

### Optional discovery environment name

The management service publishes a client discovery document at `/.well-known/pyck-configuration`. Its `meta.environment` field holds the name of the environment as listed in the DNS TXT record `_pyck.pyck.cloud`, for example `dev`, `test`, `demo` or `eu`. For the format of the document, see [Client discovery document](https://docs.pyck.cloud/developers/authentication.md#client-discovery-document).

The name can be set with this optional environment variable:

- **`PYCK_DISCOVERY_ENVIRONMENT`**: The name published as `meta.environment` (default: the value of `PYCK_ENV`)

**Example Configuration:**

```yaml
environment:
  - PYCK_DISCOVERY_ENVIRONMENT=eu
```

The management service builds the document once at startup. Restart it after you change the variable.

### Optional health check configuration

Temporal workers expose a `/health` HTTP endpoint (enabled by default on port 8080) to support deployment health monitoring. This endpoint verifies that the worker is actively polling Temporal task queues.

The health server can be configured via these optional environment variables:

- **`HEALTH_DISABLED`**: Set to `1` to disable the health endpoint
- **`HEALTH_PORT`**: HTTP port for health checks (default: `8080`)
- **`HEALTH_INTERVAL`**: How often to probe Temporal (default: `10s`)
- **`HEALTH_TIMEOUT`**: RPC timeout for each probe (default: `3s`)
- **`HEALTH_MAX_STALE`**: Maximum age of last successful probe before reporting unhealthy (default: `90s`)

**Example Configuration:**

```yaml
environment:
  - HEALTH_PORT=9090
  - HEALTH_INTERVAL=30s
  - HEALTH_MAX_STALE=120s
```

The health endpoint returns:

- **200 OK** when the worker is actively polling Temporal
- **503 Service Unavailable** when polling has stalled or Temporal is unreachable

The same server also exposes `/ready` for a readiness probe. It returns 200 only when `/health` would return 200 and the worker has stamped its UI bundle metadata, and 503 otherwise. A worker with no UI bundle configured, or with worker deployment versioning disabled, has nothing to stamp and counts as stamped.

This is particularly useful for container orchestrators (Kubernetes, fly.io) that need to detect and restart wedged workers.

## NATS configuration requirements

Pyck uses NATS.io for event streaming and service messaging with a **strict account separation** for security. The system enforces the following requirements:

### Tenant account separation

The **tenant account** (configured via `PYCK_NATS_TENANT_ACCOUNT_NAME`, default: `pyck-tenants`) must be **separate from the services' account**.

**Why the accounts must be separate:**

- Tenant clients connect to NATS through a dedicated account isolated from backend services
- If tenant clients were placed in the services' account, they could potentially access streams and subjects they shouldn't, creating a security vulnerability
- The answers to tenant API calls would be delivered to whatever reply subject the client names, and stored in a stream under another tenant's or the platform's subjects

### Startup validation

**BREAKING CHANGE** (since v0.26.0): The management service now performs an account separation check at startup using the NATS system API (`$SYS.REQ.USER.INFO`). The service will **refuse to start** if:

1. `PYCK_NATS_TENANT_ACCOUNT_NAME` names the same account as the management service's own NATS connection
2. The NATS server does not have a system account configured (required for the `$SYS.REQ.USER.INFO` API)

**Required NATS Server Configuration:**

- A `system_account` must be configured in the NATS server config
- The tenant account declared in the server config must match `PYCK_NATS_TENANT_ACCOUNT_NAME`
- The tenant account must be distinct from the account used by Pyck backend services

**Example Error:**
If the validation fails, you'll see an error like:

```text
failed checking PYCK_NATS_TENANT_ACCOUNT_NAME: the NATS tenant account is the services' account: "pyck-tenants"
```

**Resolution:**

1. Verify your NATS server configuration has a `system_account` defined
2. Ensure `PYCK_NATS_TENANT_ACCOUNT_NAME` points to a separate account for tenant clients
3. Confirm the account exists in your NATS server configuration's `accounts` block

### Consumer create subject (breaking change)

**BREAKING CHANGE** (in the next release after v0.26.0): tenant clients can no longer create push consumers. Every NATS server configuration, the Kubernetes one included, must export and import the consumer create subject the same way `config/nats/nats.conf` does:

```text
# account "pyck", exports
{service: "$PYCK.TENANT.CONSUMER.CREATE.>", accounts: ["pyck-tenants"]}

# account "pyck-tenants", imports
{service: {account: "pyck", subject: "$PYCK.TENANT.CONSUMER.CREATE.>"}, to: "$JS.API.CONSUMER.CREATE.>"}
```

If you changed `PYCK_NATS_TENANT_ACCOUNT_NAME`, use that account name instead of `pyck-tenants`.

These lines replace the export and import of `$JS.API.CONSUMER.CREATE.>`. Deploy the new management image before the NATS configuration: until management runs, tenant clients cannot create consumers. For the same reason, only roll back management together with the NATS configuration. For how tenant clients create consumers, see [Tenant NATS clients](https://docs.pyck.cloud/developers/architecture.md#tenant-nats-clients).
