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

# Harden a self-hosted instance

> Protect the keys, database, gateway, network, and backups of a self-hosted OneCLI instance before you connect an agent.

Treat the API, gateway, database, and host as trusted infrastructure. Keep agents on a separate machine or network. Read the [trust and threat model](/docs/guides/trust-model.md) before deciding which workloads to connect.

This guide is for the operator of a single-person 3.0 installation. You apply the controls below yourself. OneCLI does not apply them to your host.

**1. Keep the management plane private**

Start with `ONECLI_BIND_HOST=127.0.0.1`, the Compose default. The stack publishes the dashboard, API, and gateway ports on that address. Don't change it to `0.0.0.0` to make one service reachable: that also exposes the other published ports.

For remote browser access, put a TLS reverse proxy in front of the dashboard and API. Set `ONECLI_EXTERNAL_URL` to your public HTTPS origin and use the routing instructions in [Configuration](/docs/self-hosting/configuration.md). Keep PostgreSQL and internal service endpoints unreachable from the internet and agent networks.

By default the agent proxy port speaks plain HTTP. A TLS reverse proxy for the dashboard does not protect that port. Use a private network, or [turn on TLS for agents](/docs/self-hosting/configuration.md#tls-for-agents). Verify the entire path before sending a credential across it.

**2. Protect the four instance secrets**

| Secret | What depends on it |
| - | - |
| `SECRET_ENCRYPTION_KEY` | Decryption of stored values. Preserve it with your database backup. |
| `CREDENTIAL_PEPPER_SECRET` | Hash checks for managing keys, connect tokens, and agent credentials. Give the API and gateway the same value. |
| `GATEWAY_INTERNAL_SECRET` | Authentication of internal API and gateway calls. |
| `BETTER_AUTH_SECRET` | Browser authentication sessions. |

The installer creates these values in the installation's `.env`. For a manual install, generate each value separately. `CREDENTIAL_PEPPER_SECRET` must have at least 32 characters.

Protect the configuration file on the host:

```bash theme={null}
chmod 700 ~/.onecli
chmod 600 ~/.onecli/.env
```

Don't mount that file into an agent, commit it, put it in a support bundle, or print `docker compose config` into shared logs. Configuration output and `docker inspect` can contain secrets. Anyone who controls Docker or the host can read the service environment.

Keep a separate encrypted backup of the secret values. Don't generate a replacement encryption key or pepper during a routine restart. If you rotate them, retain the previous values in `SECRET_ENCRYPTION_KEYS_OLD` and `CREDENTIAL_PEPPER_SECRET_OLD` while they are still needed. Use the same relevant values on every service that reads them.

**3. Protect the gateway certificate authority**

The gateway stores its certificate authority in the `app-data` volume. Agents need the public certificate to trust inspected HTTPS traffic. They must not receive the volume or its private key.

Back up that volume with restricted access. Don't mount `/app/data` from the gateway into an agent. Deliver only the public certificate through the connection flow. A stolen certificate authority private key can be used to impersonate services to agents that trust it.

**4. Keep destination checks and TLS verification on**

Leave `GATEWAY_ALLOW_PRIVATE_DESTINATIONS` unset unless an agent must use a specific internal service. The gateway checks resolved addresses and blocks private, loopback, and link-local destinations by default. Prefer an exact destination over a broad subnet or wildcard.

Don't allow cloud metadata endpoints. Metadata ranges require an exact IP exception, but that is not a reason to add one.

Leave `GATEWAY_DANGER_ACCEPT_INVALID_CERTS` unset. Setting it to `true` or `1` disables certificate checks for all upstream hosts. Fix the upstream certificate trust instead of using a global bypass.

Keep plain HTTP credential injection off on items. Only enable it for a service whose unencrypted network path you have accepted. This item setting does not encrypt the agent-to-gateway hop.

**5. Separate access by vault**

Give each class of agent a vault containing only the items it needs. All agents on that vault have the same item permissions. Review the permission before adding an item because existing agents can use new items too.

A new item of any kind starts with every tool on **Always allow**. Review each item's permissions and tighten them.

A connect token from `onecli tokens create` works once and expires after 15 minutes by default. A vault can also have a standing connect token that never expires: treat it as a reusable enrollment secret and turn it off with [the API](/docs/api-reference/connect-tokens/turn-a-vaults-connect-token-off.md). Review the agent list and disconnect any agent you don't recognize. Keep managing keys outside sandboxes, including the key `onecli login` stores, and use an explicit expiry when provisioning an agent that should stop by itself.

**6. Keep the host and backups recoverable**

* Pin a released version instead of leaving service images on `latest`.
* Keep the Compose capability drops and `no-new-privileges` settings. Don't add privileged mode or a Docker socket mount to an agent.
* Restrict shell access, debugging, crash collection, and access to container logs. Avoid request or response body capture for credential-bearing traffic.
* Back up PostgreSQL, the gateway data volume, and the configuration secrets together. Encrypt the backup and restrict who can restore it.
* Rehearse a restore into an isolated environment before an upgrade. Don't let the restored copy send requests to real upstream services.
* Record how you revoke upstream credentials if an agent, host, or gateway is compromised. Disconnecting an agent does not rotate the upstream credential.

## Verify before connecting an agent

From an agent network, confirm that the database, dashboard management endpoints, and internal API are not directly reachable. From outside your private network, confirm the proxy port is not exposed. Check both IPv4 and IPv6.

Use a disposable test credential with a non-echoing upstream. Confirm an allowed request works through the gateway and a denied item cannot be used. Confirm the agent's environment and credential files hold placeholders or its own agent credential, not your stored upstream value. Don't paste the real value into a test assertion or terminal log.

## Next steps

* [Review the trust boundary and known limits](/docs/guides/trust-model.md).
* [Connect agents to your instance](/docs/self-hosting/connect-agents.md).


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