# Harden the deployment

> Close the shared services of the XTM stack to the network, protect the health keys, limit who gets an OpenCRQ account, and tighten the OpenCTI settings, from rate limiting to sessions and logs.

- URL: https://filigran.io/docs/lts/7.260309-lts/deploy/operate/harden/
- Products (the whole suite): XTM One 1.261119.1, OpenCTI 7.260309.0-lts.8, OpenAEV 3.261118.0, OpenCRQ 0.261123.0, XTM Composer 3.261121.0
- OpenCTI line: 7.260309 LTS · 7.260309.0-lts.8
- For: platform engineers
- Type: How-to guide

The XTM stack starts with settings that make a first deployment easy, not with the strictest ones. This page lists what to tighten before production: the shared services the Docker deployment publishes, the health keys, who can create an account in XTM One, and the security settings of OpenCTI, each with its key, its default and the value to choose.

**Diagram: Only the reverse proxy faces users, Elasticsearch and Redis are closed to the network, RabbitMQ and S3 storage keep their passwords, and OpenCTI limits what each client sends**

- Outside the host: Users and clients (Over HTTPS), External integrations (Connect to RabbitMQ)
- Host: Reverse proxy (TLS), Host firewall (Restricts 5672, 15672 and 9000)
- OpenCTI: OpenCTI (Rate limit, GraphQL limits, sessions, logs)
- Shared services: Elasticsearch (9200, no authentication: unpublished), Redis (6379, no password: unpublished), RabbitMQ (5672 and 15672, password of .env), S3 storage (9000, password of .env)

Connections:

- Users and clients → Reverse proxy: HTTPS
- Reverse proxy → OpenCTI: X-Forwarded-For
- OpenCTI → Elasticsearch: Docker network
- OpenCTI → Redis: Docker network
- External integrations → Host firewall: if you have some
- Host firewall → RabbitMQ: user and password

## Before you start {#before-you-start}

