# Access rules

Source: https://tiltas.openpanel.sh/docs/access

> Say which Members, Groups or Devices may reach which Devices, Services, Groups or LANs, and on which ports.

An **Access rule** says who may reach what, and on which ports. Anything no rule allows is closed. Rules only open
things; there is no rule that refuses, so the order of rules does not matter.

> Diagram: everything is closed until a rule opens it. Ona's own Personal devices reach each other. An Access rule lets Ona reach the Server nas on port 445. Nothing allows Ona to reach the Service gitea, so it is refused.

## What is open from the start

- **Each Member's own Personal devices reach each other.** This is the built-in rule, listed first under **Access rules**
  as **Built in**. It cannot be removed.
- **Servers and Services are closed** until a rule, or a Service's **Who can open it**, opens them.
- **Other Members' Personal devices are closed** to you, and yours to them.
- **A Device waiting for approval reaches nothing**, when [Device approval](/docs/access/device-approval) is on.

On macOS, Windows, iPhone and Android, the app also refuses incoming connections until **Allow incoming connections** is
on in its Settings, even when a rule allows them. See [The access model](/docs/concepts/access-model).

## Add a rule

Owners and Admins write rules; every Member can read them.

In the [console](/app), open **Access rules** and choose **Add a rule**.

Under **Who**, choose **Everyone in the Network**, or Members, Groups and Devices.

Under **May reach**, choose what they may reach, and its ports. Add more lines for more destinations.

Optionally, add a **Note**, such as "ops on the database servers". It is shown in the list and in what a Device can
reach.

Choose **Add rule**. The rule reaches every Device within seconds.

The box at the top of the form, **Reads as**, writes the rule as one sentence before you save it.

## Who

| Choose | Covers |
|---|---|
| **Everyone in the Network** | every Member's Personal devices and every Server |
| A Member | that Member's Personal devices |
| A Group | the Personal devices of its Members, and its Servers |
| A Device | that one Device |

A Member added to a Group later gets what the Group's rules allow, at once. See [Groups](/docs/access/groups).

## May reach

| Kind | Reaches |
|---|---|
| **Service** | that Service only, on its own ports. The rest of the Device stays closed. |
| **Device** | that Device, on the ports you give |
| **Group** | the Servers in that Group, on the ports you give |
| **Subnet** | a LAN shared by one of your Devices, such as `192.168.1.0/24`. See [Subnet routers](/docs/access/subnet-routers). |

A Group as a destination means its Servers. To let people reach each other's Personal devices, name the Devices.

## Ports

Write ports as numbers or ranges, separated by commas: `22`, `443, 8443`, `8000-8100`. Leave the field empty for all
ports. Ports are 1 to 65535.

A rule allows the traffic it names in one direction: the Devices under **Who** may open connections to what they may
reach. Answers come back on the same connection; the other side does not get to open connections back.

## Rules that belong to a Service

Each Service's **Who can open it** is kept as an Access rule of its own. In the list it says **Belongs to the Service**
and the Service's name. Change it on the Service. Removing it closes the Service to everyone until you choose who may
open it again.

## Change or remove a rule

Open the menu at the end of a rule and choose **Edit** or **Remove**. Devices that a removed rule let through lose that
access within seconds.

A rule that names a Device keeps working until the Device is removed from the Network; then the Device is taken out of
the rule, and a rule left with nothing to reach is removed.

## With the API

```bash
curl -X POST https://tiltas.openpanel.sh/api/v1/accounts/acc_your_account/access-rules \
  -H "Authorization: Bearer $TILTAS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"description": "ops on the database servers", "sources": {"groups": ["grp_your_group"]}, "destinations": [{"device_id": "dev_your_server", "ports": ["5432"]}]}'
```

Each destination names exactly one of `service_id`, `device_id`, `group_id` or `subnet`. See
[Create an Access rule](/docs/api/access/createAccessRule).

## Check before you rely on it

Open any Device in the console to see what it can reach and which rule allows each thing. See
[Check what a Device can reach](/docs/access/check-reach).
