> Markdown version of https://tuna.am/en/docs/reference/tuna-yml/. Documentation index: [llms.txt](https://tuna.am/en/llms.txt), full text in one file: [llms-full.txt](https://tuna.am/en/llms-full.txt). Any page is available as Markdown: append `.md` to its URL without the trailing slash.

# .tuna.yml Reference

`.tuna.yml` is the project settings file. Put it at the repository root, and `tuna start`, traffic policies and the `tuna secrets` commands work the same for everyone who clones the repository. Personal settings, such as the API key or proxy, live in a different file, the [global `tuna.yml`](https://tuna.am/en/docs/guides/config-file.md).

.tuna.yml

```yaml
tunnels:
  web:
    commandLine: http 3000 --subdomain=web
    tags: frontend
  api:
    commandLine: http 8080 --subdomain=api
    tags: backend

rules:
  - name: Admin only with password
    expressions:
      - req.URL.Path startsWith "/admin"
    actions:
      - type: basic_auth
        config:
          userList:
            admin: s3cr3t

secrets:
  project: api-php
  config: dev

```

## Keys

| Key                                                   | What it sets                                        |
| ----------------------------------------------------- | --------------------------------------------------- |
| [`tunnels`](#tunnels)                                 | Tunnels started by `tuna start`                     |
| [`tunnels.<name>.commandLine`](#tunnels-command-line) | Command that starts the tunnel                      |
| [`tunnels.<name>.tags`](#tunnels-tags)                | Tags for starting a group of tunnels                |
| [`rules`](#rules)                                     | Traffic policy rules                                |
| [`rules[].name`](#rules-name)                         | Rule name                                           |
| [`rules[].expressions`](#rules-expressions)           | Conditions under which the rule applies             |
| [`rules[].actions`](#rules-actions)                   | Rule actions                                        |
| [`secrets.project`, `secrets.config`](#secrets)       | Secrets project and config for the file's directory |
| [`secrets.scoped`](#secrets-scoped)                   | Secrets project and config for subdirectories       |
| [`1c`](#1c)                                           | Platform and infobase for `tuna 1c`                 |

## Where tuna looks for the file

Each section is read by its own commands, and they look for the file in different places:

| Section   | Read by                      | Where they look                                                                 | Other path                                                                |
| --------- | ---------------------------- | ------------------------------------------------------------------------------- | ------------------------------------------------------------------------- |
| `tunnels` | `tuna start`, `tuna service` | Current directory                                                               | `--tunnels-file`, `TUNA_START_TUNNELS_FILE`                               |
| `rules`   | `tuna http`, `tuna 1c`       | Current directory                                                               | `--policy-file`, `TUNA_POLICY_FILE`; for `tuna http`, also `--policy-url` |
| `secrets` | `tuna secrets`               | From the `--scope` directory (current by default) up to the git repository root | —                                                                         |
| `1c`      | `tuna 1c`                    | Current directory                                                               | `--policy-file`, `TUNA_POLICY_FILE`                                       |

`tunnels` and `rules` add to the sections of the same name in the global `tuna.yml`. A tunnel with the same name is taken from `.tuna.yml`; the others stay. Rules from both files run one after another: first the global ones, then those from `.tuna.yml`.

If there is no file, the commands work without it. If the file can't be parsed, `tuna http` and `tuna 1c` won't start the tunnel, while `tuna start` prints a warning and uses only the tunnels from the global `tuna.yml`.

## tunnels

|         |                                 |
| ------- | ------------------------------- |
| Type    | Map: tunnel name → its settings |
| Read by | `tuna start`, `tuna service`    |

Tunnels that `tuna start` runs with one command. The key is the tunnel name: you start the tunnel by it (`tuna start web`), and the dashboard shows it. The name must be unique within the file.

Before starting, tuna checks every tunnel in the file. If one has an error, none of them start. A tunnel that crashes restarts after 5 seconds. See the [Multiple Tunnel Startup](https://tuna.am/en/docs/tunnels/guides/multi-tunnels.md) guide for details.

### tunnels.\<name>.commandLine

|          |        |
| -------- | ------ |
| Type     | String |
| Required | Yes    |

The command that starts the tunnel, the same as in the terminal. The `tuna` prefix is optional.

.tuna.yml

```yaml
tunnels:
  db:
    commandLine: postgres 5432 --port=db --cidr-allow=203.0.113.0/24

```

* Supported commands: `http`, `tcp`, `ssh`, `app`, `postgres`, `mysql`, `redis`, `kubernetes`, `1c`, `trigger webhook` and `trigger smtp`. Any flags of these commands work, see the [CLI reference](https://tuna.am/en/docs/cli.md).
* The string is split into arguments on spaces; quotes are not supported. A value with a space can't be passed as a flag. Set it with an [environment variable](https://tuna.am/en/docs/guides/environment-variables.md) instead: tunnels inherit the environment of `tuna start`.
* Each tunnel gets the `TUNA_TUNNEL_NAME` variable set to its name.

### tunnels.\<name>.tags

|          |                           |
| -------- | ------------------------- |
| Type     | String or list of strings |
| Required | No                        |

Tags for starting a group of tunnels: `tuna start --tags=backend` starts every tunnel tagged `backend`.

.tuna.yml

```yaml
tunnels:
  api:
    commandLine: http 8080
    tags: [backend, api]
  worker:
    commandLine: tcp 6379
    tags: backend

```

## rules

Available on the [Pro](https://tuna.am/en/#pricing) and [Legend](https://tuna.am/en/#pricing) plans

|         |                        |
| ------- | ---------------------- |
| Type    | List of rules          |
| Read by | `tuna http`, `tuna 1c` |

[Traffic policy](https://tuna.am/en/docs/traffic-policy.md) rules. Rules are checked in order. A request goes through the actions of every rule whose conditions it matches.

### rules\[].name

|          |        |
| -------- | ------ |
| Type     | String |
| Required | No     |

Rule name. A rule without a name is named after its position in the list.

### rules\[].expressions

|          |                 |
| -------- | --------------- |
| Type     | List of strings |
| Required | No              |

Conditions in the [exprOpens in a new tab](https://expr-lang.org/) language. The rule applies only if all conditions in the list are met. Without conditions, the actions apply to every request. For variables and functions, see [Expressions](https://tuna.am/en/docs/traffic-policy.md#expressions).

.tuna.yml

```yaml
rules:
  - expressions:
      - req.Method == "POST"
      - req.URL.Path startsWith "/api"
    actions:
      - type: rate_limit
        config:
          rate: "60s"
          capacity: 100

```

### rules\[].actions

|          |                 |
| -------- | --------------- |
| Type     | List of actions |
| Required | Yes             |

What to do with the request. Actions run in order. Each action has three fields:

| Field    | Required            | What it sets                     |
| -------- | ------------------- | -------------------------------- |
| `type`   | Yes                 | Action type, see the table below |
| `config` | Depends on the type | Action settings                  |
| `name`   | No                  | Action name                      |

| `type`                                                                             | What it does                       |
| ---------------------------------------------------------------------------------- | ---------------------------------- |
| [`add_headers`](https://tuna.am/en/docs/traffic-policy.md#add_headers)             | Adds request or response headers   |
| [`remove_headers`](https://tuna.am/en/docs/traffic-policy.md#remove_headers)       | Removes headers                    |
| [`basic_auth`](https://tuna.am/en/docs/traffic-policy.md#basic_auth)               | Asks for a username and password   |
| [`url_rewrite`](https://tuna.am/en/docs/traffic-policy.md#url_rewrite)             | Rewrites the request path          |
| [`redirect`](https://tuna.am/en/docs/traffic-policy.md#redirect)                   | Redirects to another URL           |
| [`deny`](https://tuna.am/en/docs/traffic-policy.md#deny)                           | Rejects the request                |
| [`restrict_ips`](https://tuna.am/en/docs/traffic-policy.md#restrict_ips)           | Allows or blocks by IP address     |
| [`rate_limit`](https://tuna.am/en/docs/traffic-policy.md#rate_limit)               | Limits the number of requests      |
| [`custom_response`](https://tuna.am/en/docs/traffic-policy.md#custom_response)     | Returns a predefined response      |
| [`reverse_proxy`](https://tuna.am/en/docs/traffic-policy.md#reverse_proxy)         | Proxies the request to another URL |
| [`verify_webhook`](https://tuna.am/en/docs/tunnels/http.md#verify-webhook)         | Verifies the webhook signature     |
| [`compress_response`](https://tuna.am/en/docs/traffic-policy.md#compress_response) | Compresses the response            |

An unknown `type` is a parse error, and the tunnel won't start.

## secrets

|         |                                                       |
| ------- | ----------------------------------------------------- |
| Type    | Object with the `project`, `config` and `scoped` keys |
| Read by | `tuna secrets`                                        |

Which [secrets](https://tuna.am/en/docs/secrets.md) the `tuna secrets` commands use in this repository. A new developer only needs `tuna login`: `tuna secrets run` picks up the right config right away.

`project` and `config` bind the directory that contains the file:

.tuna.yml

```yaml
secrets:
  project: api-php
  config: dev

```

The `--project` and `--config` flags and a personal binding from `tuna secrets setup` take precedence over the file. The order is described in [Which binding wins](https://tuna.am/en/docs/secrets/cli.md#binding-priority).

### secrets.scoped

|          |                                                 |
| -------- | ----------------------------------------------- |
| Type     | Map: subdirectory path → `project` and `config` |
| Required | No                                              |

Bindings for subdirectories, for example in a monorepo. Paths are relative to the file's directory; absolute paths and `..` are errors. If several bindings match, the deepest one wins. `scoped` can be combined with the top-level `project` and `config`.

.tuna.yml

```yaml
secrets:
  project: api-php
  config: dev
  scoped:
    frontend:
      project: ui
      config: dev

```

`tuna secrets setup --local` writes the binding to this section itself and leaves the rest of the file, comments included, unchanged.

The `tuna.yaml` file with the `setup` key is deprecated: the CLI warns about it and asks you to move the bindings to the `secrets` section of `.tuna.yml`.

## 1c

|         |                                                                     |
| ------- | ------------------------------------------------------------------- |
| Type    | Object with the `home`, `platform`, `name`, `infobase`, `port` keys |
| Read by | `tuna 1c`                                                           |

The 1C:Enterprise platform and infobase that `tuna 1c` publishes by default. The `tuna 1c setup` wizard writes this section, and you can also edit it by hand.

.tuna.yml

```yaml
1c:
  home: 'C:\Program Files (x86)\1cv8'
  platform: 'x86'
  name: 'My base'
  infobase: 'File="C:\Bases\MyBase";'
  port: 8314

```

The global `tuna.yml` can have the same section. If both files have it, `.tuna.yml` overrides it entirely, and command-line arguments and flags take precedence over both files. For what each key means, see [Saved settings](https://tuna.am/en/docs/tunnels/1c.md#setup).