- A deployment that works: see [Install with Docker Compose](https://filigran.io/docs/lts/7.260309-lts/deploy/install/docker-compose/).
- Every password, token and key of `.env` replaced with a random value, as in the [Quick start](https://filigran.io/docs/lts/7.260309-lts/deploy/quick-start/).
- The platforms published over TLS, behind a reverse proxy: see [Publish the platforms over HTTPS](https://filigran.io/docs/lts/7.260309-lts/deploy/install/reverse-proxy/).

In xtm-docker, the platforms take their settings from `docker-compose.yml`. Put your changes in `docker-compose.override.yml`, as [Change the stack without editing docker-compose.yml](https://filigran.io/docs/lts/7.260309-lts/deploy/install/docker-compose/#change-the-stack-without-editing-docker-compose-yml) describes, then apply them with `docker compose up -d`.

## Close Elasticsearch and Redis to the network {#close-elasticsearch-and-redis-to-the-network}

xtm-docker publishes the ports of the shared services on every interface of the host. Two of them have no authentication: Elasticsearch, on port 9200, runs with `xpack.security.enabled=false`, and Redis, on port 6379, has no password. Anyone who reaches these ports reads and changes all the data. The platforms reach them on the Docker network, so the published ports are not needed.

1. Remove the published ports in `docker-compose.override.yml`. If the file already has `ports` for these services, replace them. The `!reset` tag needs Docker Compose 2.24 or later.

   ```yaml
   services:
     elasticsearch:
       ports: !reset []
     redis:
       ports: !reset []
   ```

2. Recreate the two services.

   ```bash
   docker compose up -d elasticsearch redis
   ```

   **Check that it worked**

   ```bash
   docker compose ps --format '{{.Service}} {{.Ports}}' | grep -E '^(elasticsearch|redis) '
   ```
   No line shows a `0.0.0.0:` mapping.

RabbitMQ (5672, and 15672 for its management interface) and S3 storage (9000) are protected by the user and password of `.env`. Integrations that run outside the host connect to RabbitMQ: if you have none, restrict these ports with the firewall of the host.

## Protect the health keys {#protect-the-health-keys}

The health endpoints answer only with their key. See [Check that the platforms are healthy](https://filigran.io/docs/lts/7.260309-lts/deploy/operate/health-probes/).

- OpenCTI refuses every call while its key is empty or `ChangeMe`. Keep a random `OPENCTI_HEALTHCHECK_ACCESS_KEY`, and do not set it to `public` on a network you do not trust.
- OpenAEV accepts its default key, `ChangeMe`, and xtm-docker falls back to it when `OPENAEV_HEALTHCHECK_KEY` is missing from `.env`. Set a random value.

## Limit who gets an OpenCRQ account {#limit-who-gets-an-opencrq-account}

OpenCRQ signs its users in through XTM One, and gives an account to any XTM One user at their first sign-in, even one who is a member of no tenant: they then read **You don't have access to OpenCRQ yet** until an administrator adds them. Who can sign in to OpenCRQ is therefore who can get an XTM One account.

In XTM One, keep **Local Registration** off, or limit new accounts to your domains with **Allowed email domains**, and do the same for the **On-the-fly user creation** of each single sign-on method. See [Decide who gets an account](https://filigran.io/docs/xtm-one/administer/sso/#decide-who-gets-an-account) in XTM One.

## Tighten OpenCTI {#tighten-opencti}

The settings below are keys of the OpenCTI configuration. Each one has an environment variable: the key in capitals, with `__` between its levels, such as `APP__SESSION_TIMEOUT` for `app:session_timeout`. Give a list as a JSON array.

```yaml
services:
  opencti:
    environment:
      - APP__SESSION_TIMEOUT=900000
      - 'APP__RATE_PROTECTION__IP_SKIP_RANGES=["10.0.0.0/8"]'
```

### Rate limiting {#rate-limiting}

OpenCTI limits the number of HTTP requests each client can send in a time window, GraphQL included, before any session handling. A client over the limit gets `429 Too Many Requests` until the window ends. Use it when nothing in front of the platform limits the rate already.

*(OpenCTI before 7.260811)*

A client is an IP address.

| Key | Default | What it does |
| --- | --- | --- |
| `app:rate_protection:max_requests` | `10000` | Requests a client may send in the window. `0` refuses every request: it does not turn the limiter off. To exempt clients, use the skip lists |
| `app:rate_protection:time_window` | `1` | Length of the window, in seconds. Below `1`, one second |
| `app:rate_protection:ip_skip_list` | `[]` | IP addresses never limited, as exact addresses |

Behind a reverse proxy, OpenCTI limits each client by the address in the proxy's `X-Forwarded-For` header only when it trusts the proxy. Loopback, link-local and private addresses are trusted.

### GraphQL query limits {#graphql-query-limits}

The rate limiter counts HTTP requests, but one GraphQL request can hold many operations. OpenCTI checks each GraphQL document before it runs it, with two protections.

The batching protection is always on. It limits how many times one request calls the same query or mutation through aliases, a way to guess passwords or overload the platform in a single HTTP request. The login mutation is always limited to one call.

| Key | Default | What it does |
| --- | --- | --- |
| `app:graphql:batching_protection:query_default` | `2` | Calls of the same query in one request |
| `app:graphql:batching_protection:query_subtypes` | `4` | Calls of the `subTypes` query, which the interface sends several times |
| `app:graphql:batching_protection:mutation_default` | `1` | Calls of the same mutation in one request |

The armor protection is off by default: `app:graphql:armor_protection:disabled` is `true`. Once on, it refuses a document that goes over one of its limits, and stops suggesting field names in the error of a wrong query: these suggestions help an attacker map the API.

| Key | Default | What it does |
| --- | --- | --- |
| `app:graphql:armor_protection:disabled` | `true` | Set to `false` to turn the armor protection on |
| `app:graphql:armor_protection:max_depth` | `20` | Nesting depth of a document |
| `app:graphql:armor_protection:max_directives` | `20` | Directives in a document |
| `app:graphql:armor_protection:max_tokens` | `100000` | GraphQL tokens in a document |
| `app:graphql:armor_protection:cost_limit` | `50000000` | Computed cost of a document |
| `app:graphql:armor_protection:block_field_suggestion` | `true` | Hides the field suggestions |

*(OpenCTI before 7.260811)*

In this version, `app:graphql:armor_protection:cost_limit` defaults to `3000000`.

Turn it on in a staging platform first, and check that the screens and the integrations you use still work: a limit set too low refuses their queries.

```yaml
- APP__GRAPHQL__ARMOR_PROTECTION__DISABLED=false
- APP__GRAPHQL__ARMOR_PROTECTION__MAX_DEPTH=20
- APP__GRAPHQL__ARMOR_PROTECTION__BLOCK_FIELD_SUGGESTION=true
```

### Requests and uploads {#requests-and-uploads}

`app:request_timeout` closes a connection that stays idle this many milliseconds. The default, `1200000`, is 20 minutes. Keep the timeout of your reverse proxy consistent with it, or long requests fail at the proxy first.

*(OpenCTI before 7.261030)*

This version does not limit the size or the number of uploaded files: limit the size of request bodies on your reverse proxy.

### Encryption key {#encryption-key}

OpenCTI derives its encryption keys from `app:encryption_key` (`APP__ENCRYPTION_KEY`): 32 bytes or more, in base64, generated with `openssl rand -base64 32`. They protect the secrets it stores in its database, such as those of the authentication providers and of the managed connectors. OpenCTI does not start without it, and cannot read these secrets with another key: keep it in your secret store with the backups.

`app:crypto:master_seed` (`APP__CRYPTO__MASTER_SEED`) is the former name of this key, read only when `app:encryption_key` is not set. If your configuration still uses it, move its value to `app:encryption_key`.

### HTTPS served by OpenCTI {#https-served-by-opencti}

Behind a reverse proxy, OpenCTI does not need certificates. When it serves HTTPS itself, as [Serve HTTPS from a platform](https://filigran.io/docs/lts/7.260309-lts/deploy/configure/certificates/#serve-https-from-a-platform) describes, three more keys apply. `app:https_cert:passphrase` decrypts an encrypted private key. With certificate authentication turned on, OpenCTI asks clients for a certificate, checks it against the authorities listed in `app:https_cert:ca`, paths or PEM contents, and refuses a client whose certificate does not match while `app:https_cert:reject_unauthorized` is `true`, the default.

### Sessions {#sessions}

`app:session_timeout` ends a session after this many milliseconds. The default, `1200000`, is 20 minutes: set it to what your security policy requires. See [Cookies](https://filigran.io/docs/lts/7.260309-lts/opencti/administer/cookies/).

### Public dashboards {#public-dashboards}

By default, no other website can embed a public dashboard. To allow some, list them in `app:public_dashboard_authorized_domains`, as the sources of a Content Security Policy `frame-ancestors` directive, separated by spaces, such as `https://intranet.example.com`. Leave it empty to keep embedding forbidden.

### Logs {#logs}

| Key | Default | What it does |
| --- | --- | --- |
| `app:app_logs:logs_redacted_inputs` | `password`, `secret`, `token`, `api_tokens`, `authentication_value`, `enterprise_license` | GraphQL input fields whose value is hidden in the logs. Add the fields of your own sensitive data, and keep the default ones |
| `app:audit_logs:trace_request_headers` | `user-agent`, `x-forwarded-for` | HTTP headers written to the audit logs with each event |
| `app:app_logs:extended_error_message` | `false` | Adds the input data to error logs, and the GraphQL query and its variables to the logs of API calls. Keep it `false`: the logs would then hold sensitive data |
| `app:performance_logger` | `false` | Logs every API call with its duration and size. Keep it `false` outside a performance analysis: it writes a lot of logs |

See [Troubleshoot the XTM stack](https://filigran.io/docs/lts/7.260309-lts/deploy/operate/troubleshoot/) for the other log settings.

### GraphQL playground {#graphql-playground}

`app:graphql:playground:enabled` is `true` by default and serves the GraphQL playground of the API.

Set it to `false` if your users do not need it. Without the playground, the [GraphQL schema reference](https://filigran.io/docs/lts/7.260309-lts/reference/opencti/graphql-schema/) still documents every query and mutation.

`app:graphql:playground:force_disabled_introspection` is `true` by default: OpenCTI refuses introspection queries, which return the whole schema, even with the playground on. Set it to `false` to let signed-in users introspect the API, as some GraphQL tools require. Without the playground, or with the interface turned off, introspection stays refused.

### Artifact archives {#artifact-archives}

OpenCTI stores potentially malicious files, the artifacts, in encrypted ZIP archives. The password of these archives is `app:artifact_zip_password`, `infected` by default, the usual value for malware samples. Change it if your policy requires another one.

## What's next {#what-s-next}

- [Network and security settings of OpenCTI](https://filigran.io/docs/lts/7.260309-lts/reference/opencti/configuration/#network-and-security), every security key with its default, and the [whole OpenCTI configuration](https://filigran.io/docs/lts/7.260309-lts/reference/opencti/configuration/).
- [Set platform security policies](https://filigran.io/docs/lts/7.260309-lts/opencti/administer/policies/), the security policies set in the interface.
- [Back up and restore](https://filigran.io/docs/lts/7.260309-lts/deploy/operate/backup/), to keep the secrets safe with the data.
